Skip to content

Commit e57f98c

Browse files
committed
C++: Use StackVariable in def-use libraries
Most of the implementation was already in terms of `SemanticStackVariable`, so not much should have changed.
1 parent 95a333d commit e57f98c

File tree

6 files changed

+15
-17
lines changed

6 files changed

+15
-17
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/DefinitionsAndUses.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cpp
2-
private import semmle.code.cpp.controlflow.LocalScopeVariableReachability
2+
private import semmle.code.cpp.controlflow.StackVariableReachability
33
private import semmle.code.cpp.dataflow.EscapesTree
44

55
/**
@@ -108,7 +108,7 @@ library class DefOrUse extends ControlFlowNodeBase {
108108
/*
109109
* Implementation detail: this predicate and its private auxiliary
110110
* predicates are instances of the more general predicates in
111-
* LocalScopeVariableReachability.qll, and should be kept in sync.
111+
* StackVariableReachability.qll, and should be kept in sync.
112112
*
113113
* Unfortunately, caching of abstract predicates does not work well, so the
114114
* predicates are duplicated for now.

cpp/ql/test/library-tests/defuse/definitionUsePairEquivalence.ql

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import cpp
2-
import semmle.code.cpp.controlflow.LocalScopeVariableReachability
2+
import semmle.code.cpp.controlflow.StackVariableReachability
33

4-
// Test that def/use algorithm is an instance of LocalScopeVariableReachability
5-
class MyDefOrUse extends LocalScopeVariableReachability {
4+
// Test that def/use algorithm is an instance of StackVariableReachability
5+
class MyDefOrUse extends StackVariableReachability {
66
MyDefOrUse() { this = "MyDefUse" }
77

8-
override predicate isSource(ControlFlowNode node, LocalScopeVariable v) { definition(v, node) }
8+
override predicate isSource(ControlFlowNode node, StackVariable v) { definition(v, node) }
99

10-
override predicate isSink(ControlFlowNode node, LocalScopeVariable v) { useOfVar(v, node) }
10+
override predicate isSink(ControlFlowNode node, StackVariable v) { useOfVar(v, node) }
1111

12-
override predicate isBarrier(ControlFlowNode node, LocalScopeVariable v) {
13-
definitionBarrier(v, node)
14-
}
12+
override predicate isBarrier(ControlFlowNode node, StackVariable v) { definitionBarrier(v, node) }
1513
}
1614

1715
predicate equivalence() {
18-
forall(LocalScopeVariable v, Expr first, Expr second | definitionUsePair(v, first, second) |
16+
forall(StackVariable v, Expr first, Expr second | definitionUsePair(v, first, second) |
1917
exists(MyDefOrUse x | x.reaches(first, v, second))
2018
) and
21-
forall(LocalScopeVariable v, Expr first, Expr second |
19+
forall(StackVariable v, Expr first, Expr second |
2220
exists(MyDefOrUse x | x.reaches(first, v, second))
2321
|
2422
definitionUsePair(v, first, second)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cpp
22

3-
from LocalScopeVariable v, ControlFlowNode def, Expr e
3+
from StackVariable v, ControlFlowNode def, Expr e
44
where exprDefinition(v, def, e)
55
select v, def, e
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cpp
22

3-
from LocalScopeVariable v, VariableAccess use
3+
from StackVariable v, VariableAccess use
44
where useOfVar(v, use)
55
select v, use
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import cpp
22

3-
from LocalScopeVariable v, VariableAccess use
3+
from StackVariable v, VariableAccess use
44
where
55
useOfVarActual(v, use) and
66
// Also check that `useOfVarActual` is a subset of `useOfVar`; if not
77
// the query will not return any results
8-
forall(LocalScopeVariable v0, VariableAccess use0 | useOfVarActual(v0, use0) | useOfVar(v0, use0))
8+
forall(StackVariable v0, VariableAccess use0 | useOfVarActual(v0, use0) | useOfVar(v0, use0))
99
select v, use
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cpp
22

3-
from LocalScopeVariable v, ControlFlowNode def, Expr e
3+
from StackVariable v, ControlFlowNode def, Expr e
44
where exprDefinition(v, def, e)
55
select v, def, e

0 commit comments

Comments
 (0)