diff --git a/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll b/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll index dad011d93912..54b8c7e6000d 100644 --- a/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll +++ b/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll @@ -160,23 +160,6 @@ module GuardsInput implements SharedGuards::InputSig ... | Guards.cs:279:17:279:17 | access to parameter o | true | -| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:280:28:280:28 | access to local variable a | true | -| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:281:17:281:17 | access to local variable a | true | -| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | true | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | false | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:17 | access to parameter o | true | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | false | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:17 | access to parameter o | false | | Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | false | | Guards.cs:343:31:343:31 | access to local variable s | Guards.cs:342:13:342:21 | ... != ... | Guards.cs:342:13:342:13 | access to local variable s | true | | Guards.cs:349:13:349:13 | access to parameter o | Guards.cs:348:13:348:25 | ... is ... | Guards.cs:348:13:348:13 | access to parameter o | true | diff --git a/csharp/ql/test/library-tests/controlflow/guards/GuardedControlFlowNode.expected b/csharp/ql/test/library-tests/controlflow/guards/GuardedControlFlowNode.expected index 577a21887181..f9d4f9775b40 100644 --- a/csharp/ql/test/library-tests/controlflow/guards/GuardedControlFlowNode.expected +++ b/csharp/ql/test/library-tests/controlflow/guards/GuardedControlFlowNode.expected @@ -152,6 +152,7 @@ | Guards.cs:145:20:145:20 | access to local variable s | Guards.cs:144:13:144:25 | ... is ... | Guards.cs:144:25:144:25 | access to local variable s | true | | Guards.cs:146:16:146:16 | access to parameter o | Guards.cs:144:13:144:25 | ... is ... | Guards.cs:144:13:144:13 | access to parameter o | false | | Guards.cs:154:24:154:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | not null | +| Guards.cs:156:24:156:24 | access to local variable a | Guards.cs:155:18:155:33 | Action a | Guards.cs:155:33:155:33 | access to local variable a | match | | Guards.cs:158:24:158:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | | | Guards.cs:158:24:158:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | not null | | Guards.cs:160:24:160:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | not | @@ -178,33 +179,13 @@ | Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true | | Guards.cs:271:13:271:14 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true | | Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not null | -| Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | true | -| Guards.cs:279:17:279:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | true | -| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:280:28:280:28 | access to local variable a | true | -| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:281:17:281:17 | access to local variable a | true | -| Guards.cs:281:17:281:28 | call to method ToString | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:281:17:281:28 | call to method ToString | true | +| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:280:28 | Action a | Guards.cs:280:28:280:28 | access to local variable a | match | | Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | | | Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not null | -| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | true | -| Guards.cs:283:17:283:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false | -| Guards.cs:283:17:283:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | true | | Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not | | Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | null | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | false | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:17 | access to parameter o | true | -| Guards.cs:285:17:285:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false | -| Guards.cs:285:17:285:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | false | -| Guards.cs:285:17:285:28 | call to method ToString | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:28 | call to method ToString | true | | Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not | | Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not null | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | false | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:17 | access to parameter o | false | -| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false | -| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | false | -| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:28 | call to method ToString | false | | Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | false | | Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:32 | ... ? ... : ... | Guards.cs:341:20:341:20 | access to parameter b | not null | | Guards.cs:343:31:343:31 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | not null | diff --git a/csharp/ql/test/library-tests/controlflow/guards/GuardedExpr.expected b/csharp/ql/test/library-tests/controlflow/guards/GuardedExpr.expected index 577a21887181..f9d4f9775b40 100644 --- a/csharp/ql/test/library-tests/controlflow/guards/GuardedExpr.expected +++ b/csharp/ql/test/library-tests/controlflow/guards/GuardedExpr.expected @@ -152,6 +152,7 @@ | Guards.cs:145:20:145:20 | access to local variable s | Guards.cs:144:13:144:25 | ... is ... | Guards.cs:144:25:144:25 | access to local variable s | true | | Guards.cs:146:16:146:16 | access to parameter o | Guards.cs:144:13:144:25 | ... is ... | Guards.cs:144:13:144:13 | access to parameter o | false | | Guards.cs:154:24:154:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | not null | +| Guards.cs:156:24:156:24 | access to local variable a | Guards.cs:155:18:155:33 | Action a | Guards.cs:155:33:155:33 | access to local variable a | match | | Guards.cs:158:24:158:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | | | Guards.cs:158:24:158:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | not null | | Guards.cs:160:24:160:24 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | Guards.cs:151:17:151:17 | access to parameter o | not | @@ -178,33 +179,13 @@ | Guards.cs:269:13:269:14 | access to parameter o1 | Guards.cs:268:13:268:41 | call to operator == | Guards.cs:268:13:268:14 | access to parameter o1 | true | | Guards.cs:271:13:271:14 | access to parameter o1 | Guards.cs:270:13:270:42 | call to operator == | Guards.cs:270:13:270:14 | access to parameter o1 | true | | Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not null | -| Guards.cs:279:17:279:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | true | -| Guards.cs:279:17:279:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | true | -| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:280:28:280:28 | access to local variable a | true | -| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:281:17:281:17 | access to local variable a | true | -| Guards.cs:281:17:281:28 | call to method ToString | Guards.cs:280:13:281:28 | ... => ... | Guards.cs:281:17:281:28 | call to method ToString | true | +| Guards.cs:281:17:281:17 | access to local variable a | Guards.cs:280:13:280:28 | Action a | Guards.cs:280:28:280:28 | access to local variable a | match | | Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | | | Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not null | -| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:283:17:283:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | true | -| Guards.cs:283:17:283:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false | -| Guards.cs:283:17:283:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | true | | Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not | | Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | null | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | false | -| Guards.cs:285:17:285:17 | access to parameter o | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:17 | access to parameter o | true | -| Guards.cs:285:17:285:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false | -| Guards.cs:285:17:285:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | false | -| Guards.cs:285:17:285:28 | call to method ToString | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:28 | call to method ToString | true | | Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not | | Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | Guards.cs:276:16:276:16 | access to parameter o | not null | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:17 | access to parameter o | false | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:17 | access to parameter o | false | -| Guards.cs:287:17:287:17 | access to parameter o | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:17 | access to parameter o | false | -| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:278:13:279:28 | ... => ... | Guards.cs:279:17:279:28 | call to method ToString | false | -| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:282:13:283:28 | ... => ... | Guards.cs:283:17:283:28 | call to method ToString | false | -| Guards.cs:287:17:287:28 | call to method ToString | Guards.cs:284:13:285:28 | ... => ... | Guards.cs:285:17:285:28 | call to method ToString | false | | Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | Guards.cs:341:20:341:20 | access to parameter b | false | | Guards.cs:342:27:342:27 | access to parameter b | Guards.cs:341:20:341:32 | ... ? ... : ... | Guards.cs:341:20:341:20 | access to parameter b | not null | | Guards.cs:343:31:343:31 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | Guards.cs:342:13:342:13 | access to local variable s | not null | diff --git a/csharp/ql/test/query-tests/Nullness/EqualityCheck.expected b/csharp/ql/test/query-tests/Nullness/EqualityCheck.expected index 5ba1fdf87656..43b3b90651b9 100644 --- a/csharp/ql/test/query-tests/Nullness/EqualityCheck.expected +++ b/csharp/ql/test/query-tests/Nullness/EqualityCheck.expected @@ -190,12 +190,12 @@ | E.cs:83:13:83:24 | ... != ... | false | E.cs:83:21:83:24 | null | E.cs:83:13:83:16 | access to parameter vals | | E.cs:85:18:85:29 | ... != ... | false | E.cs:85:18:85:21 | access to parameter vals | E.cs:85:26:85:29 | null | | E.cs:85:18:85:29 | ... != ... | false | E.cs:85:26:85:29 | null | E.cs:85:18:85:21 | access to parameter vals | -| E.cs:92:13:92:28 | case ...: | true | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:92:18:92:27 | access to constant MY_CONST_A | -| E.cs:92:13:92:28 | case ...: | true | E.cs:92:18:92:27 | access to constant MY_CONST_A | E.cs:90:17:90:27 | access to local variable switchguard | -| E.cs:95:13:95:28 | case ...: | true | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:95:18:95:27 | access to constant MY_CONST_C | -| E.cs:95:13:95:28 | case ...: | true | E.cs:95:18:95:27 | access to constant MY_CONST_C | E.cs:90:17:90:27 | access to local variable switchguard | -| E.cs:97:13:97:28 | case ...: | true | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:97:18:97:27 | access to constant MY_CONST_B | -| E.cs:97:13:97:28 | case ...: | true | E.cs:97:18:97:27 | access to constant MY_CONST_B | E.cs:90:17:90:27 | access to local variable switchguard | +| E.cs:92:18:92:27 | access to constant MY_CONST_A | match | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:92:18:92:27 | access to constant MY_CONST_A | +| E.cs:92:18:92:27 | access to constant MY_CONST_A | match | E.cs:92:18:92:27 | access to constant MY_CONST_A | E.cs:90:17:90:27 | access to local variable switchguard | +| E.cs:95:18:95:27 | access to constant MY_CONST_C | match | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:95:18:95:27 | access to constant MY_CONST_C | +| E.cs:95:18:95:27 | access to constant MY_CONST_C | match | E.cs:95:18:95:27 | access to constant MY_CONST_C | E.cs:90:17:90:27 | access to local variable switchguard | +| E.cs:97:18:97:27 | access to constant MY_CONST_B | match | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:97:18:97:27 | access to constant MY_CONST_B | +| E.cs:97:18:97:27 | access to constant MY_CONST_B | match | E.cs:97:18:97:27 | access to constant MY_CONST_B | E.cs:90:17:90:27 | access to local variable switchguard | | E.cs:126:21:126:29 | ... == ... | true | E.cs:126:21:126:24 | access to local variable step | E.cs:126:29:126:29 | 0 | | E.cs:126:21:126:29 | ... == ... | true | E.cs:126:29:126:29 | 0 | E.cs:126:21:126:24 | access to local variable step | | E.cs:153:13:153:24 | ... != ... | false | E.cs:153:13:153:16 | access to local variable obj2 | E.cs:153:21:153:24 | null | diff --git a/csharp/ql/test/query-tests/Nullness/NullCheck.expected b/csharp/ql/test/query-tests/Nullness/NullCheck.expected index 2b6962b51c01..d6fc07cc8632 100644 --- a/csharp/ql/test/query-tests/Nullness/NullCheck.expected +++ b/csharp/ql/test/query-tests/Nullness/NullCheck.expected @@ -57,6 +57,7 @@ | D.cs:39:16:39:24 | ... == ... | D.cs:39:16:39:16 | access to parameter x | | D.cs:45:13:45:22 | ... != ... | D.cs:45:13:45:14 | access to local variable o1 | | D.cs:48:13:48:24 | ... is ... | D.cs:48:13:48:14 | access to local variable o2 | +| D.cs:48:19:48:24 | access to type String | D.cs:48:13:48:14 | access to local variable o2 | | D.cs:51:13:51:44 | ... != ... | D.cs:51:14:51:35 | ... = ... | | D.cs:55:23:55:32 | ... != ... | D.cs:55:23:55:24 | access to local variable o4 | | D.cs:58:19:58:28 | ... != ... | D.cs:58:19:58:20 | access to local variable o4 | @@ -104,6 +105,7 @@ | E.cs:180:13:180:23 | ... == ... | E.cs:180:13:180:15 | access to parameter obj | | E.cs:193:17:193:17 | access to parameter o | E.cs:193:17:193:17 | access to parameter o | | E.cs:208:13:208:23 | ... is ... | E.cs:208:13:208:13 | access to parameter s | +| E.cs:208:18:208:23 | access to type String | E.cs:208:13:208:13 | access to parameter s | | E.cs:245:13:245:22 | access to property HasValue | E.cs:245:13:245:13 | access to parameter i | | E.cs:252:13:252:21 | ... != ... | E.cs:252:13:252:13 | access to parameter i | | E.cs:259:13:259:21 | ... == ... | E.cs:259:13:259:13 | access to parameter i | diff --git a/go/ql/lib/semmle/go/controlflow/Guards.qll b/go/ql/lib/semmle/go/controlflow/Guards.qll index b17cc263a5d5..99bbfe07971c 100644 --- a/go/ql/lib/semmle/go/controlflow/Guards.qll +++ b/go/ql/lib/semmle/go/controlflow/Guards.qll @@ -97,64 +97,13 @@ private module GuardsInput implements class Case extends AstNode { G::ExpressionSwitchStmt switch; - Case() { - exists(switch.getExpr()) and - this = switch.getACase() - or - not exists(switch.getExpr()) and - ( - this = switch.getANonDefaultCase().getAnExpr() - or - this = switch.getDefault() - ) - } + Case() { this = switch.getACase() } - Expr getSwitchExpr() { - result = switch.getExpr() - or - not exists(switch.getExpr()) and result = this - } + Expr getSwitchExpr() { result = switch.getExpr() } predicate isDefaultCase() { this = switch.getDefault() } - ConstantExpr asConstantCase() { - exists(G::CaseClause cc | - this = cc and - cc.getNumExpr() = 1 and - result = cc.getExpr(0) - ) - } - - predicate matchEdge(CfgImpl::Cfg::BasicBlock bb1, CfgImpl::Cfg::BasicBlock bb2) { - exists(Expr caseExpr | - caseExpr = this.(G::CaseClause).getAnExpr() - or - caseExpr = this - | - caseExpressionBranch(caseExpr, bb1, - any(MatchingSuccessor successor | - bb1.getASuccessor(successor) = bb2 and successor.getValue() = true - )) - ) - } - - predicate nonMatchEdge(CfgImpl::Cfg::BasicBlock bb1, CfgImpl::Cfg::BasicBlock bb2) { - exists(G::CaseClause cc, int last, Expr caseExpr | - cc = this and - last = max(int i | exists(cc.getExpr(i))) and - caseExpr = cc.getExpr(last) - | - caseExpressionBranch(caseExpr, bb1, - any(MatchingSuccessor successor | - bb1.getASuccessor(successor) = bb2 and successor.getValue() = false - )) - ) - or - caseExpressionBranch(this, bb1, - any(MatchingSuccessor successor | - bb1.getASuccessor(successor) = bb2 and successor.getValue() = false - )) - } + AstNode getAPattern() { result = this.(G::CaseClause).getAnExpr() } } additional predicate caseExpressionBranch( @@ -168,20 +117,6 @@ private module GuardsInput implements ) } - predicate equalityBranchEdge( - Expr left, Expr right, CfgImpl::Cfg::BasicBlock bb1, CfgImpl::Cfg::BasicBlock bb2, boolean equal - ) { - exists(G::CaseClause cc, G::ExpressionSwitchStmt switch | - cc = switch.getACase() and - left = switch.getExpr() and - right = cc.getAnExpr() and - caseExpressionBranch(right, bb1, - any(MatchingSuccessor successor | - bb1.getASuccessor(successor) = bb2 and successor.getValue() = equal - )) - ) - } - class AndExpr = G::LandExpr; class OrExpr = G::LorExpr; diff --git a/go/ql/test/library-tests/semmle/go/controlflow/Guards/Guards.expected b/go/ql/test/library-tests/semmle/go/controlflow/Guards/Guards.expected index 24f26c65326d..12ac603beab2 100644 --- a/go/ql/test/library-tests/semmle/go/controlflow/Guards/Guards.expected +++ b/go/ql/test/library-tests/semmle/go/controlflow/Guards/Guards.expected @@ -4,15 +4,8 @@ controlsResult | guards.go:12:7:12:15 | ...<... | zero | false | | guards.go:14:7:14:16 | ...==... | positive | false | | guards.go:14:7:14:16 | ...==... | zero | true | -| guards.go:23:2:24:21 | case clause | tagged one or two | false | -| guards.go:23:2:24:21 | case clause | tagged other | false | -| guards.go:23:2:24:21 | case clause | tagged zero | true | -| guards.go:25:2:26:27 | case clause | tagged other | false | -| guards.go:34:2:35:30 | case clause | tagged false boolean | true | | guards.go:34:7:34:11 | value | tagged false boolean | false | -| guards.go:38:2:39:29 | case clause | tagged true boolean | true | | guards.go:38:7:38:11 | value | tagged true boolean | true | -| guards.go:42:2:43:33 | case clause | tagged false comparison | true | | guards.go:42:7:42:17 | ...<... | tagged false comparison | false | | guards.go:48:5:48:5 | a | compound true | true | | guards.go:48:5:48:17 | ...&&... | compound false | false | @@ -38,10 +31,6 @@ controlsResult | guards.go:118:5:118:32 | ...==... | errors new | true | | guards.go:122:5:122:32 | ...==... | fmt errorf | true | | guards.go:126:5:126:28 | ...==... | source non-nil return | true | -| guards.go:137:2:138:26 | case clause | default case | false | -| guards.go:137:2:138:26 | case clause | non-default case | true | -| guards.go:148:2:149:28 | case clause | case after default | true | -| guards.go:148:2:149:28 | case clause | default before case | false | | guards.go:162:7:162:11 | value | expressionless case | true | | guards.go:162:7:162:11 | value | expressionless default | false | | guards.go:183:5:183:21 | call to isNotNil | non-variadic wrapper | true | @@ -62,29 +51,35 @@ valueControlsResult | guards.go:12:7:12:11 | value | negative | Upper bound -1 | | guards.go:12:7:12:11 | value | positive | Lower bound 0 | | guards.go:12:7:12:11 | value | zero | Lower bound 0 | +| guards.go:12:7:12:15 | ...<... | negative | match | | guards.go:12:7:12:15 | ...<... | negative | true | | guards.go:12:7:12:15 | ...<... | positive | false | +| guards.go:12:7:12:15 | ...<... | positive | no match | | guards.go:12:7:12:15 | ...<... | zero | false | +| guards.go:12:7:12:15 | ...<... | zero | no match | | guards.go:14:7:14:11 | value | positive | not 0 | | guards.go:14:7:14:11 | value | zero | 0 | | guards.go:14:7:14:16 | ...==... | positive | false | +| guards.go:14:7:14:16 | ...==... | positive | no match | +| guards.go:14:7:14:16 | ...==... | zero | match | | guards.go:14:7:14:16 | ...==... | zero | true | | guards.go:22:9:22:13 | value | tagged one or two | not 0 | | guards.go:22:9:22:13 | value | tagged other | not 0 | | guards.go:22:9:22:13 | value | tagged other | not 1 | | guards.go:22:9:22:13 | value | tagged other | not 2 | | guards.go:22:9:22:13 | value | tagged zero | 0 | -| guards.go:23:2:24:21 | case clause | tagged one or two | false | -| guards.go:23:2:24:21 | case clause | tagged other | false | -| guards.go:23:2:24:21 | case clause | tagged zero | true | -| guards.go:25:2:26:27 | case clause | tagged other | false | -| guards.go:34:2:35:30 | case clause | tagged false boolean | true | +| guards.go:23:7:23:7 | 0 | tagged one or two | no match | +| guards.go:23:7:23:7 | 0 | tagged other | no match | +| guards.go:23:7:23:7 | 0 | tagged zero | match | +| guards.go:25:7:25:7 | 1 | tagged other | no match | +| guards.go:25:10:25:10 | 2 | tagged other | no match | | guards.go:34:7:34:11 | value | tagged false boolean | false | -| guards.go:38:2:39:29 | case clause | tagged true boolean | true | +| guards.go:34:7:34:11 | value | tagged false boolean | match | +| guards.go:38:7:38:11 | value | tagged true boolean | match | | guards.go:38:7:38:11 | value | tagged true boolean | true | -| guards.go:42:2:43:33 | case clause | tagged false comparison | true | | guards.go:42:7:42:12 | number | tagged false comparison | Lower bound 10 | | guards.go:42:7:42:17 | ...<... | tagged false comparison | false | +| guards.go:42:7:42:17 | ...<... | tagged false comparison | match | | guards.go:48:5:48:5 | a | compound true | true | | guards.go:48:5:48:17 | ...&&... | compound false | false | | guards.go:48:5:48:17 | ...&&... | compound true | true | @@ -140,14 +135,16 @@ valueControlsResult | guards.go:126:14:126:28 | call to returnsNonNil | source non-nil return | no exception | | guards.go:136:9:136:13 | value | default case | not 0 | | guards.go:136:9:136:13 | value | non-default case | 0 | -| guards.go:137:2:138:26 | case clause | default case | false | -| guards.go:137:2:138:26 | case clause | non-default case | true | +| guards.go:137:7:137:7 | 0 | default case | no match | +| guards.go:137:7:137:7 | 0 | non-default case | match | | guards.go:145:9:145:13 | value | case after default | 0 | | guards.go:145:9:145:13 | value | default before case | not 0 | -| guards.go:148:2:149:28 | case clause | case after default | true | -| guards.go:148:2:149:28 | case clause | default before case | false | +| guards.go:148:7:148:7 | 0 | case after default | match | +| guards.go:148:7:148:7 | 0 | default before case | no match | +| guards.go:162:7:162:11 | value | expressionless case | match | | guards.go:162:7:162:11 | value | expressionless case | true | | guards.go:162:7:162:11 | value | expressionless default | false | +| guards.go:162:7:162:11 | value | expressionless default | no match | | guards.go:183:5:183:21 | call to isNotNil | non-variadic wrapper | no exception | | guards.go:183:5:183:21 | call to isNotNil | non-variadic wrapper | true | | guards.go:183:14:183:20 | pointer | non-variadic wrapper | not null | @@ -193,8 +190,6 @@ valueControlsResult ensuresEqResult | guards.go:14:7:14:16 | ...==... | 0 = value | true | | guards.go:14:7:14:16 | ...==... | value = 0 | true | -| guards.go:23:2:24:21 | case clause | 0 = value | true | -| guards.go:23:2:24:21 | case clause | value = 0 | true | | guards.go:56:5:56:20 | ...==... | 0 = type conversion | true | | guards.go:56:5:56:20 | ...==... | type conversion = 0 | true | | guards.go:59:5:59:19 | ...==... | 0 = type conversion | true | @@ -217,12 +212,6 @@ ensuresEqResult | guards.go:122:5:122:32 | ...==... | value = call to Errorf | true | | guards.go:126:5:126:28 | ...==... | call to returnsNonNil = value | true | | guards.go:126:5:126:28 | ...==... | value = call to returnsNonNil | true | -| guards.go:137:2:138:26 | case clause | 0 = value | true | -| guards.go:137:2:138:26 | case clause | value = 0 | true | -| guards.go:148:2:149:28 | case clause | 0 = value | true | -| guards.go:148:2:149:28 | case clause | value = 0 | true | -| guards.go:171:2:172:13 | case clause | 0 = value | true | -| guards.go:171:2:172:13 | case clause | value = 0 | true | | guards.go:179:9:179:22 | ...!=... | nil = pointer | false | | guards.go:179:9:179:22 | ...!=... | pointer = nil | false | | guards.go:189:10:189:23 | ...!=... | nil = pointer | false | diff --git a/java/ql/lib/semmle/code/java/controlflow/Guards.qll b/java/ql/lib/semmle/code/java/controlflow/Guards.qll index d309e0f2f01e..e4082e828402 100644 --- a/java/ql/lib/semmle/code/java/controlflow/Guards.qll +++ b/java/ql/lib/semmle/code/java/controlflow/Guards.qll @@ -165,27 +165,8 @@ private module GuardsInput implements SharedGuards::InputSig { * Holds if `va` is an access to a value that is guarded by `instanceof t` or `case e t`. */ private predicate typeTestGuarded(VarAccess va, RefType t) { - exists(Guard typeTest, Base::SsaDefinition v | - typeTest.appliesTypeTest(v.getARead(), t, _) and + exists(Guard typeTest, Base::SsaDefinition v, GuardValue gv | + typeTest.appliesTypeTest(v.getARead(), t, _, gv) and va = v.getARead() and - guardControls_v1(typeTest, va.getBasicBlock(), true) + guardControls_v1(typeTest, va.getBasicBlock(), gv) ) } @@ -314,13 +314,15 @@ private module Input implements TypeFlowInput { * Holds if `aa` is an access to a value that is guarded by `instanceof t` or `case e t`. */ private predicate arrayTypeTestGuarded(ArrayAccess aa, RefType t) { - exists(Guard typeTest, Base::SsaDefinition v1, Base::SsaDefinition v2, ArrayAccess aa1 | - typeTest.appliesTypeTest(aa1, t, _) and + exists( + Guard typeTest, Base::SsaDefinition v1, Base::SsaDefinition v2, ArrayAccess aa1, GuardValue gv + | + typeTest.appliesTypeTest(aa1, t, _, gv) and aa1.getArray() = v1.getARead() and aa1.getIndexExpr() = v2.getARead() and aa.getArray() = v1.getARead() and aa.getIndexExpr() = v2.getARead() and - guardControls_v1(typeTest, aa.getBasicBlock(), true) + guardControls_v1(typeTest, aa.getBasicBlock(), gv) ) } diff --git a/java/ql/lib/semmle/code/java/dispatch/VirtualDispatch.qll b/java/ql/lib/semmle/code/java/dispatch/VirtualDispatch.qll index 0119930caf43..ece53afa2bea 100644 --- a/java/ql/lib/semmle/code/java/dispatch/VirtualDispatch.qll +++ b/java/ql/lib/semmle/code/java/dispatch/VirtualDispatch.qll @@ -194,11 +194,11 @@ private module Dispatch { */ private predicate impossibleDispatchTarget(MethodCall source, Method tgt) { tgt = viableImpl_v1_cand(source) and - exists(Guard typeTest, Base::SsaDefinition v, Expr q, RefType t | + exists(Guard typeTest, Base::SsaDefinition v, Expr q, RefType t, GuardValue gv | source.getQualifier() = q and v.getARead() = q and - typeTest.appliesTypeTest(v.getARead(), t, false) and - guardControls_v1(typeTest, q.getBasicBlock(), false) and + typeTest.appliesTypeTest(v.getARead(), t, false, gv) and + guardControls_v1(typeTest, q.getBasicBlock(), gv.getDualValue()) and tgt.getDeclaringType().getSourceDeclaration().getASourceSupertype*() = t.getErasure() ) } diff --git a/java/ql/test/library-tests/guards/Guards.java b/java/ql/test/library-tests/guards/Guards.java index 35e3b7c09a9a..1f1a4b7f7f15 100644 --- a/java/ql/test/library-tests/guards/Guards.java +++ b/java/ql/test/library-tests/guards/Guards.java @@ -36,13 +36,13 @@ void t1(int[] a, String s) { s = "bar"; switch (s) { case "bar": - chk(); // $ guarded='s:match "bar"' guarded='s:bar' + chk(); // $ guarded='"bar":match' guarded='s:bar' break; case "foo": - chk(); // $ guarded='s:non-match "bar"' guarded='s:not bar' guarded='s:match "foo"' guarded='s:foo' guarded=g(3):false + chk(); // $ guarded='"bar":no match' guarded='s:not bar' guarded='"foo":match' guarded='s:foo' guarded=g(3):false break; default: - chk(); // $ guarded='s:non-match "bar"' guarded='s:non-match "foo"' guarded='s:not bar' guarded='s:not foo' guarded=g(3):false + chk(); // $ guarded='"bar":no match' guarded='"foo":no match' guarded='s:not bar' guarded='s:not foo' guarded=g(3):false break; } @@ -89,13 +89,13 @@ void t4() { chk(); // $ guarded='x == null:true' guarded='x:null' guarded=g(1):false guarded=g(2):false guarded=g(Alt2):false guarded=g(3):false switch (x) { case E1: - chk(); // $ guarded='x:match E1' guarded='x:E1' guarded=g(1):true guarded=g(2):false guarded=g(Alt2):false guarded=g(3):false + chk(); // $ guarded='E1:match' guarded='x:E1' guarded=g(1):true guarded=g(2):false guarded=g(Alt2):false guarded=g(3):false break; case E2: - chk(); // $ guarded='x:non-match E1' guarded='x:not E1' guarded='x:match E2' guarded='x:E2' guarded=g(3):false + chk(); // $ guarded='E1:no match' guarded='x:not E1' guarded='E2:match' guarded='x:E2' guarded=g(3):false break; case E3: - chk(); // $ guarded='x:non-match E1' guarded='x:non-match E2' guarded='x:not E1' guarded='x:not E2' guarded='x:match E3' guarded='x:E3' guarded=g(3):true + chk(); // $ guarded='E1:no match' guarded='E2:no match' guarded='x:not E1' guarded='x:not E2' guarded='E3:match' guarded='x:E3' guarded=g(3):true break; } Object o = g(4) ? new Object() : null; @@ -195,10 +195,10 @@ void testWrappers(String s, Integer i) { switch (testEnumWrapper(g(1))) { case SUCCESS: - chk(); // $ guarded='testEnumWrapper(...):SUCCESS' guarded='testEnumWrapper(...):match SUCCESS' guarded=g(1):true + chk(); // $ guarded='testEnumWrapper(...):SUCCESS' guarded='SUCCESS:match' guarded=g(1):true break; case FAILURE: - chk(); // $ guarded='testEnumWrapper(...):not SUCCESS' guarded='testEnumWrapper(...):non-match SUCCESS' guarded='testEnumWrapper(...):FAILURE' guarded='testEnumWrapper(...):match FAILURE' guarded=g(1):false + chk(); // $ guarded='testEnumWrapper(...):not SUCCESS' guarded='SUCCESS:no match' guarded='testEnumWrapper(...):FAILURE' guarded='FAILURE:match' guarded=g(1):false break; } } diff --git a/java/ql/test/library-tests/guards/GuardsInline.expected b/java/ql/test/library-tests/guards/GuardsInline.expected index 9d5ea1992c69..b3985e01d76f 100644 --- a/java/ql/test/library-tests/guards/GuardsInline.expected +++ b/java/ql/test/library-tests/guards/GuardsInline.expected @@ -14,15 +14,15 @@ | Guards.java:29:7:29:11 | chk(...) | 'a:not null' | | Guards.java:29:7:29:11 | chk(...) | 'i < sz:true' | | Guards.java:29:7:29:11 | chk(...) | 'sz:Lower bound 1' | +| Guards.java:39:9:39:13 | chk(...) | '"bar":match' | | Guards.java:39:9:39:13 | chk(...) | 's:bar' | -| Guards.java:39:9:39:13 | chk(...) | 's:match "bar"' | +| Guards.java:42:9:42:13 | chk(...) | '"bar":no match' | +| Guards.java:42:9:42:13 | chk(...) | '"foo":match' | | Guards.java:42:9:42:13 | chk(...) | 's:foo' | -| Guards.java:42:9:42:13 | chk(...) | 's:match "foo"' | -| Guards.java:42:9:42:13 | chk(...) | 's:non-match "bar"' | | Guards.java:42:9:42:13 | chk(...) | 's:not bar' | | Guards.java:42:9:42:13 | chk(...) | g(3):false | -| Guards.java:45:9:45:13 | chk(...) | 's:non-match "bar"' | -| Guards.java:45:9:45:13 | chk(...) | 's:non-match "foo"' | +| Guards.java:45:9:45:13 | chk(...) | '"bar":no match' | +| Guards.java:45:9:45:13 | chk(...) | '"foo":no match' | | Guards.java:45:9:45:13 | chk(...) | 's:not bar' | | Guards.java:45:9:45:13 | chk(...) | 's:not foo' | | Guards.java:45:9:45:13 | chk(...) | g(3):false | @@ -54,21 +54,21 @@ | Guards.java:89:7:89:11 | chk(...) | g(2):false | | Guards.java:89:7:89:11 | chk(...) | g(3):false | | Guards.java:89:7:89:11 | chk(...) | g(Alt2):false | +| Guards.java:92:9:92:13 | chk(...) | 'E1:match' | | Guards.java:92:9:92:13 | chk(...) | 'x:E1' | -| Guards.java:92:9:92:13 | chk(...) | 'x:match E1' | | Guards.java:92:9:92:13 | chk(...) | g(1):true | | Guards.java:92:9:92:13 | chk(...) | g(2):false | | Guards.java:92:9:92:13 | chk(...) | g(3):false | | Guards.java:92:9:92:13 | chk(...) | g(Alt2):false | +| Guards.java:95:9:95:13 | chk(...) | 'E1:no match' | +| Guards.java:95:9:95:13 | chk(...) | 'E2:match' | | Guards.java:95:9:95:13 | chk(...) | 'x:E2' | -| Guards.java:95:9:95:13 | chk(...) | 'x:match E2' | -| Guards.java:95:9:95:13 | chk(...) | 'x:non-match E1' | | Guards.java:95:9:95:13 | chk(...) | 'x:not E1' | | Guards.java:95:9:95:13 | chk(...) | g(3):false | +| Guards.java:98:9:98:13 | chk(...) | 'E1:no match' | +| Guards.java:98:9:98:13 | chk(...) | 'E2:no match' | +| Guards.java:98:9:98:13 | chk(...) | 'E3:match' | | Guards.java:98:9:98:13 | chk(...) | 'x:E3' | -| Guards.java:98:9:98:13 | chk(...) | 'x:match E3' | -| Guards.java:98:9:98:13 | chk(...) | 'x:non-match E1' | -| Guards.java:98:9:98:13 | chk(...) | 'x:non-match E2' | | Guards.java:98:9:98:13 | chk(...) | 'x:not E1' | | Guards.java:98:9:98:13 | chk(...) | 'x:not E2' | | Guards.java:98:9:98:13 | chk(...) | g(3):true | @@ -115,12 +115,12 @@ | Guards.java:193:7:193:11 | chk(...) | 'concatNonNull(...):not null' | | Guards.java:193:7:193:11 | chk(...) | 'null == concatNonNull(...):false' | | Guards.java:193:7:193:11 | chk(...) | 's:not null' | +| Guards.java:198:9:198:13 | chk(...) | 'SUCCESS:match' | | Guards.java:198:9:198:13 | chk(...) | 'testEnumWrapper(...):SUCCESS' | -| Guards.java:198:9:198:13 | chk(...) | 'testEnumWrapper(...):match SUCCESS' | | Guards.java:198:9:198:13 | chk(...) | g(1):true | +| Guards.java:201:9:201:13 | chk(...) | 'FAILURE:match' | +| Guards.java:201:9:201:13 | chk(...) | 'SUCCESS:no match' | | Guards.java:201:9:201:13 | chk(...) | 'testEnumWrapper(...):FAILURE' | -| Guards.java:201:9:201:13 | chk(...) | 'testEnumWrapper(...):match FAILURE' | -| Guards.java:201:9:201:13 | chk(...) | 'testEnumWrapper(...):non-match SUCCESS' | | Guards.java:201:9:201:13 | chk(...) | 'testEnumWrapper(...):not SUCCESS' | | Guards.java:201:9:201:13 | chk(...) | g(1):false | | Guards.java:213:5:213:9 | chk(...) | 'ensureNotNull(...):no exception' | diff --git a/java/ql/test/library-tests/guards/GuardsInline.ql b/java/ql/test/library-tests/guards/GuardsInline.ql index 9f29af6de606..c9cf65c8f752 100644 --- a/java/ql/test/library-tests/guards/GuardsInline.ql +++ b/java/ql/test/library-tests/guards/GuardsInline.ql @@ -15,19 +15,6 @@ string ppGuard(Guard g, Boolean branch) { "'" + bin.getLeftOperand() + " " + bin.getOp() + " " + bin.getRightOperand() + ":" + branch + "'" ) - or - exists(SwitchCase cc, Expr s, string match, string value | - cc = g and - cc.getSelectorExpr() = s and - ( - cc.(ConstCase).getValue().toString() = value - or - cc instanceof DefaultCase and value = "default" - ) and - if branch = true then match = ":match " else match = ":non-match " - | - result = "'" + s.toString() + match + value + "'" - ) } query predicate guarded(MethodCall mc, string guard) { diff --git a/java/ql/test/library-tests/guards/guardslogic.expected b/java/ql/test/library-tests/guards/guardslogic.expected index cbc4cd6f8be7..eef1ca3ae162 100644 --- a/java/ql/test/library-tests/guards/guardslogic.expected +++ b/java/ql/test/library-tests/guards/guardslogic.expected @@ -22,12 +22,12 @@ | Logic.java:19:9:19:12 | g(...) | false | Logic.java:25:9:25:14 | break | | Logic.java:19:9:19:12 | g(...) | false | Logic.java:26:7:26:14 | default | | Logic.java:19:9:19:12 | g(...) | true | Logic.java:20:7:20:16 | ; | -| Logic.java:22:7:22:17 | case ... | false | Logic.java:24:7:24:17 | case ... | -| Logic.java:22:7:22:17 | case ... | false | Logic.java:25:9:25:14 | break | -| Logic.java:22:7:22:17 | case ... | false | Logic.java:26:7:26:14 | default | -| Logic.java:22:7:22:17 | case ... | true | Logic.java:23:9:23:14 | break | -| Logic.java:24:7:24:17 | case ... | false | Logic.java:26:7:26:14 | default | -| Logic.java:24:7:24:17 | case ... | true | Logic.java:25:9:25:14 | break | +| Logic.java:22:12:22:16 | "bar" | match | Logic.java:23:9:23:14 | break | +| Logic.java:22:12:22:16 | "bar" | no match | Logic.java:24:7:24:17 | case ... | +| Logic.java:22:12:22:16 | "bar" | no match | Logic.java:25:9:25:14 | break | +| Logic.java:22:12:22:16 | "bar" | no match | Logic.java:26:7:26:14 | default | +| Logic.java:24:12:24:16 | "foo" | match | Logic.java:25:9:25:14 | break | +| Logic.java:24:12:24:16 | "foo" | no match | Logic.java:26:7:26:14 | default | | Logic.java:29:16:29:19 | g(...) | false | Logic.java:29:30:29:30 | s | | Logic.java:29:16:29:19 | g(...) | false | Logic.java:30:30:31:5 | { ... } | | Logic.java:29:16:29:19 | g(...) | true | Logic.java:29:23:29:26 | null | diff --git a/java/ql/test/library-tests/guards/guardslogic.ql b/java/ql/test/library-tests/guards/guardslogic.ql index e68be505ff71..697197f33faf 100644 --- a/java/ql/test/library-tests/guards/guardslogic.ql +++ b/java/ql/test/library-tests/guards/guardslogic.ql @@ -6,5 +6,11 @@ from Guard g, BasicBlock bb, GuardValue gv where g.valueControls(bb, gv) and g.getEnclosingCallable().getDeclaringType().hasName("Logic") and - (exists(gv.asBooleanValue()) or gv.isThrowsException() or gv.getDualValue().isThrowsException()) + ( + exists(gv.asBooleanValue()) or + gv.isThrowsException() or + gv.getDualValue().isThrowsException() or + gv.isMatch() or + gv.getDualValue().isMatch() + ) select g, gv, getFirstAstNode(bb) diff --git a/java/ql/test/library-tests/guards12/guard.expected b/java/ql/test/library-tests/guards12/guard.expected index f88b560c9a40..6055ba2c16e5 100644 --- a/java/ql/test/library-tests/guards12/guard.expected +++ b/java/ql/test/library-tests/guards12/guard.expected @@ -1,76 +1,112 @@ hasBranchEdge -| Test.java:5:7:5:17 | case ... | Test.java:5:7:5:17 | case ... | Test.java:5:19:5:19 | 2 | true | -| Test.java:5:7:5:17 | case ... | Test.java:5:7:5:17 | case ... | Test.java:6:7:6:17 | case ... | false | -| Test.java:6:7:6:17 | case ... | Test.java:6:7:6:17 | case ... | Test.java:6:19:6:19 | 2 | true | -| Test.java:6:7:6:17 | case ... | Test.java:6:7:6:17 | case ... | Test.java:7:7:7:16 | default | false | -| Test.java:11:7:11:17 | case ... | Test.java:11:7:11:17 | case ... | Test.java:11:19:11:21 | { ... } | true | -| Test.java:11:7:11:17 | case ... | Test.java:11:7:11:17 | case ... | Test.java:12:7:12:17 | case ... | false | -| Test.java:12:7:12:17 | case ... | Test.java:12:7:12:17 | case ... | Test.java:12:19:12:21 | { ... } | true | -| Test.java:12:7:12:17 | case ... | Test.java:12:7:12:17 | case ... | Test.java:13:7:13:16 | default | false | -| Test.java:17:7:17:36 | case | Test.java:15:5:15:25 | var ...; | Test.java:17:19:17:19 | After [no-match] | false | -| Test.java:17:7:17:36 | case | Test.java:15:5:15:25 | var ...; | Test.java:17:26:17:28 | len | true | +| Test.java:4:12:4:14 | "a" | Test.java:2:39:36:3 | { ... } | Test.java:4:12:4:14 | After "a" [match] | match | +| Test.java:4:12:4:14 | "a" | Test.java:2:39:36:3 | { ... } | Test.java:4:17:4:19 | "b" | no match | +| Test.java:4:17:4:19 | "b" | Test.java:4:17:4:19 | "b" | Test.java:4:17:4:19 | After "b" [match] | match | +| Test.java:4:17:4:19 | "b" | Test.java:4:17:4:19 | "b" | Test.java:5:7:5:17 | case ... | no match | +| Test.java:5:12:5:14 | "c" | Test.java:5:7:5:17 | case ... | Test.java:5:19:5:19 | 2 | match | +| Test.java:5:12:5:14 | "c" | Test.java:5:7:5:17 | case ... | Test.java:6:7:6:17 | case ... | no match | +| Test.java:6:12:6:14 | "d" | Test.java:6:7:6:17 | case ... | Test.java:6:19:6:19 | 2 | match | +| Test.java:6:12:6:14 | "d" | Test.java:6:7:6:17 | case ... | Test.java:7:7:7:16 | default | no match | +| Test.java:10:12:10:14 | "a" | Test.java:3:9:3:21 | x | Test.java:10:12:10:14 | After "a" [match] | match | +| Test.java:10:12:10:14 | "a" | Test.java:3:9:3:21 | x | Test.java:10:17:10:19 | "b" | no match | +| Test.java:10:17:10:19 | "b" | Test.java:10:17:10:19 | "b" | Test.java:10:17:10:19 | After "b" [match] | match | +| Test.java:10:17:10:19 | "b" | Test.java:10:17:10:19 | "b" | Test.java:11:7:11:17 | case ... | no match | +| Test.java:11:12:11:14 | "c" | Test.java:11:7:11:17 | case ... | Test.java:11:19:11:21 | { ... } | match | +| Test.java:11:12:11:14 | "c" | Test.java:11:7:11:17 | case ... | Test.java:12:7:12:17 | case ... | no match | +| Test.java:12:12:12:14 | "d" | Test.java:12:7:12:17 | case ... | Test.java:12:19:12:21 | { ... } | match | +| Test.java:12:12:12:14 | "d" | Test.java:12:7:12:17 | case ... | Test.java:13:7:13:16 | default | no match | +| Test.java:17:19:17:19 | | Test.java:15:5:15:25 | var ...; | Test.java:17:19:17:19 | After [no-match] | no match | +| Test.java:17:19:17:19 | | Test.java:15:5:15:25 | var ...; | Test.java:17:26:17:28 | len | match | | Test.java:17:26:17:33 | ... == ... | Test.java:17:26:17:28 | len | Test.java:17:26:17:33 | After ... == ... [false] | false | | Test.java:17:26:17:33 | ... == ... | Test.java:17:26:17:28 | len | Test.java:17:38:17:40 | { ... } | true | -| Test.java:18:7:18:17 | case ... | Test.java:18:7:18:17 | case ... | Test.java:18:19:18:21 | { ... } | true | -| Test.java:18:7:18:17 | case ... | Test.java:18:7:18:17 | case ... | Test.java:19:7:19:16 | default | false | +| Test.java:18:12:18:14 | "e" | Test.java:18:7:18:17 | case ... | Test.java:18:19:18:21 | { ... } | match | +| Test.java:18:12:18:14 | "e" | Test.java:18:7:18:17 | case ... | Test.java:19:7:19:16 | default | no match | | Test.java:21:13:21:19 | unknown | Test.java:21:5:21:42 | switch (...) | Test.java:21:23:21:23 | s | true | | Test.java:21:13:21:19 | unknown | Test.java:21:5:21:42 | switch (...) | Test.java:21:27:21:27 | s | false | -| Test.java:22:7:22:17 | case ... | Test.java:22:7:22:17 | case ... | Test.java:22:19:22:21 | { ... } | true | -| Test.java:22:7:22:17 | case ... | Test.java:22:7:22:17 | case ... | Test.java:23:7:23:37 | case | false | -| Test.java:23:7:23:37 | case | Test.java:23:7:23:37 | case | Test.java:23:19:23:20 | After s2 [no-match] | false | -| Test.java:23:7:23:37 | case | Test.java:23:7:23:37 | case | Test.java:23:27:23:29 | len | true | +| Test.java:22:12:22:14 | "f" | Test.java:22:7:22:17 | case ... | Test.java:22:19:22:21 | { ... } | match | +| Test.java:22:12:22:14 | "f" | Test.java:22:7:22:17 | case ... | Test.java:23:7:23:37 | case | no match | +| Test.java:23:19:23:20 | s2 | Test.java:23:7:23:37 | case | Test.java:23:19:23:20 | After s2 [no-match] | no match | +| Test.java:23:19:23:20 | s2 | Test.java:23:7:23:37 | case | Test.java:23:27:23:29 | len | match | | Test.java:23:27:23:34 | ... == ... | Test.java:23:27:23:29 | len | Test.java:23:27:23:34 | After ... == ... [false] | false | | Test.java:23:27:23:34 | ... == ... | Test.java:23:27:23:29 | len | Test.java:23:39:23:41 | { ... } | true | -| Test.java:24:7:24:17 | case ... | Test.java:24:7:24:17 | case ... | Test.java:24:19:24:21 | { ... } | true | -| Test.java:24:7:24:17 | case ... | Test.java:24:7:24:17 | case ... | Test.java:25:7:25:16 | default | false | -| Test.java:28:7:28:15 | case ... | Test.java:27:5:27:14 | switch (...) | Test.java:28:12:28:14 | After "h" [match] | true | -| Test.java:28:7:28:15 | case ... | Test.java:27:5:27:14 | switch (...) | Test.java:29:7:29:34 | case | false | -| Test.java:29:7:29:34 | case | Test.java:29:7:29:34 | case | Test.java:29:19:29:19 | After [no-match] | false | -| Test.java:29:7:29:34 | case | Test.java:29:7:29:34 | case | Test.java:29:26:29:28 | len | true | +| Test.java:24:12:24:14 | "g" | Test.java:24:7:24:17 | case ... | Test.java:24:19:24:21 | { ... } | match | +| Test.java:24:12:24:14 | "g" | Test.java:24:7:24:17 | case ... | Test.java:25:7:25:16 | default | no match | +| Test.java:28:12:28:14 | "h" | Test.java:27:5:27:14 | switch (...) | Test.java:28:12:28:14 | After "h" [match] | match | +| Test.java:28:12:28:14 | "h" | Test.java:27:5:27:14 | switch (...) | Test.java:29:7:29:34 | case | no match | +| Test.java:29:19:29:19 | | Test.java:29:7:29:34 | case | Test.java:29:19:29:19 | After [no-match] | no match | +| Test.java:29:19:29:19 | | Test.java:29:7:29:34 | case | Test.java:29:26:29:28 | len | match | | Test.java:29:26:29:33 | ... == ... | Test.java:29:26:29:28 | len | Test.java:29:26:29:33 | After ... == ... [false] | false | | Test.java:29:26:29:33 | ... == ... | Test.java:29:26:29:28 | len | Test.java:29:26:29:33 | After ... == ... [true] | true | -| Test.java:30:7:30:15 | case ... | Test.java:30:7:30:15 | case ... | Test.java:30:12:30:14 | After "i" [match] | true | -| Test.java:30:7:30:15 | case ... | Test.java:30:7:30:15 | case ... | Test.java:33:7:33:14 | default | false | +| Test.java:30:12:30:14 | "i" | Test.java:30:7:30:15 | case ... | Test.java:30:12:30:14 | After "i" [match] | match | +| Test.java:30:12:30:14 | "i" | Test.java:30:7:30:15 | case ... | Test.java:33:7:33:14 | default | no match | #select -| Test.java:5:7:5:17 | case ... | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | true | false | Test.java:6:7:6:17 | case ... | -| Test.java:5:7:5:17 | case ... | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | true | false | Test.java:6:19:6:19 | 2 | -| Test.java:5:7:5:17 | case ... | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | true | false | Test.java:7:7:7:16 | default | -| Test.java:5:7:5:17 | case ... | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | true | true | Test.java:5:19:5:19 | 2 | -| Test.java:6:7:6:17 | case ... | Test.java:3:20:3:20 | s | Test.java:6:12:6:14 | "d" | true | false | Test.java:7:7:7:16 | default | -| Test.java:6:7:6:17 | case ... | Test.java:3:20:3:20 | s | Test.java:6:12:6:14 | "d" | true | true | Test.java:6:19:6:19 | 2 | -| Test.java:11:7:11:17 | case ... | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | true | false | Test.java:12:7:12:17 | case ... | -| Test.java:11:7:11:17 | case ... | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | true | false | Test.java:12:19:12:21 | { ... } | -| Test.java:11:7:11:17 | case ... | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | true | false | Test.java:13:7:13:16 | default | -| Test.java:11:7:11:17 | case ... | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | true | true | Test.java:11:19:11:21 | { ... } | -| Test.java:12:7:12:17 | case ... | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | true | false | Test.java:13:7:13:16 | default | -| Test.java:12:7:12:17 | case ... | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | true | true | Test.java:12:19:12:21 | { ... } | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | match | Test.java:4:12:4:14 | After "a" [match] | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | no match | Test.java:4:17:4:19 | "b" | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | no match | Test.java:4:17:4:19 | After "b" [match] | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | no match | Test.java:5:7:5:17 | case ... | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | no match | Test.java:5:19:5:19 | 2 | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | no match | Test.java:6:7:6:17 | case ... | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | no match | Test.java:6:19:6:19 | 2 | +| Test.java:4:12:4:14 | "a" | Test.java:3:20:3:20 | s | Test.java:4:12:4:14 | "a" | match | no match | Test.java:7:7:7:16 | default | +| Test.java:4:17:4:19 | "b" | Test.java:3:20:3:20 | s | Test.java:4:17:4:19 | "b" | match | match | Test.java:4:17:4:19 | After "b" [match] | +| Test.java:4:17:4:19 | "b" | Test.java:3:20:3:20 | s | Test.java:4:17:4:19 | "b" | match | no match | Test.java:5:7:5:17 | case ... | +| Test.java:4:17:4:19 | "b" | Test.java:3:20:3:20 | s | Test.java:4:17:4:19 | "b" | match | no match | Test.java:5:19:5:19 | 2 | +| Test.java:4:17:4:19 | "b" | Test.java:3:20:3:20 | s | Test.java:4:17:4:19 | "b" | match | no match | Test.java:6:7:6:17 | case ... | +| Test.java:4:17:4:19 | "b" | Test.java:3:20:3:20 | s | Test.java:4:17:4:19 | "b" | match | no match | Test.java:6:19:6:19 | 2 | +| Test.java:4:17:4:19 | "b" | Test.java:3:20:3:20 | s | Test.java:4:17:4:19 | "b" | match | no match | Test.java:7:7:7:16 | default | +| Test.java:5:12:5:14 | "c" | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | match | match | Test.java:5:19:5:19 | 2 | +| Test.java:5:12:5:14 | "c" | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | match | no match | Test.java:6:7:6:17 | case ... | +| Test.java:5:12:5:14 | "c" | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | match | no match | Test.java:6:19:6:19 | 2 | +| Test.java:5:12:5:14 | "c" | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | match | no match | Test.java:7:7:7:16 | default | +| Test.java:6:12:6:14 | "d" | Test.java:3:20:3:20 | s | Test.java:6:12:6:14 | "d" | match | match | Test.java:6:19:6:19 | 2 | +| Test.java:6:12:6:14 | "d" | Test.java:3:20:3:20 | s | Test.java:6:12:6:14 | "d" | match | no match | Test.java:7:7:7:16 | default | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | match | Test.java:10:12:10:14 | After "a" [match] | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | no match | Test.java:10:17:10:19 | "b" | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | no match | Test.java:10:17:10:19 | After "b" [match] | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | no match | Test.java:11:7:11:17 | case ... | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | no match | Test.java:11:19:11:21 | { ... } | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | no match | Test.java:12:7:12:17 | case ... | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | no match | Test.java:12:19:12:21 | { ... } | +| Test.java:10:12:10:14 | "a" | Test.java:9:13:9:13 | s | Test.java:10:12:10:14 | "a" | match | no match | Test.java:13:7:13:16 | default | +| Test.java:10:17:10:19 | "b" | Test.java:9:13:9:13 | s | Test.java:10:17:10:19 | "b" | match | match | Test.java:10:17:10:19 | After "b" [match] | +| Test.java:10:17:10:19 | "b" | Test.java:9:13:9:13 | s | Test.java:10:17:10:19 | "b" | match | no match | Test.java:11:7:11:17 | case ... | +| Test.java:10:17:10:19 | "b" | Test.java:9:13:9:13 | s | Test.java:10:17:10:19 | "b" | match | no match | Test.java:11:19:11:21 | { ... } | +| Test.java:10:17:10:19 | "b" | Test.java:9:13:9:13 | s | Test.java:10:17:10:19 | "b" | match | no match | Test.java:12:7:12:17 | case ... | +| Test.java:10:17:10:19 | "b" | Test.java:9:13:9:13 | s | Test.java:10:17:10:19 | "b" | match | no match | Test.java:12:19:12:21 | { ... } | +| Test.java:10:17:10:19 | "b" | Test.java:9:13:9:13 | s | Test.java:10:17:10:19 | "b" | match | no match | Test.java:13:7:13:16 | default | +| Test.java:11:12:11:14 | "c" | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | match | match | Test.java:11:19:11:21 | { ... } | +| Test.java:11:12:11:14 | "c" | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | match | no match | Test.java:12:7:12:17 | case ... | +| Test.java:11:12:11:14 | "c" | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | match | no match | Test.java:12:19:12:21 | { ... } | +| Test.java:11:12:11:14 | "c" | Test.java:9:13:9:13 | s | Test.java:11:12:11:14 | "c" | match | no match | Test.java:13:7:13:16 | default | +| Test.java:12:12:12:14 | "d" | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | match | match | Test.java:12:19:12:21 | { ... } | +| Test.java:12:12:12:14 | "d" | Test.java:9:13:9:13 | s | Test.java:12:12:12:14 | "d" | match | no match | Test.java:13:7:13:16 | default | | Test.java:17:26:17:33 | ... == ... | Test.java:17:26:17:28 | len | Test.java:17:33:17:33 | 4 | true | false | Test.java:17:26:17:33 | After ... == ... [false] | | Test.java:17:26:17:33 | ... == ... | Test.java:17:26:17:28 | len | Test.java:17:33:17:33 | 4 | true | true | Test.java:17:38:17:40 | { ... } | -| Test.java:18:7:18:17 | case ... | Test.java:16:13:16:13 | s | Test.java:18:12:18:14 | "e" | true | false | Test.java:19:7:19:16 | default | -| Test.java:18:7:18:17 | case ... | Test.java:16:13:16:13 | s | Test.java:18:12:18:14 | "e" | true | true | Test.java:18:19:18:21 | { ... } | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:7:23:37 | case | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:19:23:20 | After s2 [no-match] | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:27:23:29 | len | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:27:23:34 | After ... == ... [false] | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:23:39:23:41 | { ... } | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:24:7:24:17 | case ... | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:24:19:24:21 | { ... } | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | false | Test.java:25:7:25:16 | default | -| Test.java:22:7:22:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | true | true | Test.java:22:19:22:21 | { ... } | +| Test.java:18:12:18:14 | "e" | Test.java:16:13:16:13 | s | Test.java:18:12:18:14 | "e" | match | match | Test.java:18:19:18:21 | { ... } | +| Test.java:18:12:18:14 | "e" | Test.java:16:13:16:13 | s | Test.java:18:12:18:14 | "e" | match | no match | Test.java:19:7:19:16 | default | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | match | Test.java:22:19:22:21 | { ... } | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:23:7:23:37 | case | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:23:19:23:20 | After s2 [no-match] | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:23:27:23:29 | len | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:23:27:23:34 | After ... == ... [false] | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:23:39:23:41 | { ... } | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:24:7:24:17 | case ... | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:24:19:24:21 | { ... } | +| Test.java:22:12:22:14 | "f" | Test.java:21:13:21:41 | ...?...:... | Test.java:22:12:22:14 | "f" | match | no match | Test.java:25:7:25:16 | default | | Test.java:23:27:23:34 | ... == ... | Test.java:23:27:23:29 | len | Test.java:23:34:23:34 | 4 | true | false | Test.java:23:27:23:34 | After ... == ... [false] | | Test.java:23:27:23:34 | ... == ... | Test.java:23:27:23:29 | len | Test.java:23:34:23:34 | 4 | true | true | Test.java:23:39:23:41 | { ... } | -| Test.java:24:7:24:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | true | false | Test.java:25:7:25:16 | default | -| Test.java:24:7:24:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | true | true | Test.java:24:19:24:21 | { ... } | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:7:29:34 | case | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:19:29:19 | After [no-match] | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:26:29:28 | len | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:26:29:33 | After ... == ... [false] | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:29:26:29:33 | After ... == ... [true] | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:30:7:30:15 | case ... | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:30:12:30:14 | After "i" [match] | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:33:7:33:14 | default | -| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | true | Test.java:28:12:28:14 | After "h" [match] | +| Test.java:24:12:24:14 | "g" | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | match | match | Test.java:24:19:24:21 | { ... } | +| Test.java:24:12:24:14 | "g" | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | match | no match | Test.java:25:7:25:16 | default | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | match | Test.java:28:12:28:14 | After "h" [match] | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:29:7:29:34 | case | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:29:19:29:19 | After [no-match] | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:29:26:29:28 | len | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:29:26:29:33 | After ... == ... [false] | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:29:26:29:33 | After ... == ... [true] | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:30:7:30:15 | case ... | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:30:12:30:14 | After "i" [match] | +| Test.java:28:12:28:14 | "h" | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | match | no match | Test.java:33:7:33:14 | default | | Test.java:29:26:29:33 | ... == ... | Test.java:29:26:29:28 | len | Test.java:29:33:29:33 | 4 | true | false | Test.java:29:26:29:33 | After ... == ... [false] | | Test.java:29:26:29:33 | ... == ... | Test.java:29:26:29:28 | len | Test.java:29:33:29:33 | 4 | true | true | Test.java:29:26:29:33 | After ... == ... [true] | -| Test.java:30:7:30:15 | case ... | Test.java:27:13:27:13 | s | Test.java:30:12:30:14 | "i" | true | false | Test.java:33:7:33:14 | default | -| Test.java:30:7:30:15 | case ... | Test.java:27:13:27:13 | s | Test.java:30:12:30:14 | "i" | true | true | Test.java:30:12:30:14 | After "i" [match] | +| Test.java:30:12:30:14 | "i" | Test.java:27:13:27:13 | s | Test.java:30:12:30:14 | "i" | match | match | Test.java:30:12:30:14 | After "i" [match] | +| Test.java:30:12:30:14 | "i" | Test.java:27:13:27:13 | s | Test.java:30:12:30:14 | "i" | match | no match | Test.java:33:7:33:14 | default | diff --git a/java/ql/test/library-tests/guards12/guard.ql b/java/ql/test/library-tests/guards12/guard.ql index d4d134d81863..72b430267c35 100644 --- a/java/ql/test/library-tests/guards12/guard.ql +++ b/java/ql/test/library-tests/guards12/guard.ql @@ -16,5 +16,7 @@ from Guard g, BasicBlock bb, GuardValue branch, Expr e1, Expr e2, GuardValue eqv where g.valueControls(bb, branch) and g.isEquality(e1, e2, eqval) and - not e1 instanceof Literal + not e1 instanceof Literal and + not e1 instanceof PatternExpr and + not e2 instanceof PatternExpr select g, e1, e2, eqval, branch, getFirstAstNodeOrSynth(bb) diff --git a/java/ql/test/library-tests/switch-default-impossible-dispatch/Test.java b/java/ql/test/library-tests/switch-default-impossible-dispatch/Test.java index 7c00a71021e6..a33e7ef7f39a 100644 --- a/java/ql/test/library-tests/switch-default-impossible-dispatch/Test.java +++ b/java/ql/test/library-tests/switch-default-impossible-dispatch/Test.java @@ -63,7 +63,7 @@ case WrapperWrapper(Wrapper(String s)) -> { } i.take(source()); // Must be either C1.take or C2.take (but we don't currently notice, because neither dominates) break; default: - i.take(source()); // Can't call C1.take or C2.take (but we don't currently notice, because a multi-pattern case isn't understood as a type test) + i.take(source()); // Can't call C1.take or C2.take } switch(i) { @@ -71,7 +71,7 @@ case WrapperWrapper(Wrapper(String s)) -> { } i.take(source()); // Must be either C1.take or C2.take (but we don't currently notice, because neither dominates) break; default: - i.take(source()); // Can't call C1.take or C2.take (but we don't currently notice, because a multi-pattern case isn't understood as a type test) + i.take(source()); // Could call any implementation, because of the guard } switch(i) { diff --git a/java/ql/test/library-tests/switch-default-impossible-dispatch/test.expected b/java/ql/test/library-tests/switch-default-impossible-dispatch/test.expected index f95dc4ee9466..7436a4fe1c9c 100644 --- a/java/ql/test/library-tests/switch-default-impossible-dispatch/test.expected +++ b/java/ql/test/library-tests/switch-default-impossible-dispatch/test.expected @@ -32,8 +32,6 @@ | Test.java:63:16:63:23 | source(...) | Test.java:8:65:8:65 | x | | Test.java:63:16:63:23 | source(...) | Test.java:9:74:9:74 | x | | Test.java:63:16:63:23 | source(...) | Test.java:10:82:10:82 | x | -| Test.java:66:16:66:23 | source(...) | Test.java:7:65:7:65 | x | -| Test.java:66:16:66:23 | source(...) | Test.java:8:65:8:65 | x | | Test.java:66:16:66:23 | source(...) | Test.java:9:74:9:74 | x | | Test.java:66:16:66:23 | source(...) | Test.java:10:82:10:82 | x | | Test.java:71:16:71:23 | source(...) | Test.java:7:65:7:65 | x | diff --git a/shared/controlflow/codeql/controlflow/Guards.qll b/shared/controlflow/codeql/controlflow/Guards.qll index 45f1f1175beb..282d97e21826 100644 --- a/shared/controlflow/codeql/controlflow/Guards.qll +++ b/shared/controlflow/codeql/controlflow/Guards.qll @@ -98,19 +98,6 @@ signature module InputSig