Skip to content

Commit 8085460

Browse files
committed
C++/Shared: Fix join order issues.
1 parent 5c635e9 commit 8085460

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,39 +1285,35 @@ module IsUnreachableInCall {
12851285
predicate isUnreachableInCall(NodeRegion block, DataFlowCall call) {
12861286
exists(
12871287
InstructionDirectParameterNode paramNode, ConstantIntegralTypeArgumentNode arg,
1288-
IntegerConstantInstruction constant, int k, Operand left, Operand right
1288+
IntegerConstantInstruction constant, int k, Operand left, Operand right, int argval
12891289
|
12901290
// arg flows into `paramNode`
1291-
DataFlowImplCommon::viableParamArg(call, paramNode, arg) and
1291+
DataFlowImplCommon::viableParamArg(call, pragma[only_bind_into](paramNode),
1292+
pragma[only_bind_into](arg)) and
12921293
left = constant.getAUse() and
1293-
right = valueNumber(paramNode.getInstruction()).getAUse()
1294+
right = valueNumber(paramNode.getInstruction()).getAUse() and
1295+
argval = arg.getValue()
12941296
|
12951297
// and there's a guard condition which ensures that the result of `left == right + k` is `areEqual`
1296-
exists(boolean areEqual |
1297-
ensuresEq(pragma[only_bind_into](left), pragma[only_bind_into](right),
1298-
pragma[only_bind_into](k), pragma[only_bind_into](block), areEqual)
1299-
|
1298+
exists(boolean areEqual | ensuresEq(left, right, k, block, areEqual) |
13001299
// this block ensures that left = right + k, but it holds that `left != right + k`
13011300
areEqual = true and
1302-
constant.getValue().toInt() != arg.getValue() + k
1301+
constant.getValue().toInt() != argval + k
13031302
or
13041303
// this block ensures that or `left != right + k`, but it holds that `left = right + k`
13051304
areEqual = false and
1306-
constant.getValue().toInt() = arg.getValue() + k
1305+
constant.getValue().toInt() = argval + k
13071306
)
13081307
or
13091308
// or there's a guard condition which ensures that the result of `left < right + k` is `isLessThan`
1310-
exists(boolean isLessThan |
1311-
ensuresLt(pragma[only_bind_into](left), pragma[only_bind_into](right),
1312-
pragma[only_bind_into](k), pragma[only_bind_into](block), isLessThan)
1313-
|
1309+
exists(boolean isLessThan | ensuresLt(left, right, k, block, isLessThan) |
13141310
isLessThan = true and
13151311
// this block ensures that `left < right + k`, but it holds that `left >= right + k`
1316-
constant.getValue().toInt() >= arg.getValue() + k
1312+
constant.getValue().toInt() >= argval + k
13171313
or
13181314
// this block ensures that `left >= right + k`, but it holds that `left < right + k`
13191315
isLessThan = false and
1320-
constant.getValue().toInt() < arg.getValue() + k
1316+
constant.getValue().toInt() < argval + k
13211317
)
13221318
)
13231319
}

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
530530

531531
TCallEdge getAValue(TCallEdge ctxEdge) {
532532
exists(DataFlowCall ctx, DataFlowCallable c, DataFlowCall call, DataFlowCallable tgt |
533-
ctxEdge = TMkCallEdge(ctx, c) and
534-
result = TMkCallEdge(call, tgt) and
533+
ctxEdge = mkCallEdge(ctx, c) and
534+
result = mkCallEdge(call, tgt) and
535535
viableImplInCallContextExtIn(call, ctx) = tgt and
536536
reducedViableImplInCallContext(call, c, ctx)
537537
)
@@ -1505,7 +1505,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
15051505

15061506
NodeRegion getAValue(TCallEdge edge) {
15071507
exists(DataFlowCall call, DataFlowCallable tgt |
1508-
edge = TMkCallEdge(call, tgt) and
1508+
edge = mkCallEdge(call, tgt) and
15091509
getNodeRegionEnclosingCallable(result) = tgt and
15101510
isUnreachableInCallCached(result, call)
15111511
)
@@ -1598,6 +1598,12 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
15981598
TApproxAccessPathFrontSome(ApproxAccessPathFront apf)
15991599
}
16001600

1601+
bindingset[call, tgt]
1602+
pragma[inline_late]
1603+
private TCallEdge mkCallEdge(DataFlowCall call, DataFlowCallable tgt) {
1604+
result = TMkCallEdge(call, tgt)
1605+
}
1606+
16011607
bindingset[t1, t2]
16021608
pragma[inline_late]
16031609
private predicate typeStrongerThan0(DataFlowType t1, DataFlowType t2) { typeStrongerThan(t1, t2) }

0 commit comments

Comments
 (0)