Skip to content

Commit 1878d04

Browse files
committed
C++/C#: sync files and update imports
1 parent 0c43a16 commit 1878d04

File tree

17 files changed

+118
-0
lines changed

17 files changed

+118
-0
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/IRBlock.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class IRBlockBase extends TIRBlock {
2727
* by debugging and printing code only.
2828
*/
2929
int getDisplayIndex() {
30+
exists(IRConfiguration config |
31+
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
32+
) and
3033
this =
3134
rank[result + 1](IRBlock funcBlock |
3235
funcBlock.getEnclosingFunction() = getEnclosingFunction()

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ module InstructionSanity {
283283
* `File` and line number. Used for assigning register names when printing IR.
284284
*/
285285
private Instruction getAnInstructionAtLine(IRFunction irFunc, Language::File file, int line) {
286+
exists(IRConfiguration config |
287+
config.shouldEvaluateDebugStringsForFunction(irFunc.getFunction())
288+
) and
286289
exists(Language::Location location |
287290
irFunc = result.getEnclosingIRFunction() and
288291
location = result.getLocation() and
@@ -307,13 +310,19 @@ class Instruction extends Construction::TInstruction {
307310
result = getResultString() + " = " + getOperationString() + " " + getOperandsString()
308311
}
309312

313+
predicate shouldGenerateDumpStrings() {
314+
exists(IRConfiguration config |
315+
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
316+
)
317+
}
310318
/**
311319
* Gets a string describing the operation of this instruction. This includes
312320
* the opcode and the immediate value, if any. For example:
313321
*
314322
* VariableAddress[x]
315323
*/
316324
final string getOperationString() {
325+
shouldGenerateDumpStrings() and
317326
if exists(getImmediateString())
318327
then result = getOperationPrefix() + getOpcode().toString() + "[" + getImmediateString() + "]"
319328
else result = getOperationPrefix() + getOpcode().toString()
@@ -325,10 +334,12 @@ class Instruction extends Construction::TInstruction {
325334
string getImmediateString() { none() }
326335

327336
private string getOperationPrefix() {
337+
shouldGenerateDumpStrings() and
328338
if this instanceof SideEffectInstruction then result = "^" else result = ""
329339
}
330340

331341
private string getResultPrefix() {
342+
shouldGenerateDumpStrings() and
332343
if getResultIRType() instanceof IRVoidType
333344
then result = "v"
334345
else
@@ -342,6 +353,7 @@ class Instruction extends Construction::TInstruction {
342353
* used by debugging and printing code only.
343354
*/
344355
int getDisplayIndexInBlock() {
356+
shouldGenerateDumpStrings() and
345357
exists(IRBlock block |
346358
this = block.getInstruction(result)
347359
or
@@ -355,6 +367,7 @@ class Instruction extends Construction::TInstruction {
355367
}
356368

357369
private int getLineRank() {
370+
shouldGenerateDumpStrings() and
358371
this =
359372
rank[result](Instruction instr |
360373
instr =
@@ -373,6 +386,7 @@ class Instruction extends Construction::TInstruction {
373386
* Example: `r1_1`
374387
*/
375388
string getResultId() {
389+
shouldGenerateDumpStrings() and
376390
result = getResultPrefix() + getAST().getLocation().getStartLine() + "_" + getLineRank()
377391
}
378392

@@ -384,6 +398,7 @@ class Instruction extends Construction::TInstruction {
384398
* Example: `r1_1(int*)`
385399
*/
386400
final string getResultString() {
401+
shouldGenerateDumpStrings() and
387402
result = getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
388403
}
389404

@@ -394,6 +409,7 @@ class Instruction extends Construction::TInstruction {
394409
* Example: `func:r3_4, this:r3_5`
395410
*/
396411
string getOperandsString() {
412+
shouldGenerateDumpStrings() and
397413
result =
398414
concat(Operand operand |
399415
operand = getAnOperand()

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/PrintIR.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ class PrintIRConfiguration extends TPrintIRConfiguration {
1818
predicate shouldPrintFunction(Language::Function func) { any() }
1919
}
2020

21+
/**
22+
* Override of `IRConfiguration` to only evaluate debug strings for the functions that are to be dumped.
23+
*/
24+
private class FilteredIRConfiguration extends IRConfiguration {
25+
override predicate shouldEvaluateDebugStringsForFunction(Language::Function func) {
26+
shouldPrintFunction(func)
27+
}
28+
}
29+
2130
private predicate shouldPrintFunction(Language::Function func) {
2231
exists(PrintIRConfiguration config | config.shouldPrintFunction(func))
2332
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import semmle.code.cpp.ir.internal.IRCppLanguage as Language
22
import IRConstruction as Construction
3+
import semmle.code.cpp.ir.implementation.IRConfiguration as IRConfiguration

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/IRBlock.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class IRBlockBase extends TIRBlock {
2727
* by debugging and printing code only.
2828
*/
2929
int getDisplayIndex() {
30+
exists(IRConfiguration config |
31+
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
32+
) and
3033
this =
3134
rank[result + 1](IRBlock funcBlock |
3235
funcBlock.getEnclosingFunction() = getEnclosingFunction()

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ module InstructionSanity {
283283
* `File` and line number. Used for assigning register names when printing IR.
284284
*/
285285
private Instruction getAnInstructionAtLine(IRFunction irFunc, Language::File file, int line) {
286+
exists(IRConfiguration config |
287+
config.shouldEvaluateDebugStringsForFunction(irFunc.getFunction())
288+
) and
286289
exists(Language::Location location |
287290
irFunc = result.getEnclosingIRFunction() and
288291
location = result.getLocation() and
@@ -307,13 +310,19 @@ class Instruction extends Construction::TInstruction {
307310
result = getResultString() + " = " + getOperationString() + " " + getOperandsString()
308311
}
309312

313+
predicate shouldGenerateDumpStrings() {
314+
exists(IRConfiguration config |
315+
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
316+
)
317+
}
310318
/**
311319
* Gets a string describing the operation of this instruction. This includes
312320
* the opcode and the immediate value, if any. For example:
313321
*
314322
* VariableAddress[x]
315323
*/
316324
final string getOperationString() {
325+
shouldGenerateDumpStrings() and
317326
if exists(getImmediateString())
318327
then result = getOperationPrefix() + getOpcode().toString() + "[" + getImmediateString() + "]"
319328
else result = getOperationPrefix() + getOpcode().toString()
@@ -325,10 +334,12 @@ class Instruction extends Construction::TInstruction {
325334
string getImmediateString() { none() }
326335

327336
private string getOperationPrefix() {
337+
shouldGenerateDumpStrings() and
328338
if this instanceof SideEffectInstruction then result = "^" else result = ""
329339
}
330340

331341
private string getResultPrefix() {
342+
shouldGenerateDumpStrings() and
332343
if getResultIRType() instanceof IRVoidType
333344
then result = "v"
334345
else
@@ -342,6 +353,7 @@ class Instruction extends Construction::TInstruction {
342353
* used by debugging and printing code only.
343354
*/
344355
int getDisplayIndexInBlock() {
356+
shouldGenerateDumpStrings() and
345357
exists(IRBlock block |
346358
this = block.getInstruction(result)
347359
or
@@ -355,6 +367,7 @@ class Instruction extends Construction::TInstruction {
355367
}
356368

357369
private int getLineRank() {
370+
shouldGenerateDumpStrings() and
358371
this =
359372
rank[result](Instruction instr |
360373
instr =
@@ -373,6 +386,7 @@ class Instruction extends Construction::TInstruction {
373386
* Example: `r1_1`
374387
*/
375388
string getResultId() {
389+
shouldGenerateDumpStrings() and
376390
result = getResultPrefix() + getAST().getLocation().getStartLine() + "_" + getLineRank()
377391
}
378392

@@ -384,6 +398,7 @@ class Instruction extends Construction::TInstruction {
384398
* Example: `r1_1(int*)`
385399
*/
386400
final string getResultString() {
401+
shouldGenerateDumpStrings() and
387402
result = getResultId() + "(" + getResultLanguageType().getDumpString() + ")"
388403
}
389404

@@ -394,6 +409,7 @@ class Instruction extends Construction::TInstruction {
394409
* Example: `func:r3_4, this:r3_5`
395410
*/
396411
string getOperandsString() {
412+
shouldGenerateDumpStrings() and
397413
result =
398414
concat(Operand operand |
399415
operand = getAnOperand()

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ class PrintIRConfiguration extends TPrintIRConfiguration {
1818
predicate shouldPrintFunction(Language::Function func) { any() }
1919
}
2020

21+
/**
22+
* Override of `IRConfiguration` to only evaluate debug strings for the functions that are to be dumped.
23+
*/
24+
private class FilteredIRConfiguration extends IRConfiguration {
25+
override predicate shouldEvaluateDebugStringsForFunction(Language::Function func) {
26+
shouldPrintFunction(func)
27+
}
28+
}
29+
2130
private predicate shouldPrintFunction(Language::Function func) {
2231
exists(PrintIRConfiguration config | config.shouldPrintFunction(func))
2332
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import semmle.code.cpp.ir.internal.IRCppLanguage as Language
22
import SSAConstruction as Construction
3+
import semmle.code.cpp.ir.implementation.IRConfiguration as IRConfiguration

csharp/ql/src/semmle/code/csharp/ir/implementation/IRConfiguration.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class IRConfiguration extends TIRConfiguration {
1616
* Holds if IR should be created for function `func`. By default, holds for all functions.
1717
*/
1818
predicate shouldCreateIRForFunction(Language::Function func) { any() }
19+
20+
predicate shouldEvaluateDebugStringsForFunction(Language::Function func) { any() }
1921
}
2022

2123
private newtype TIREscapeAnalysisConfiguration = MkIREscapeAnalysisConfiguration()

csharp/ql/src/semmle/code/csharp/ir/implementation/raw/IRBlock.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class IRBlockBase extends TIRBlock {
2727
* by debugging and printing code only.
2828
*/
2929
int getDisplayIndex() {
30+
exists(IRConfiguration config |
31+
config.shouldEvaluateDebugStringsForFunction(this.getEnclosingFunction())
32+
) and
3033
this =
3134
rank[result + 1](IRBlock funcBlock |
3235
funcBlock.getEnclosingFunction() = getEnclosingFunction()

0 commit comments

Comments
 (0)