Skip to content

Commit d6fba0e

Browse files
committed
C++: Don't create partial defs for calls to const
These partial defs don't do any harm, but they could hurt performance. In typical C++ snapshots, between 5% and 20% of all calls are to `const` functions.
1 parent fd3615d commit d6fba0e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ private module PartialDefinitions {
113113
)
114114
)
115115
} or
116-
TExplicitCallQualifier(Expr qualifier, Call call) { qualifier = call.getQualifier() } or
116+
TExplicitCallQualifier(Expr qualifier) {
117+
exists(Call call |
118+
qualifier = call.getQualifier() and
119+
not call.getTarget().hasSpecifier("const")
120+
)
121+
} or
117122
TReferenceArgument(Expr arg, VariableAccess va) { referenceArgument(va, arg) }
118123

119124
private predicate isInstanceFieldWrite(FieldAccess fa, ControlFlowNode node) {
@@ -128,7 +133,7 @@ private module PartialDefinitions {
128133
PartialDefinition() {
129134
this = TExplicitFieldStoreQualifier(definedExpr, node)
130135
or
131-
this = TExplicitCallQualifier(definedExpr, _) and node = definedExpr
136+
this = TExplicitCallQualifier(definedExpr) and node = definedExpr
132137
or
133138
this = TReferenceArgument(definedExpr, node)
134139
}

cpp/ql/test/library-tests/dataflow/partialdefinitions/partialdefinitions.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
| partialdefinitions.cpp:15:4:15:4 | partial def of y | partialdefinitions.cpp:15:4:15:4 | y | partialdefinitions.cpp:15:2:15:10 | ... = ... |
44
| partialdefinitions.cpp:22:29:22:32 | partial def of this | file://:0:0:0:0 | this | partialdefinitions.cpp:22:29:22:40 | ... = ... |
55
| partialdefinitions.cpp:27:3:27:7 | partial def of myInt | partialdefinitions.cpp:27:3:27:7 | myInt | partialdefinitions.cpp:27:3:27:7 | myInt |
6-
| partialdefinitions.cpp:28:7:28:11 | partial def of myInt | partialdefinitions.cpp:28:7:28:11 | myInt | partialdefinitions.cpp:28:7:28:11 | myInt |
7-
| partialdefinitions.cpp:30:10:30:14 | partial def of myInt | partialdefinitions.cpp:30:10:30:14 | myInt | partialdefinitions.cpp:30:10:30:14 | myInt |

0 commit comments

Comments
 (0)