mirror of
https://github.com/github/codeql.git
synced 2026-04-20 22:44:52 +02:00
C++: Fix tests for guards.
This commit is contained in:
@@ -4,8 +4,8 @@ import semmle.code.cpp.controlflow.IRGuards
|
||||
query predicate astGuards(GuardCondition guard) { any() }
|
||||
|
||||
query predicate astGuardsCompare(int startLine, string msg) {
|
||||
exists(GuardCondition guard, Expr left, int k, string which, string op |
|
||||
exists(boolean sense |
|
||||
exists(GuardCondition guard, Expr left, int k, string op |
|
||||
exists(boolean sense, string which |
|
||||
sense = true and which = "true"
|
||||
or
|
||||
sense = false and which = "false"
|
||||
@@ -21,14 +21,16 @@ query predicate astGuardsCompare(int startLine, string msg) {
|
||||
|
|
||||
msg = left + op + right + "+" + k + " when " + guard + " is " + which
|
||||
)
|
||||
)
|
||||
or
|
||||
exists(AbstractValue value |
|
||||
guard.comparesEq(left, k, true, value) and op = " == "
|
||||
or
|
||||
(
|
||||
guard.comparesEq(left, k, true, sense) and op = " == "
|
||||
or
|
||||
guard.comparesEq(left, k, false, sense) and op = " != "
|
||||
) and
|
||||
msg = left + op + k + " when " + guard + " is " + which
|
||||
) and
|
||||
guard.comparesEq(left, k, false, value) and op = " != "
|
||||
|
|
||||
msg = left + op + k + " when " + guard + " is " + value
|
||||
)
|
||||
|
|
||||
startLine = guard.getLocation().getStartLine()
|
||||
)
|
||||
}
|
||||
@@ -71,8 +73,8 @@ query predicate astGuardsEnsure_const(
|
||||
query predicate irGuards(IRGuardCondition guard) { any() }
|
||||
|
||||
query predicate irGuardsCompare(int startLine, string msg) {
|
||||
exists(IRGuardCondition guard, Operand left, int k, string which, string op |
|
||||
exists(boolean sense |
|
||||
exists(IRGuardCondition guard, Operand left, int k, string op |
|
||||
exists(boolean sense, string which |
|
||||
sense = true and which = "true"
|
||||
or
|
||||
sense = false and which = "false"
|
||||
@@ -91,16 +93,18 @@ query predicate irGuardsCompare(int startLine, string msg) {
|
||||
right.getAnyDef().getUnconvertedResultExpression() + "+" + k + " when " + guard + " is "
|
||||
+ which
|
||||
)
|
||||
)
|
||||
or
|
||||
exists(AbstractValue value |
|
||||
guard.comparesEq(left, k, true, value) and op = " == "
|
||||
or
|
||||
(
|
||||
guard.comparesEq(left, k, true, sense) and op = " == "
|
||||
or
|
||||
guard.comparesEq(left, k, false, sense) and op = " != "
|
||||
) and
|
||||
guard.comparesEq(left, k, false, value) and op = " != "
|
||||
|
|
||||
msg =
|
||||
left.getAnyDef().getUnconvertedResultExpression() + op + k + " when " + guard + " is " +
|
||||
which
|
||||
) and
|
||||
value
|
||||
)
|
||||
|
|
||||
startLine = guard.getLocation().getStartLine()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@
|
||||
| 58 | y < 0+0 when ... < ... is true |
|
||||
| 58 | y >= 0+0 when ... < ... is false |
|
||||
| 58 | y >= 0+0 when ... \|\| ... is false |
|
||||
| 61 | i == 0 when i is true |
|
||||
| 61 | i == 1 when i is true |
|
||||
| 61 | i == 2 when i is true |
|
||||
| 61 | i == 0 when i is Case[0] |
|
||||
| 61 | i == 1 when i is Case[1] |
|
||||
| 61 | i == 2 when i is Case[2] |
|
||||
| 75 | 0 != x+0 when ... == ... is false |
|
||||
| 75 | 0 == x+0 when ... == ... is true |
|
||||
| 75 | x != 0 when ... == ... is false |
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
import cpp
|
||||
import semmle.code.cpp.controlflow.Guards
|
||||
|
||||
from GuardCondition guard, Expr left, int k, string which, string op, string msg
|
||||
from GuardCondition guard, Expr left, int k, string op, string msg
|
||||
where
|
||||
exists(boolean sense |
|
||||
exists(boolean sense, string which |
|
||||
sense = true and which = "true"
|
||||
or
|
||||
sense = false and which = "false"
|
||||
@@ -25,12 +25,13 @@ where
|
||||
|
|
||||
msg = left + op + right + "+" + k + " when " + guard + " is " + which
|
||||
)
|
||||
)
|
||||
or
|
||||
exists(AbstractValue value |
|
||||
guard.comparesEq(left, k, true, value) and op = " == "
|
||||
or
|
||||
(
|
||||
guard.comparesEq(left, k, true, sense) and op = " == "
|
||||
or
|
||||
guard.comparesEq(left, k, false, sense) and op = " != "
|
||||
) and
|
||||
msg = left + op + k + " when " + guard + " is " + which
|
||||
guard.comparesEq(left, k, false, value) and op = " != "
|
||||
|
|
||||
msg = left + op + k + " when " + guard + " is " + value
|
||||
)
|
||||
select guard.getLocation().getStartLine(), msg
|
||||
|
||||
Reference in New Issue
Block a user