Skip to content

Commit 22d5dc9

Browse files
committed
Shared: Bugfix for unique value implication.
1 parent 378209a commit 22d5dc9

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

java/ql/test/library-tests/guards/Guards.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,20 @@ void t6() {
127127
chk(); // $ guarded='o != null:false' guarded=g(1):false
128128
}
129129
}
130+
131+
void t7(int[] a) {
132+
boolean found = false;
133+
for (int i = 0; i < a.length; i++) {
134+
boolean answer = a[i] == 42;
135+
if (answer) {
136+
found = true;
137+
}
138+
if (found) {
139+
chk(); // $ guarded=found:true guarded='i < a.length:true'
140+
}
141+
}
142+
if (found) {
143+
chk(); // $ guarded=found:true guarded='i < a.length:false'
144+
}
145+
}
130146
}

java/ql/test/library-tests/guards/GuardsInline.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@
5454
| Guards.java:125:7:125:11 | chk(...) | 'o != null:true' |
5555
| Guards.java:127:7:127:11 | chk(...) | 'o != null:false' |
5656
| Guards.java:127:7:127:11 | chk(...) | g(1):false |
57+
| Guards.java:139:9:139:13 | chk(...) | 'i < a.length:true' |
58+
| Guards.java:139:9:139:13 | chk(...) | found:true |
59+
| Guards.java:143:7:143:11 | chk(...) | 'i < a.length:false' |
60+
| Guards.java:143:7:143:11 | chk(...) | found:true |

shared/controlflow/codeql/controlflow/Guards.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
647647
*/
648648
private predicate uniqueValue(SsaDefinition v, Expr e, GuardValue k) {
649649
possibleValue(v, false, e, k) and
650+
not possibleValue(v, true, e, k) and
650651
forex(Expr other, GuardValue otherval | possibleValue(v, _, other, otherval) and other != e |
651652
disjointValues(otherval, k)
652653
)

0 commit comments

Comments
 (0)