Skip to content

Commit dfb3483

Browse files
authored
Merge pull request github#18307 from MathiasVP/fix-more-join-orders-in-dataflow
C++: Fix two more dataflow-related joins
2 parents 8efd870 + 2cc6ffb commit dfb3483

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,12 +1237,14 @@ module IsUnreachableInCall {
12371237
int getValue() { result = value }
12381238
}
12391239

1240-
pragma[nomagic]
1240+
bindingset[right]
1241+
pragma[inline_late]
12411242
private predicate ensuresEq(Operand left, Operand right, int k, IRBlock block, boolean areEqual) {
12421243
any(G::IRGuardCondition guard).ensuresEq(left, right, k, block, areEqual)
12431244
}
12441245

1245-
pragma[nomagic]
1246+
bindingset[right]
1247+
pragma[inline_late]
12461248
private predicate ensuresLt(Operand left, Operand right, int k, IRBlock block, boolean areEqual) {
12471249
any(G::IRGuardCondition guard).ensuresLt(left, right, k, block, areEqual)
12481250
}

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,7 @@ private predicate guardControlsPhiInput(
22752275
*/
22762276
signature predicate guardChecksSig(IRGuardCondition g, Expr e, boolean branch);
22772277

2278-
bindingset[g, n]
2278+
bindingset[g]
22792279
pragma[inline_late]
22802280
private predicate controls(IRGuardCondition g, Node n, boolean edge) {
22812281
g.controls(n.getBasicBlock(), edge)
@@ -2288,6 +2288,15 @@ private predicate controls(IRGuardCondition g, Node n, boolean edge) {
22882288
* in data flow and taint tracking.
22892289
*/
22902290
module BarrierGuard<guardChecksSig/3 guardChecks> {
2291+
bindingset[value, n]
2292+
pragma[inline_late]
2293+
private predicate convertedExprHasValueNumber(ValueNumber value, Node n) {
2294+
exists(Expr e |
2295+
e = value.getAnInstruction().getConvertedResultExpression() and
2296+
n.asConvertedExpr() = e
2297+
)
2298+
}
2299+
22912300
/**
22922301
* Gets an expression node that is safely guarded by the given guard check.
22932302
*
@@ -2321,9 +2330,8 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
23212330
* NOTE: If an indirect expression is tracked, use `getAnIndirectBarrierNode` instead.
23222331
*/
23232332
Node getABarrierNode() {
2324-
exists(IRGuardCondition g, Expr e, ValueNumber value, boolean edge |
2325-
e = value.getAnInstruction().getConvertedResultExpression() and
2326-
result.asConvertedExpr() = e and
2333+
exists(IRGuardCondition g, ValueNumber value, boolean edge |
2334+
convertedExprHasValueNumber(value, result) and
23272335
guardChecks(g,
23282336
pragma[only_bind_into](value.getAnInstruction().getConvertedResultExpression()), edge) and
23292337
controls(g, result, edge)
@@ -2374,6 +2382,17 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
23742382
*/
23752383
Node getAnIndirectBarrierNode() { result = getAnIndirectBarrierNode(_) }
23762384

2385+
bindingset[value, n]
2386+
pragma[inline_late]
2387+
private predicate indirectConvertedExprHasValueNumber(
2388+
int indirectionIndex, ValueNumber value, Node n
2389+
) {
2390+
exists(Expr e |
2391+
e = value.getAnInstruction().getConvertedResultExpression() and
2392+
n.asIndirectConvertedExpr(indirectionIndex) = e
2393+
)
2394+
}
2395+
23772396
/**
23782397
* Gets an indirect expression node with indirection index `indirectionIndex` that is
23792398
* safely guarded by the given guard check.
@@ -2409,9 +2428,8 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
24092428
* NOTE: If a non-indirect expression is tracked, use `getABarrierNode` instead.
24102429
*/
24112430
Node getAnIndirectBarrierNode(int indirectionIndex) {
2412-
exists(IRGuardCondition g, Expr e, ValueNumber value, boolean edge |
2413-
e = value.getAnInstruction().getConvertedResultExpression() and
2414-
result.asIndirectConvertedExpr(indirectionIndex) = e and
2431+
exists(IRGuardCondition g, ValueNumber value, boolean edge |
2432+
indirectConvertedExprHasValueNumber(indirectionIndex, value, result) and
24152433
guardChecks(g,
24162434
pragma[only_bind_into](value.getAnInstruction().getConvertedResultExpression()), edge) and
24172435
controls(g, result, edge)
@@ -2450,12 +2468,20 @@ private EdgeKind getConditionalEdge(boolean branch) {
24502468
* in data flow and taint tracking.
24512469
*/
24522470
module InstructionBarrierGuard<instructionGuardChecksSig/3 instructionGuardChecks> {
2471+
bindingset[value, n]
2472+
pragma[inline_late]
2473+
private predicate operandHasValueNumber(ValueNumber value, Node n) {
2474+
exists(Operand use |
2475+
use = value.getAnInstruction().getAUse() and
2476+
n.asOperand() = use
2477+
)
2478+
}
2479+
24532480
/** Gets a node that is safely guarded by the given guard check. */
24542481
Node getABarrierNode() {
2455-
exists(IRGuardCondition g, ValueNumber value, boolean edge, Operand use |
2482+
exists(IRGuardCondition g, ValueNumber value, boolean edge |
24562483
instructionGuardChecks(g, pragma[only_bind_into](value.getAnInstruction()), edge) and
2457-
use = value.getAnInstruction().getAUse() and
2458-
result.asOperand() = use and
2484+
operandHasValueNumber(value, result) and
24592485
controls(g, result, edge)
24602486
)
24612487
or

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/ValueNumbering.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ValueNumber extends TValueNumber {
5151
/**
5252
* Gets an `Operand` whose definition is exact and has this value number.
5353
*/
54+
pragma[nomagic]
5455
final Operand getAUse() { this = valueNumber(result.getDef()) }
5556

5657
final string getKind() {

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ValueNumber extends TValueNumber {
5151
/**
5252
* Gets an `Operand` whose definition is exact and has this value number.
5353
*/
54+
pragma[nomagic]
5455
final Operand getAUse() { this = valueNumber(result.getDef()) }
5556

5657
final string getKind() {

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/ValueNumbering.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ValueNumber extends TValueNumber {
5151
/**
5252
* Gets an `Operand` whose definition is exact and has this value number.
5353
*/
54+
pragma[nomagic]
5455
final Operand getAUse() { this = valueNumber(result.getDef()) }
5556

5657
final string getKind() {

0 commit comments

Comments
 (0)