Skip to content

Commit 8f9a9c7

Browse files
committed
Implement constant propagation for substring operations
This implements constant propagation of ID_cprover_string_substring_func function application expressions. These are in turn used by the various substring operations of String and StringBuilder.
1 parent 115c5f8 commit 8f9a9c7

File tree

18 files changed

+284
-0
lines changed

18 files changed

+284
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class Main {
2+
public void test() {
3+
StringBuilder sb = new StringBuilder("abc");
4+
5+
String s1 = sb.substring(0);
6+
assert s1.length() == 3;
7+
assert s1.startsWith("abc");
8+
9+
String s2 = sb.substring(1);
10+
assert s2.length() == 2;
11+
assert s2.startsWith("bc");
12+
13+
String s3 = sb.substring(0, 3);
14+
assert s3.length() == 3;
15+
assert s3.startsWith("abc");
16+
17+
String s4 = sb.substring(0, 0);
18+
assert s4.length() == 0;
19+
assert s4.startsWith("");
20+
21+
String s5 = sb.substring(0, 1);
22+
assert s5.length() == 1;
23+
assert s5.startsWith("a");
24+
}
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
Main.class
3+
--function Main.test
4+
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
--
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Main {
2+
public void test1(StringBuilder sb) {
3+
String s = sb.substring(0);
4+
assert s.startsWith("xyz");
5+
}
6+
7+
public void test2(int i) {
8+
StringBuilder sb = new StringBuilder("abc");
9+
10+
String s = sb.substring(i);
11+
assert s.startsWith("xyz");
12+
}
13+
14+
public void test3(StringBuilder sb, int i) {
15+
String s = sb.substring(i);
16+
assert s.startsWith("xyz");
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Main.class
3+
--function Main.test1 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property "java::Main.test1:(Ljava/lang/StringBuilder;)V.assertion.1"
4+
^Generated 1 VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Main.class
3+
--function Main.test2 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property "java::Main.test2:(I)V.assertion.1"
4+
^Generated 1 VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Main.class
3+
--function Main.test3 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property "java::Main.test3:(Ljava/lang/StringBuilder;I)V.assertion.1"
4+
^Generated 1 VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
--
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Main {
2+
public void test() {
3+
String s = "abc";
4+
5+
String s1 = s.substring(0);
6+
assert s1.equals("abc");
7+
8+
String s2 = s.substring(1);
9+
assert s2.equals("bc");
10+
11+
String s3 = s.substring(0, 3);
12+
assert s3.equals("abc");
13+
14+
String s4 = s.substring(0, 0);
15+
assert s4.equals("");
16+
17+
String s5 = s.substring(0, 1);
18+
assert s5.equals("a");
19+
}
20+
}

0 commit comments

Comments
 (0)