Skip to content

Commit bcd987c

Browse files
Merge from master and share value numbering
2 parents f76334c + 387e21e commit bcd987c

File tree

32 files changed

+2678
-274
lines changed

32 files changed

+2678
-274
lines changed

config/identical-files.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@
181181
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll",
182182
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll"
183183
],
184+
"C++ IR ValueNumberingImports": [
185+
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/internal/ValueNumberingImports.qll",
186+
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/internal/ValueNumberingImports.qll",
187+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/internal/ValueNumberingImports.qll"
188+
],
184189
"IR SSA SimpleSSA": [
185190
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/SimpleSSA.qll",
186191
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/SimpleSSA.qll"
@@ -195,10 +200,12 @@
195200
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/PrintSSA.qll",
196201
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/PrintSSA.qll"
197202
],
198-
"C++ IR ValueNumber": [
203+
"IR ValueNumber": [
199204
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll",
200205
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll",
201-
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/ValueNumbering.qll"
206+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/ValueNumbering.qll",
207+
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/gvn/ValueNumbering.qll",
208+
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll"
202209
],
203210
"C++ IR ConstantAnalysis": [
204211
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/constant/ConstantAnalysis.qll",
@@ -249,5 +256,9 @@
249256
"C# IR PrintIRImports": [
250257
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/internal/PrintIRImports.qll",
251258
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/PrintIRImports.qll"
259+
],
260+
"C# IR ValueNumberingImports": [
261+
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/gvn/internal/ValueNumberingImports.qll",
262+
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/gvn/internal/ValueNumberingImports.qll"
252263
]
253264
}

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

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
private import internal.ValueNumberingInternal
2-
private import cpp
2+
private import internal.ValueNumberingImports
33
private import IR
44

55
/**
@@ -23,31 +23,31 @@ newtype TValueNumber =
2323
initializeParameterValueNumber(_, irFunc, var)
2424
} or
2525
TInitializeThisValueNumber(IRFunction irFunc) { initializeThisValueNumber(_, irFunc) } or
26-
TConstantValueNumber(IRFunction irFunc, Type type, string value) {
26+
TConstantValueNumber(IRFunction irFunc, IRType type, string value) {
2727
constantValueNumber(_, irFunc, type, value)
2828
} or
29-
TStringConstantValueNumber(IRFunction irFunc, Type type, string value) {
29+
TStringConstantValueNumber(IRFunction irFunc, IRType type, string value) {
3030
stringConstantValueNumber(_, irFunc, type, value)
3131
} or
32-
TFieldAddressValueNumber(IRFunction irFunc, Field field, ValueNumber objectAddress) {
32+
TFieldAddressValueNumber(IRFunction irFunc, Language::Field field, ValueNumber objectAddress) {
3333
fieldAddressValueNumber(_, irFunc, field, objectAddress)
3434
} or
3535
TBinaryValueNumber(
36-
IRFunction irFunc, Opcode opcode, Type type, ValueNumber leftOperand, ValueNumber rightOperand
36+
IRFunction irFunc, Opcode opcode, IRType type, ValueNumber leftOperand, ValueNumber rightOperand
3737
) {
3838
binaryValueNumber(_, irFunc, opcode, type, leftOperand, rightOperand)
3939
} or
4040
TPointerArithmeticValueNumber(
41-
IRFunction irFunc, Opcode opcode, Type type, int elementSize, ValueNumber leftOperand,
41+
IRFunction irFunc, Opcode opcode, IRType type, int elementSize, ValueNumber leftOperand,
4242
ValueNumber rightOperand
4343
) {
4444
pointerArithmeticValueNumber(_, irFunc, opcode, type, elementSize, leftOperand, rightOperand)
4545
} or
46-
TUnaryValueNumber(IRFunction irFunc, Opcode opcode, Type type, ValueNumber operand) {
46+
TUnaryValueNumber(IRFunction irFunc, Opcode opcode, IRType type, ValueNumber operand) {
4747
unaryValueNumber(_, irFunc, opcode, type, operand)
4848
} or
4949
TInheritanceConversionValueNumber(
50-
IRFunction irFunc, Opcode opcode, Class baseClass, Class derivedClass, ValueNumber operand
50+
IRFunction irFunc, Opcode opcode, Language::Class baseClass, Language::Class derivedClass, ValueNumber operand
5151
) {
5252
inheritanceConversionValueNumber(_, irFunc, opcode, baseClass, derivedClass, operand)
5353
} or
@@ -59,7 +59,7 @@ newtype TValueNumber =
5959
class ValueNumber extends TValueNumber {
6060
final string toString() { result = getExampleInstruction().getResultId() }
6161

62-
final Location getLocation() { result = getExampleInstruction().getLocation() }
62+
final Language::Location getLocation() { result = getExampleInstruction().getLocation() }
6363

6464
/**
6565
* Gets the instructions that have been assigned this value number. This will always produce at
@@ -150,67 +150,67 @@ private predicate initializeThisValueNumber(InitializeThisInstruction instr, IRF
150150
}
151151

152152
private predicate constantValueNumber(
153-
ConstantInstruction instr, IRFunction irFunc, Type type, string value
153+
ConstantInstruction instr, IRFunction irFunc, IRType type, string value
154154
) {
155155
instr.getEnclosingIRFunction() = irFunc and
156-
instr.getResultType() = type and
156+
instr.getResultIRType() = type and
157157
instr.getValue() = value
158158
}
159159

160160
private predicate stringConstantValueNumber(
161-
StringConstantInstruction instr, IRFunction irFunc, Type type, string value
161+
StringConstantInstruction instr, IRFunction irFunc, IRType type, string value
162162
) {
163163
instr.getEnclosingIRFunction() = irFunc and
164-
instr.getResultType() = type and
164+
instr.getResultIRType() = type and
165165
instr.getValue().getValue() = value
166166
}
167167

168168
private predicate fieldAddressValueNumber(
169-
FieldAddressInstruction instr, IRFunction irFunc, Field field, ValueNumber objectAddress
169+
FieldAddressInstruction instr, IRFunction irFunc, Language::Field field, ValueNumber objectAddress
170170
) {
171171
instr.getEnclosingIRFunction() = irFunc and
172172
instr.getField() = field and
173173
valueNumber(instr.getObjectAddress()) = objectAddress
174174
}
175175

176176
private predicate binaryValueNumber(
177-
BinaryInstruction instr, IRFunction irFunc, Opcode opcode, Type type, ValueNumber leftOperand,
177+
BinaryInstruction instr, IRFunction irFunc, Opcode opcode, IRType type, ValueNumber leftOperand,
178178
ValueNumber rightOperand
179179
) {
180180
instr.getEnclosingIRFunction() = irFunc and
181181
not instr instanceof PointerArithmeticInstruction and
182182
instr.getOpcode() = opcode and
183-
instr.getResultType() = type and
183+
instr.getResultIRType() = type and
184184
valueNumber(instr.getLeft()) = leftOperand and
185185
valueNumber(instr.getRight()) = rightOperand
186186
}
187187

188188
private predicate pointerArithmeticValueNumber(
189-
PointerArithmeticInstruction instr, IRFunction irFunc, Opcode opcode, Type type, int elementSize,
189+
PointerArithmeticInstruction instr, IRFunction irFunc, Opcode opcode, IRType type, int elementSize,
190190
ValueNumber leftOperand, ValueNumber rightOperand
191191
) {
192192
instr.getEnclosingIRFunction() = irFunc and
193193
instr.getOpcode() = opcode and
194-
instr.getResultType() = type and
194+
instr.getResultIRType() = type and
195195
instr.getElementSize() = elementSize and
196196
valueNumber(instr.getLeft()) = leftOperand and
197197
valueNumber(instr.getRight()) = rightOperand
198198
}
199199

200200
private predicate unaryValueNumber(
201-
UnaryInstruction instr, IRFunction irFunc, Opcode opcode, Type type, ValueNumber operand
201+
UnaryInstruction instr, IRFunction irFunc, Opcode opcode, IRType type, ValueNumber operand
202202
) {
203203
instr.getEnclosingIRFunction() = irFunc and
204204
not instr instanceof InheritanceConversionInstruction and
205205
not instr instanceof CopyInstruction and
206206
instr.getOpcode() = opcode and
207-
instr.getResultType() = type and
207+
instr.getResultIRType() = type and
208208
valueNumber(instr.getUnary()) = operand
209209
}
210210

211211
private predicate inheritanceConversionValueNumber(
212-
InheritanceConversionInstruction instr, IRFunction irFunc, Opcode opcode, Class baseClass,
213-
Class derivedClass, ValueNumber operand
212+
InheritanceConversionInstruction instr, IRFunction irFunc, Opcode opcode,
213+
Language::Class baseClass, Language::Class derivedClass, ValueNumber operand
214214
) {
215215
instr.getEnclosingIRFunction() = irFunc and
216216
instr.getOpcode() = opcode and
@@ -225,7 +225,7 @@ private predicate inheritanceConversionValueNumber(
225225
*/
226226
private predicate uniqueValueNumber(Instruction instr, IRFunction irFunc) {
227227
instr.getEnclosingIRFunction() = irFunc and
228-
not instr.getResultType() instanceof VoidType and
228+
not instr.getResultIRType() instanceof IRVoidType and
229229
not numberableInstruction(instr)
230230
}
231231

@@ -269,38 +269,39 @@ private ValueNumber nonUniqueValueNumber(Instruction instr) {
269269
initializeThisValueNumber(instr, irFunc) and
270270
result = TInitializeThisValueNumber(irFunc)
271271
or
272-
exists(Type type, string value |
272+
exists(IRType type, string value |
273273
constantValueNumber(instr, irFunc, type, value) and
274274
result = TConstantValueNumber(irFunc, type, value)
275275
)
276276
or
277-
exists(Type type, string value |
277+
exists(IRType type, string value |
278278
stringConstantValueNumber(instr, irFunc, type, value) and
279279
result = TStringConstantValueNumber(irFunc, type, value)
280280
)
281281
or
282-
exists(Field field, ValueNumber objectAddress |
282+
exists(Language::Field field, ValueNumber objectAddress |
283283
fieldAddressValueNumber(instr, irFunc, field, objectAddress) and
284284
result = TFieldAddressValueNumber(irFunc, field, objectAddress)
285285
)
286286
or
287-
exists(Opcode opcode, Type type, ValueNumber leftOperand, ValueNumber rightOperand |
287+
exists(Opcode opcode, IRType type, ValueNumber leftOperand, ValueNumber rightOperand |
288288
binaryValueNumber(instr, irFunc, opcode, type, leftOperand, rightOperand) and
289289
result = TBinaryValueNumber(irFunc, opcode, type, leftOperand, rightOperand)
290290
)
291291
or
292-
exists(Opcode opcode, Type type, ValueNumber operand |
292+
exists(Opcode opcode, IRType type, ValueNumber operand |
293293
unaryValueNumber(instr, irFunc, opcode, type, operand) and
294294
result = TUnaryValueNumber(irFunc, opcode, type, operand)
295295
)
296296
or
297-
exists(Opcode opcode, Class baseClass, Class derivedClass, ValueNumber operand |
297+
exists(Opcode opcode, Language::Class baseClass, Language::Class derivedClass,
298+
ValueNumber operand |
298299
inheritanceConversionValueNumber(instr, irFunc, opcode, baseClass, derivedClass, operand) and
299300
result = TInheritanceConversionValueNumber(irFunc, opcode, baseClass, derivedClass, operand)
300301
)
301302
or
302303
exists(
303-
Opcode opcode, Type type, int elementSize, ValueNumber leftOperand, ValueNumber rightOperand
304+
Opcode opcode, IRType type, int elementSize, ValueNumber leftOperand, ValueNumber rightOperand
304305
|
305306
pointerArithmeticValueNumber(instr, irFunc, opcode, type, elementSize, leftOperand,
306307
rightOperand) and
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import semmle.code.cpp.ir.internal.Overlap
2+
import semmle.code.cpp.ir.internal.IRCppLanguage as Language

0 commit comments

Comments
 (0)