Skip to content

Commit 3c35e1e

Browse files
committed
C++: Require a unique IRFunction for each value number case and assign instructions with a non-unique IRFUnction a unique value number.
1 parent 76f2c6a commit 3c35e1e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ private predicate filteredNumberableInstruction(Instruction instr) {
129129
count(instr.(InheritanceConversionInstruction).getBaseClass()) != 1 or
130130
count(instr.(InheritanceConversionInstruction).getDerivedClass()) != 1
131131
)
132+
or
133+
count(instr.getEnclosingIRFunction()) != 1
132134
}
133135

134136
private predicate variableAddressValueNumber(
135137
VariableAddressInstruction instr, IRFunction irFunc, Language::AST ast
136138
) {
137-
instr.getEnclosingIRFunction() = irFunc and
139+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
138140
// The underlying AST element is used as value-numbering key instead of the
139141
// `IRVariable` to work around a problem where a variable or expression with
140142
// multiple types gives rise to multiple `IRVariable`s.
@@ -144,7 +146,7 @@ private predicate variableAddressValueNumber(
144146
private predicate initializeParameterValueNumber(
145147
InitializeParameterInstruction instr, IRFunction irFunc, Language::AST var
146148
) {
147-
instr.getEnclosingIRFunction() = irFunc and
149+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
148150
// The underlying AST element is used as value-numbering key instead of the
149151
// `IRVariable` to work around a problem where a variable or expression with
150152
// multiple types gives rise to multiple `IRVariable`s.
@@ -154,15 +156,15 @@ private predicate initializeParameterValueNumber(
154156
private predicate constantValueNumber(
155157
ConstantInstruction instr, IRFunction irFunc, IRType type, string value
156158
) {
157-
instr.getEnclosingIRFunction() = irFunc and
159+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
158160
unique( | | instr.getResultIRType()) = type and
159161
instr.getValue() = value
160162
}
161163

162164
private predicate stringConstantValueNumber(
163165
StringConstantInstruction instr, IRFunction irFunc, IRType type, string value
164166
) {
165-
instr.getEnclosingIRFunction() = irFunc and
167+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
166168
instr.getResultIRType() = type and
167169
instr.getValue().getValue() = value
168170
}
@@ -171,7 +173,7 @@ private predicate fieldAddressValueNumber(
171173
FieldAddressInstruction instr, IRFunction irFunc, Language::Field field,
172174
TValueNumber objectAddress
173175
) {
174-
instr.getEnclosingIRFunction() = irFunc and
176+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
175177
unique( | | instr.getField()) = field and
176178
tvalueNumber(instr.getObjectAddress()) = objectAddress
177179
}
@@ -182,7 +184,7 @@ private predicate binaryValueNumber0(
182184
TValueNumber valueNumber
183185
) {
184186
not instr instanceof PointerArithmeticInstruction and
185-
instr.getEnclosingIRFunction() = irFunc and
187+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
186188
instr.getOpcode() = opcode and
187189
(
188190
isLeft = true and
@@ -206,7 +208,7 @@ private predicate pointerArithmeticValueNumber0(
206208
PointerArithmeticInstruction instr, IRFunction irFunc, Opcode opcode, int elementSize,
207209
boolean isLeft, TValueNumber valueNumber
208210
) {
209-
instr.getEnclosingIRFunction() = irFunc and
211+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
210212
instr.getOpcode() = opcode and
211213
instr.getElementSize() = elementSize and
212214
(
@@ -229,7 +231,7 @@ private predicate pointerArithmeticValueNumber(
229231
private predicate unaryValueNumber(
230232
UnaryInstruction instr, IRFunction irFunc, Opcode opcode, TValueNumber operand
231233
) {
232-
instr.getEnclosingIRFunction() = irFunc and
234+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
233235
not instr instanceof InheritanceConversionInstruction and
234236
not instr instanceof CopyInstruction and
235237
not instr instanceof FieldAddressInstruction and
@@ -242,7 +244,7 @@ private predicate inheritanceConversionValueNumber(
242244
InheritanceConversionInstruction instr, IRFunction irFunc, Opcode opcode,
243245
Language::Class baseClass, Language::Class derivedClass, TValueNumber operand
244246
) {
245-
instr.getEnclosingIRFunction() = irFunc and
247+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
246248
instr.getOpcode() = opcode and
247249
tvalueNumber(instr.getUnary()) = operand and
248250
unique( | | instr.getBaseClass()) = baseClass and
@@ -254,7 +256,7 @@ private predicate loadTotalOverlapValueNumber0(
254256
LoadTotalOverlapInstruction instr, IRFunction irFunc, IRType type, TValueNumber valueNumber,
255257
boolean isAddress
256258
) {
257-
instr.getEnclosingIRFunction() = irFunc and
259+
unique( | | instr.getEnclosingIRFunction()) = irFunc and
258260
instr.getResultIRType() = type and
259261
(
260262
isAddress = true and

0 commit comments

Comments
 (0)