Skip to content

Commit 5f2018b

Browse files
Make unsupported case notModelled instead of using assume
Under-approximated models can lead to spurious UNSAT results in JBMC; however, we can mark over-approximated cases as notModelled and JBMC will detect them and give a warning that behaviour is over-approximating when reporting SAT.
1 parent de1bd66 commit 5f2018b

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/main/java/java/util/regex/Pattern.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,9 +1157,9 @@ public int flags() {
11571157
* no characters that has special meaning in regular expressions.
11581158
* This way we can then match the regex using String.equals().
11591159
*/
1160-
private static void cproverAssumeIsPlainString(String regex)
1160+
private static boolean cproverIsPlainString(String regex)
11611161
{
1162-
CProver.assume(
1162+
return
11631163
regex.indexOf('[') == -1 &&
11641164
regex.indexOf(']') == -1 &&
11651165
regex.indexOf('{') == -1 &&
@@ -1173,7 +1173,11 @@ private static void cproverAssumeIsPlainString(String regex)
11731173
regex.indexOf('*') == -1 &&
11741174
regex.indexOf('^') == -1 &&
11751175
regex.indexOf('$') == -1 &&
1176-
regex.indexOf('|') == -1);
1176+
regex.indexOf('|') == -1;
1177+
}
1178+
private static void cproverAssumeIsPlainString(String regex)
1179+
{
1180+
CProver.assume(cproverIsPlainString(regex));
11771181
}
11781182

11791183
/**
@@ -1210,14 +1214,18 @@ public static boolean matches(String regex, CharSequence input) {
12101214
// Matcher m = p.matcher(input);
12111215
// return m.matches();
12121216

1213-
// DIFFBLUE MODEL LIBRARY
1214-
// We disallow special characters so that we can do matching using equals.
1215-
cproverAssumeIsPlainString(regex);
12161217
//
12171218
if (input == null) {
12181219
throw new NullPointerException(); // JDK throws NPE when the 2nd param is null
12191220
}
1220-
return regex.equals(input);
1221+
// DIFFBLUE MODEL LIBRARY
1222+
// We disallow special characters so that we can do matching using equals.
1223+
if (cproverIsPlainString(regex)) {
1224+
return regex.equals(input);
1225+
} else {
1226+
CProver.notModelled();
1227+
return CProver.nondetBoolean();
1228+
}
12211229
}
12221230

12231231
/**
@@ -1441,7 +1449,9 @@ public static String quote(String s) {
14411449
private Pattern(String p, int f) {
14421450
// DIFFBLUE MODEL LIBRARY
14431451
// We disallow special characters so that we can use equals for matching.
1444-
cproverAssumeIsPlainString(p);
1452+
if (!cproverIsPlainString(p)) {
1453+
CProver.notModelled();
1454+
}
14451455
pattern = p;
14461456
// pattern = p;
14471457
// flags = f;

0 commit comments

Comments
 (0)