diff --git a/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll b/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll index a020c0c91e3..76cccb4a625 100644 --- a/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll +++ b/cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll @@ -125,41 +125,16 @@ module GuardsInput implements SharedGuards::InputSig op < k - 1 isLt = true and - maxValue.toInt() = k - 1 + maxValue.toInt() = k - 1 and + value.isIntRange(k - 1, true) or isLt = false and - minValue.toInt() = k + minValue.toInt() = k and + value.isIntRange(k, false) ) } diff --git a/cpp/ql/test/library-tests/controlflow/guards/GuardsCompare.expected b/cpp/ql/test/library-tests/controlflow/guards/GuardsCompare.expected index cb18638c71e..0216df7b31f 100644 --- a/cpp/ql/test/library-tests/controlflow/guards/GuardsCompare.expected +++ b/cpp/ql/test/library-tests/controlflow/guards/GuardsCompare.expected @@ -490,22 +490,22 @@ | test.cpp:69:12:69:12 | i | i == 0 when i is 0 | | test.cpp:69:12:69:12 | i | i == 1 when i is 1 | | test.cpp:69:12:69:12 | i | i == 2 when i is 2 | -| test.cpp:73:30:73:30 | i | i < 11 when i is 0..10 | -| test.cpp:73:30:73:30 | i | i < 21 when i is 11..20 | -| test.cpp:73:30:73:30 | i | i >= 0 when i is 0..10 | -| test.cpp:73:30:73:30 | i | i >= 11 when i is 11..20 | -| test.cpp:74:10:74:10 | i | i < 11 when i is 0..10 | -| test.cpp:74:10:74:10 | i | i < 21 when i is 11..20 | -| test.cpp:74:10:74:10 | i | i >= 0 when i is 0..10 | -| test.cpp:74:10:74:10 | i | i >= 11 when i is 11..20 | -| test.cpp:76:12:76:12 | i | i < 11 when i is 0..10 | -| test.cpp:76:12:76:12 | i | i < 21 when i is 11..20 | -| test.cpp:76:12:76:12 | i | i >= 0 when i is 0..10 | -| test.cpp:76:12:76:12 | i | i >= 11 when i is 11..20 | -| test.cpp:79:12:79:12 | i | i < 11 when i is 0..10 | -| test.cpp:79:12:79:12 | i | i < 21 when i is 11..20 | -| test.cpp:79:12:79:12 | i | i >= 0 when i is 0..10 | -| test.cpp:79:12:79:12 | i | i >= 11 when i is 11..20 | +| test.cpp:73:30:73:30 | i | i < 11 when i is Upper bound 10 | +| test.cpp:73:30:73:30 | i | i < 21 when i is Upper bound 20 | +| test.cpp:73:30:73:30 | i | i >= 0 when i is Lower bound 0 | +| test.cpp:73:30:73:30 | i | i >= 11 when i is Lower bound 11 | +| test.cpp:74:10:74:10 | i | i < 11 when i is Upper bound 10 | +| test.cpp:74:10:74:10 | i | i < 21 when i is Upper bound 20 | +| test.cpp:74:10:74:10 | i | i >= 0 when i is Lower bound 0 | +| test.cpp:74:10:74:10 | i | i >= 11 when i is Lower bound 11 | +| test.cpp:76:12:76:12 | i | i < 11 when i is Upper bound 10 | +| test.cpp:76:12:76:12 | i | i < 21 when i is Upper bound 20 | +| test.cpp:76:12:76:12 | i | i >= 0 when i is Lower bound 0 | +| test.cpp:76:12:76:12 | i | i >= 11 when i is Lower bound 11 | +| test.cpp:79:12:79:12 | i | i < 11 when i is Upper bound 10 | +| test.cpp:79:12:79:12 | i | i < 21 when i is Upper bound 20 | +| test.cpp:79:12:79:12 | i | i >= 0 when i is Lower bound 0 | +| test.cpp:79:12:79:12 | i | i >= 11 when i is Lower bound 11 | | test.cpp:93:6:93:6 | c | c != 0 when c is true | | test.cpp:93:6:93:6 | c | c != 1 when c is false | | test.cpp:93:6:93:6 | c | c == 0 when c is false | @@ -1304,7 +1304,7 @@ | test.cpp:330:7:330:7 | b | b != 1 when b is false | | test.cpp:330:7:330:7 | b | b == 0 when b is false | | test.cpp:330:7:330:7 | b | b == 1 when b is true | -| test.cpp:334:11:334:11 | x | x < 51 when x is 40..50 | -| test.cpp:334:11:334:11 | x | x >= 40 when x is 40..50 | -| test.cpp:338:9:338:9 | x | x < 51 when x is 40..50 | -| test.cpp:338:9:338:9 | x | x >= 40 when x is 40..50 | +| test.cpp:334:11:334:11 | x | x < 51 when x is Upper bound 50 | +| test.cpp:334:11:334:11 | x | x >= 40 when x is Lower bound 40 | +| test.cpp:338:9:338:9 | x | x < 51 when x is Upper bound 50 | +| test.cpp:338:9:338:9 | x | x >= 40 when x is Lower bound 40 | diff --git a/cpp/ql/test/library-tests/controlflow/guards/GuardsControl.expected b/cpp/ql/test/library-tests/controlflow/guards/GuardsControl.expected index b35ec323266..e9ef52f709d 100644 --- a/cpp/ql/test/library-tests/controlflow/guards/GuardsControl.expected +++ b/cpp/ql/test/library-tests/controlflow/guards/GuardsControl.expected @@ -178,12 +178,18 @@ | test.cpp:42:13:42:20 | call to getABool | true | test.cpp:43:9:45:23 | { ... } | | test.cpp:60:31:60:31 | i | 0 | test.cpp:62:5:64:12 | case ...: | | test.cpp:60:31:60:31 | i | 1 | test.cpp:65:5:66:10 | case ...: | +| test.cpp:60:31:60:31 | i | 10 | test.cpp:62:5:64:12 | case ...: | | test.cpp:61:10:61:10 | i | 0 | test.cpp:62:5:64:12 | case ...: | | test.cpp:61:10:61:10 | i | 1 | test.cpp:65:5:66:10 | case ...: | -| test.cpp:73:30:73:30 | i | 0..10 | test.cpp:75:5:77:12 | case ...: | -| test.cpp:73:30:73:30 | i | 11..20 | test.cpp:78:5:79:10 | case ...: | -| test.cpp:74:10:74:10 | i | 0..10 | test.cpp:75:5:77:12 | case ...: | -| test.cpp:74:10:74:10 | i | 11..20 | test.cpp:78:5:79:10 | case ...: | +| test.cpp:61:10:61:10 | i | 10 | test.cpp:62:5:64:12 | case ...: | +| test.cpp:73:30:73:30 | i | Lower bound 0 | test.cpp:75:5:77:12 | case ...: | +| test.cpp:73:30:73:30 | i | Lower bound 11 | test.cpp:78:5:79:10 | case ...: | +| test.cpp:73:30:73:30 | i | Upper bound 10 | test.cpp:75:5:77:12 | case ...: | +| test.cpp:73:30:73:30 | i | Upper bound 20 | test.cpp:78:5:79:10 | case ...: | +| test.cpp:74:10:74:10 | i | Lower bound 0 | test.cpp:75:5:77:12 | case ...: | +| test.cpp:74:10:74:10 | i | Lower bound 11 | test.cpp:78:5:79:10 | case ...: | +| test.cpp:74:10:74:10 | i | Upper bound 10 | test.cpp:75:5:77:12 | case ...: | +| test.cpp:74:10:74:10 | i | Upper bound 20 | test.cpp:78:5:79:10 | case ...: | | test.cpp:92:31:92:31 | c | not null | test.cpp:93:9:94:7 | { ... } | | test.cpp:93:6:93:6 | c | not null | test.cpp:93:9:94:7 | { ... } | | test.cpp:93:6:93:6 | c | true | test.cpp:93:9:94:7 | { ... } | @@ -328,9 +334,7 @@ | test.cpp:318:6:318:18 | ... != ... | true | test.cpp:318:21:320:3 | { ... } | | test.cpp:318:7:318:12 | ... < ... | 0 | test.cpp:320:10:322:3 | { ... } | | test.cpp:318:7:318:12 | ... < ... | not 0 | test.cpp:318:21:320:3 | { ... } | -| test.cpp:327:46:327:46 | b | false | test.cpp:336:3:338:7 | case ...: | | test.cpp:327:46:327:46 | b | true | test.cpp:331:3:332:10 | { ... } | -| test.cpp:329:11:329:13 | call to foo | 40..50 | test.cpp:336:3:338:7 | case ...: | -| test.cpp:330:7:330:7 | b | false | test.cpp:336:3:338:7 | case ...: | | test.cpp:330:7:330:7 | b | true | test.cpp:331:3:332:10 | { ... } | -| test.cpp:334:11:334:11 | x | 40..50 | test.cpp:336:3:338:7 | case ...: | +| test.cpp:334:11:334:11 | x | Lower bound 40 | test.cpp:336:3:338:7 | case ...: | +| test.cpp:334:11:334:11 | x | Upper bound 50 | test.cpp:336:3:338:7 | case ...: | diff --git a/cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.expected b/cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.expected index fdbdca43184..1f0b1197230 100644 --- a/cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.expected +++ b/cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.expected @@ -1295,12 +1295,8 @@ unary | test.cpp:318:6:318:18 | ... != ... | test.cpp:318:7:318:12 | ... < ... | != | 0 | test.cpp:318:21:320:3 | { ... } | | test.cpp:318:6:318:18 | ... != ... | test.cpp:318:7:318:12 | ... < ... | == | 0 | test.cpp:320:10:322:3 | { ... } | | test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | != | 0 | test.cpp:331:3:332:10 | { ... } | -| test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | != | 1 | test.cpp:336:3:338:7 | case ...: | -| test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | == | 0 | test.cpp:336:3:338:7 | case ...: | | test.cpp:327:46:327:46 | b | test.cpp:330:7:330:7 | b | == | 1 | test.cpp:331:3:332:10 | { ... } | | test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | != | 0 | test.cpp:331:3:332:10 | { ... } | -| test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | != | 1 | test.cpp:336:3:338:7 | case ...: | -| test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | == | 0 | test.cpp:336:3:338:7 | case ...: | | test.cpp:330:7:330:7 | b | test.cpp:330:7:330:7 | b | == | 1 | test.cpp:331:3:332:10 | { ... } | | test.cpp:334:11:334:11 | x | test.cpp:334:11:334:11 | x | < | 51 | test.cpp:336:3:338:7 | case ...: | | test.cpp:334:11:334:11 | x | test.cpp:334:11:334:11 | x | >= | 40 | test.cpp:336:3:338:7 | case ...: |