Skip to content

Commit 744671a

Browse files
authored
Merge pull request #4941 from danpoe/feature/constant-propagate-string-substring
[TG-7648] Constant propagation of substring operations
2 parents 60b2851 + e56041f commit 744671a

File tree

28 files changed

+385
-0
lines changed

28 files changed

+385
-0
lines changed
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+
}
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.
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+
}
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+
--
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+
--
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Main {
2+
public void test1() {
3+
StringBuilder sb = new StringBuilder("abc");
4+
sb.substring(-1);
5+
}
6+
7+
public void test2() {
8+
StringBuilder sb = new StringBuilder("abc");
9+
sb.substring(4);
10+
}
11+
12+
public void test3() {
13+
StringBuilder sb = new StringBuilder("abc");
14+
sb.substring(-1, 4);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FUTURE
2+
Main.class
3+
--function Main.test1 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^Generated [1-9][0-9]* VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
no uncaught exception: FAILURE
8+
^VERIFICATION FAILED$
9+
--
10+
--
11+
This test will pass once a model for StringBuilder.substring() exists that
12+
throws an exception when the index is greater or equal to the length of the
13+
string.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FUTURE
2+
Main.class
3+
--function Main.test2 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^Generated [1-9][0-9]* VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
no uncaught exception: FAILURE
8+
^VERIFICATION FAILED$
9+
--
10+
--
11+
This test will pass once a model for StringBuilder.substring() exists that
12+
throws an exception when the index is greater or equal to the length of the
13+
string.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FUTURE
2+
Main.class
3+
--function Main.test3 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^Generated [1-9][0-9]* VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
no uncaught exception: FAILURE
8+
^VERIFICATION FAILED$
9+
--
10+
--
11+
This test will pass once a model for StringBuilder.substring() exists that
12+
throws an exception when the index is greater or equal to the length of the
13+
string.
Binary file not shown.
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
Main.class
3+
--function Main.test --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Main {
2+
public void test1(String s1) {
3+
String s2 = s1.substring(0);
4+
assert s2.startsWith("xyz");
5+
}
6+
7+
public void test2(int i) {
8+
String s1 = "abc";
9+
10+
String s2 = s1.substring(i);
11+
assert s2.startsWith("xyz");
12+
}
13+
14+
public void test3(String s1, int i) {
15+
String s2 = s1.substring(i);
16+
assert s2.startsWith("xyz");
17+
}
18+
}
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/String;)V.assertion.1"
4+
^Generated 1 VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
--
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+
--
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/String;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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Main {
2+
public void test1() {
3+
String s1 = "abc";
4+
s1.substring(-1);
5+
}
6+
7+
public void test2() {
8+
String s1 = "abc";
9+
s1.substring(4);
10+
}
11+
12+
public void test3() {
13+
String s1 = "abc";
14+
s1.substring(-1, 4);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
Main.class
3+
--function Main.test1 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^Generated [1-9][0-9]* VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
no uncaught exception: FAILURE
8+
^VERIFICATION FAILED$
9+
--
10+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
Main.class
3+
--function Main.test2 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^Generated [1-9][0-9]* VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
no uncaught exception: FAILURE
8+
^VERIFICATION FAILED$
9+
--
10+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
Main.class
3+
--function Main.test3 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
4+
^Generated [1-9][0-9]* VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
no uncaught exception: FAILURE
8+
^VERIFICATION FAILED$
9+
--
10+
--

0 commit comments

Comments
 (0)