Skip to content

Commit 47096bb

Browse files
authored
Merge pull request #318 from geoffw0/overflowstatic
CPP: Speed up OverflowStatic.ql
2 parents c2e7627 + a9b5553 commit 47096bb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

cpp/ql/src/semmle/code/cpp/commons/Buffer.qll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,21 @@ int getBufferSize(Expr bufferExpr, Element why) {
8383
// buffer is a fixed size dynamic allocation
8484
isFixedSizeAllocationExpr(bufferExpr, result) and
8585
why = bufferExpr
86-
) or (
86+
) or exists(DataFlow::ExprNode bufferExprNode |
8787
// dataflow (all sources must be the same size)
88+
bufferExprNode = DataFlow::exprNode(bufferExpr) and
89+
8890
result = min(Expr def |
89-
DataFlow::localFlowStep(DataFlow::exprNode(def), DataFlow::exprNode(bufferExpr)) |
91+
DataFlow::localFlowStep(DataFlow::exprNode(def), bufferExprNode) |
9092
getBufferSize(def, _)
9193
) and result = max(Expr def |
92-
DataFlow::localFlowStep(DataFlow::exprNode(def), DataFlow::exprNode(bufferExpr)) |
94+
DataFlow::localFlowStep(DataFlow::exprNode(def), bufferExprNode) |
9395
getBufferSize(def, _)
9496
) and
9597

9698
// find reason
9799
exists(Expr def |
98-
DataFlow::localFlowStep(DataFlow::exprNode(def), DataFlow::exprNode(bufferExpr)) |
100+
DataFlow::localFlowStep(DataFlow::exprNode(def), bufferExprNode) |
99101
why = def or
100102
exists(getBufferSize(def, why))
101103
)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,17 @@ cached library class SSAHelper extends int {
124124
* Modern Compiler Implementation by Andrew Appel.
125125
*/
126126
private predicate frontier_phi_node(LocalScopeVariable v, BasicBlock b) {
127-
exists(BasicBlock x | dominanceFrontier(x, b) and ssa_defn(v, _, x, _))
127+
exists(BasicBlock x | dominanceFrontier(x, b) and ssa_defn_rec(v, x))
128128
/* We can also eliminate those nodes where the variable is not live on any incoming edge */
129129
and live_at_start_of_bb(v, b)
130130
}
131131

132+
private predicate ssa_defn_rec(LocalScopeVariable v, BasicBlock b) {
133+
phi_node(v, b)
134+
or
135+
variableUpdate(v, _, b, _)
136+
}
137+
132138
/**
133139
* Holds if `v` is defined, for the purpose of SSA, at `node`, which is at
134140
* position `index` in block `b`. This includes definitions from phi nodes.

0 commit comments

Comments
 (0)