Skip to content

Commit 1ad548b

Browse files
authored
Merge pull request #306 from microsoft/macro-flow-partial-expr
C++: Support macro flow when the macro generates a child expression o…
2 parents 80b6ab1 + dff05eb commit 1ad548b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

cpp/ql/lib/semmle/code/cpp/macroflow/MacroFlow.qll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ module MacroFlow {
3838
* based on the given configuration.
3939
*/
4040
module Make<ConfigSig Config> {
41+
private predicate hasChildSink(Expr e) { Config::isSink(e.getAChild*()) }
42+
4143
private predicate rev(MacroInvocation mi) {
42-
Config::isSink(mi.getExpr())
44+
hasChildSink(mi.getExpr())
4345
or
4446
exists(MacroInvocation mi1 | rev(mi1) | mi.getParentInvocation() = mi1)
4547
}
@@ -61,7 +63,7 @@ module MacroFlow {
6163
private newtype TNode =
6264
TMacroInvocationNode(MacroInvocation mi) { fwd(mi) } or
6365
TExprNode(Expr e) {
64-
Config::isSink(e) and
66+
hasChildSink(e) and
6567
(
6668
exists(MacroInvocation mi |
6769
fwd(mi) and
@@ -138,7 +140,7 @@ module MacroFlow {
138140
)
139141
}
140142

141-
private predicate isSinkNode(Node n) { Config::isSink(n.(ExprNode).getExpr()) }
143+
private predicate isSinkNode(Node n) { hasChildSink(n.(ExprNode).getExpr()) }
142144

143145
private predicate isSourceNode(Node n) {
144146
isSource(n.(MacroInvocationNode).getMacroInvocation())
@@ -159,9 +161,16 @@ module MacroFlow {
159161
isSinkNode(n2)
160162
}
161163

162-
predicate flowsTo(Node n, ExprNode n2, Expr e) {
164+
predicate flowsTo(Node n, ExprNode n2, Expr e, boolean exact) {
163165
stepsStar(n, n2) and
164-
n2.getExpr() = e
166+
Config::isSink(e) and
167+
(
168+
n2.getExpr() = e and
169+
exact = true
170+
or
171+
n2.getExpr().getAChild+() = e and
172+
exact = false
173+
)
165174
}
166175

167176
/**

0 commit comments

Comments
 (0)