Skip to content

Commit 57613d5

Browse files
committed
C++: Reintroduce the type in TConstantValueNumber to avoid giving constant with different signed-ness the same value number. Instead filter those with more than one type out.
1 parent cb510ed commit 57613d5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ newtype TValueNumber =
99
initializeParameterValueNumber(_, irFunc, var)
1010
} or
1111
TInitializeThisValueNumber(IRFunction irFunc) { initializeThisValueNumber(_, irFunc) } or
12-
TConstantValueNumber(IRFunction irFunc, string value) { constantValueNumber(_, irFunc, value) } or
12+
TConstantValueNumber(IRFunction irFunc, IRType type, string value) {
13+
constantValueNumber(_, irFunc, type, value)
14+
} or
1315
TStringConstantValueNumber(IRFunction irFunc, IRType type, string value) {
1416
stringConstantValueNumber(_, irFunc, type, value)
1517
} or
@@ -119,8 +121,12 @@ private predicate initializeThisValueNumber(InitializeThisInstruction instr, IRF
119121
instr.getEnclosingIRFunction() = irFunc
120122
}
121123

122-
predicate constantValueNumber(ConstantInstruction instr, IRFunction irFunc, string value) {
124+
predicate constantValueNumber(
125+
ConstantInstruction instr, IRFunction irFunc, IRType type, string value
126+
) {
123127
instr.getEnclosingIRFunction() = irFunc and
128+
strictcount(instr.getResultIRType()) = 1 and
129+
instr.getResultIRType() = type and
124130
instr.getValue() = value
125131
}
126132

@@ -245,9 +251,9 @@ private TValueNumber nonUniqueValueNumber(Instruction instr) {
245251
initializeThisValueNumber(instr, irFunc) and
246252
result = TInitializeThisValueNumber(irFunc)
247253
or
248-
exists(string value |
249-
constantValueNumber(instr, irFunc, value) and
250-
result = TConstantValueNumber(irFunc, value)
254+
exists(string value, IRType type |
255+
constantValueNumber(instr, irFunc, type, value) and
256+
result = TConstantValueNumber(irFunc, type, value)
251257
)
252258
or
253259
exists(IRType type, string value |

0 commit comments

Comments
 (0)