Skip to content

Commit 243dda7

Browse files
committed
C++: Expose PresentIRFunction and override in cpp/count-ir-inconsistencies
The `toString` implementtion that `PresentIRFunction` uses may result in very long strings that may crash the evaluator. Overriding allows is to limit the string size and still suffices when just counting the number of inconsistencies.
1 parent dd23d48 commit 243dda7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/IRConsistency.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module InstructionConsistency {
2222
abstract Language::Location getLocation();
2323
}
2424

25-
private class PresentIRFunction extends OptionalIRFunction, TPresentIRFunction {
25+
class PresentIRFunction extends OptionalIRFunction, TPresentIRFunction {
2626
private IRFunction irFunc;
2727

2828
PresentIRFunction() { this = TPresentIRFunction(irFunc) }
@@ -37,6 +37,8 @@ module InstructionConsistency {
3737
result =
3838
min(Language::Location loc | loc = irFunc.getLocation() | loc order by loc.toString())
3939
}
40+
41+
IRFunction getIRFunction() { result = irFunc }
4042
}
4143

4244
private class MissingIRFunction extends OptionalIRFunction, TMissingIRFunction {

cpp/ql/src/Metrics/Internal/IRConsistency.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import cpp
1010
import semmle.code.cpp.ir.implementation.aliased_ssa.IR
1111
import semmle.code.cpp.ir.implementation.aliased_ssa.IRConsistency as IRConsistency
1212

13+
class PresentIRFunction extends IRConsistency::PresentIRFunction {
14+
override string toString() {
15+
result = min(string name | name = this.getIRFunction().getFunction().getQualifiedName() | name)
16+
}
17+
}
18+
1319
select count(Instruction i | IRConsistency::missingOperand(i, _, _, _) | i) as missingOperand,
1420
count(Instruction i | IRConsistency::unexpectedOperand(i, _, _, _) | i) as unexpectedOperand,
1521
count(Instruction i | IRConsistency::duplicateOperand(i, _, _, _) | i) as duplicateOperand,

0 commit comments

Comments
 (0)