Skip to content

Commit 9008084

Browse files
authored
Merge pull request github#3272 from dbartol/dbartol/DumpFixes
C++: A couple of fixes for IR dumps
2 parents 8ca6c57 + 2264ec7 commit 9008084

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/PrintSSA.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ private import DebugSSA
66

77
bindingset[offset]
88
private string getKeySuffixForOffset(int offset) {
9+
offset >= 0 and
910
if offset % 2 = 0 then result = "" else result = "_Chi"
1011
}
1112

1213
bindingset[offset]
13-
private int getIndexForOffset(int offset) { result = offset / 2 }
14+
private int getIndexForOffset(int offset) { offset >= 0 and result = offset / 2 }
1415

1516
/**
1617
* Property provide that dumps the memory access of each result. Useful for debugging SSA

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/PrintSSA.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ private import DebugSSA
66

77
bindingset[offset]
88
private string getKeySuffixForOffset(int offset) {
9+
offset >= 0 and
910
if offset % 2 = 0 then result = "" else result = "_Chi"
1011
}
1112

1213
bindingset[offset]
13-
private int getIndexForOffset(int offset) { result = offset / 2 }
14+
private int getIndexForOffset(int offset) { offset >= 0 and result = offset / 2 }
1415

1516
/**
1617
* Property provide that dumps the memory access of each result. Useful for debugging SSA

cpp/ql/src/semmle/code/cpp/ir/internal/IRUtilities.qll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ Type getVariableType(Variable v) {
2323
then
2424
result = getDecayedType(declaredType)
2525
or
26-
not exists(getDecayedType(declaredType)) and result = declaredType
26+
not exists(getDecayedType(declaredType)) and result = v.getType()
2727
else
2828
if declaredType instanceof ArrayType and not declaredType.(ArrayType).hasArraySize()
2929
then
30-
result = v.getInitializer().getExpr().getUnspecifiedType()
30+
result = v.getInitializer().getExpr().getType()
3131
or
32-
not exists(v.getInitializer()) and result = declaredType
33-
else result = declaredType
32+
not exists(v.getInitializer()) and result = v.getType()
33+
else result = v.getType()
3434
)
3535
}
3636

37+
/**
38+
* Holds if the database contains a `case` label with the specified minimum and maximum value.
39+
*/
3740
predicate hasCaseEdge(SwitchCase switchCase, string minValue, string maxValue) {
3841
minValue = switchCase.getExpr().getFullyConverted().getValue() and
3942
if exists(switchCase.getEndExpr())

cpp/ql/test/library-tests/valuenumbering/GlobalValueNumbering/ir_gvn.expected

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,27 +425,27 @@ test.cpp:
425425
#-----| Goto -> Block 3
426426

427427
# 56| Block 3
428-
# 56| m56_1(decltype(nullptr)) = Phi : from 2:m55_4, from 5:m56_23
428+
# 56| m56_1(char *) = Phi : from 2:m55_4, from 5:m56_23
429429
# 56| valnum = m56_1, r56_13, r56_20, r56_3, r59_2
430-
# 56| r56_2(glval<char *>) = VariableAddress[ptr] :
430+
# 56| r56_2(glval<char *>) = VariableAddress[ptr] :
431431
# 56| valnum = r50_1, r55_3, r56_12, r56_19, r56_2, r59_1
432-
# 56| r56_3(char *) = Load : &:r56_2, m56_1
432+
# 56| r56_3(char *) = Load : &:r56_2, m56_1
433433
# 56| valnum = m56_1, r56_13, r56_20, r56_3, r59_2
434-
# 56| r56_4(char) = Load : &:r56_3, ~m49_4
434+
# 56| r56_4(char) = Load : &:r56_3, ~m49_4
435435
# 56| valnum = r56_14, r56_4, r59_3
436-
# 56| r56_5(int) = Convert : r56_4
436+
# 56| r56_5(int) = Convert : r56_4
437437
# 56| valnum = r56_15, r56_5, r59_4
438-
# 56| r56_6(glval<char *>) = VariableAddress[str] :
438+
# 56| r56_6(glval<char *>) = VariableAddress[str] :
439439
# 56| valnum = r49_6, r53_2, r56_6
440-
# 56| r56_7(char *) = Load : &:r56_6, m49_7
440+
# 56| r56_7(char *) = Load : &:r56_6, m49_7
441441
# 56| valnum = m49_7, r49_8, r53_3, r56_7
442-
# 56| r56_8(char) = Load : &:r56_7, ~m49_9
442+
# 56| r56_8(char) = Load : &:r56_7, ~m49_9
443443
# 56| valnum = r53_4, r56_8
444-
# 56| r56_9(int) = Convert : r56_8
444+
# 56| r56_9(int) = Convert : r56_8
445445
# 56| valnum = r53_5, r56_9
446-
# 56| r56_10(bool) = CompareNE : r56_5, r56_9
446+
# 56| r56_10(bool) = CompareNE : r56_5, r56_9
447447
# 56| valnum = unique
448-
# 56| v56_11(void) = ConditionalBranch : r56_10
448+
# 56| v56_11(void) = ConditionalBranch : r56_10
449449
#-----| False -> Block 6
450450
#-----| True -> Block 4
451451

csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/PrintSSA.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ private import DebugSSA
66

77
bindingset[offset]
88
private string getKeySuffixForOffset(int offset) {
9+
offset >= 0 and
910
if offset % 2 = 0 then result = "" else result = "_Chi"
1011
}
1112

1213
bindingset[offset]
13-
private int getIndexForOffset(int offset) { result = offset / 2 }
14+
private int getIndexForOffset(int offset) { offset >= 0 and result = offset / 2 }
1415

1516
/**
1617
* Property provide that dumps the memory access of each result. Useful for debugging SSA

0 commit comments

Comments
 (0)