Skip to content

Commit a052614

Browse files
committed
C++: Two fixes to ensure we don't use getUniqueId in the new range analysis library. (1) don't use it to rank basic blocks, and (2) don't use it in 'toString' on bounds.
1 parent e174123 commit a052614

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/rangeanalysis/Bound.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ValueNumberBound extends Bound, TBoundValueNumber {
7373
this = TBoundValueNumber(valueNumber(result)) and delta = 0
7474
}
7575

76-
override string toString() { result = vn.getExampleInstruction().toString() }
76+
override string toString() { result = "ValueNumberBound" }
7777

7878
override Location getLocation() { result = vn.getLocation() }
7979

cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticExprSpecific.qll

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ module SemanticExprConfig {
112112

113113
predicate hasDominanceInformation(BasicBlock block) { any() }
114114

115-
int getBasicBlockUniqueId(BasicBlock block) {
116-
// REVIEW: `getDisplayIndex()` is not intended for use in real queries, but for now it's the
117-
// best we can do because `equivalentRelation` won't accept a predicate whose parameters are IPA
118-
// types.
119-
result = block.getDisplayIndex()
120-
}
115+
private predicate id(Cpp::Locatable x, Cpp::Locatable y) { x = y }
116+
117+
private predicate idOf(Cpp::Locatable x, int y) = equivalenceRelation(id/2)(x, y)
118+
119+
int getBasicBlockUniqueId(BasicBlock block) { idOf(block.getFirstInstruction().getAst(), result) }
121120

122121
newtype TSsaVariable =
123122
TSsaInstruction(IR::Instruction instr) { instr.hasMemoryResult() } or
@@ -267,17 +266,7 @@ module SemanticExprConfig {
267266

268267
ValueNumberBound() { bound = this }
269268

270-
override string toString() {
271-
result =
272-
min(SsaVariable v |
273-
v.asInstruction() = bound.getValueNumber().getAnInstruction()
274-
|
275-
v
276-
order by
277-
v.asInstruction().getBlock().getDisplayIndex(),
278-
v.asInstruction().getDisplayIndexInBlock()
279-
).toString()
280-
}
269+
override string toString() { result = bound.toString() }
281270
}
282271

283272
predicate zeroBound(Bound bound) { bound instanceof IRBound::ZeroBound }

0 commit comments

Comments
 (0)