Skip to content

Commit 8fb5714

Browse files
authored
Merge pull request #10069 from jketema/ir-present
C++: Expose `PresentIRFunction` and override in `cpp/count-ir-inconsistencies`
2 parents dd23d48 + 31aa669 commit 8fb5714

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
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/lib/semmle/code/cpp/ir/implementation/raw/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/lib/semmle/code/cpp/ir/implementation/unaliased_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,

csharp/ql/src/experimental/ir/implementation/raw/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 {

csharp/ql/src/experimental/ir/implementation/unaliased_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 {

0 commit comments

Comments
 (0)