Skip to content

Commit a556152

Browse files
committed
C++: Fix asDefinition to not only work for SSA definitions.
1 parent e58a833 commit a556152

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ class Node extends TIRDataFlowNode {
312312
*/
313313
Expr asDefinition() { result = this.asDefinition(_) }
314314

315+
private predicate isCertainStore() {
316+
exists(SsaImpl::Definition def |
317+
SsaImpl::defToNode(this, def, _) and
318+
def.isCertain()
319+
)
320+
}
321+
315322
/**
316323
* Gets the definition associated with this node, if any.
317324
*
@@ -361,11 +368,10 @@ class Node extends TIRDataFlowNode {
361368
* pointed to by `p`.
362369
*/
363370
Expr asDefinition(boolean uncertain) {
364-
exists(StoreInstruction store, SsaImpl::Definition def |
371+
exists(StoreInstruction store |
365372
store = this.asInstruction() and
366373
result = asDefinitionImpl(store) and
367-
SsaImpl::defToNode(this, def, _) and
368-
if def.isCertain() then uncertain = false else uncertain = true
374+
if this.isCertainStore() then uncertain = false else uncertain = true
369375
)
370376
}
371377

cpp/ql/test/library-tests/dataflow/asDefinition/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ void test() {
1010
y = 44; // $ asDefinition="... = ..."
1111
use(y);
1212

13-
int x = 43; // $ MISSING: asDefinition=43
14-
x = 44; // $ MISSING: asDefinition="... = ..."
13+
int x = 43; // $ asDefinition=43
14+
x = 44; // $ asDefinition="... = ..."
1515

1616
S s;
17-
s.x = 42; // $ MISSING: asDefinition="... = ..."
17+
s.x = 42; // $ asDefinition="... = ..."
1818
}

0 commit comments

Comments
 (0)