Skip to content

Commit e4b4d2e

Browse files
committed
Implement constant propagation of string concatenation
This implements constant propagation of ID_cprover_string_concat_func and ID_cprover_string_empty_string_func which are the primitives used by StringBuilder.append(), which in turn is used to implement String concatenation using +.
1 parent 0073ca7 commit e4b4d2e

File tree

29 files changed

+611
-1
lines changed

29 files changed

+611
-1
lines changed
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Main {
2+
public void test() {
3+
StringBuilder sb = new StringBuilder("abc");
4+
sb.append("xyz");
5+
String s = sb.toString();
6+
assert s.length() == 6;
7+
assert s.startsWith("abcxyz");
8+
}
9+
}
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 --property "java::Main.test:()V.assertion.1" --property "java::Main.test:()V.assertion.2"
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class Main {
2+
public void test1() {
3+
StringBuilder sb1 = new StringBuilder("abc");
4+
String s2 = "";
5+
sb1.append(s2);
6+
assert sb1.length() == 3;
7+
assert sb1.toString().startsWith("abc");
8+
}
9+
10+
public void test2() {
11+
StringBuilder sb1 = new StringBuilder();
12+
String s2 = "abc";
13+
sb1.append(s2);
14+
assert sb1.length() == 3;
15+
assert sb1.toString().startsWith("abc");
16+
}
17+
18+
public void test3() {
19+
StringBuilder sb1 = new StringBuilder();
20+
String s2 = "";
21+
sb1.append(s2);
22+
assert sb1.length() == 0;
23+
assert sb1.toString().startsWith("");
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.test1 --property "java::Main.test1:()V.assertion.1" --property "java::Main.test1:()V.assertion.2"
4+
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
--
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.test2 --property "java::Main.test2:()V.assertion.1" --property "java::Main.test2:()V.assertion.2"
4+
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
--
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.test3 --property "java::Main.test3:()V.assertion.1" --property "java::Main.test3:()V.assertion.2"
4+
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class Main {
2+
public void test() {
3+
StringBuilder sb = new StringBuilder();
4+
String s = sb.toString();
5+
assert s.isEmpty();
6+
assert s.length() == 0;
7+
}
8+
}
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class Main {
2+
public void test() {
3+
String s1 = "abc";
4+
String s2 = "xyz";
5+
String s3 = s1 + s2;
6+
assert s3.length() == 6;
7+
assert s3.startsWith("abcxyz");
8+
}
9+
}
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 --property "java::Main.test:()V.assertion.1" --property "java::Main.test:()V.assertion.2"
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class Main {
2+
public void test1() {
3+
String s1 = "abc";
4+
String s2 = "";
5+
String s3 = s1 + s2;
6+
assert s3.length() == 3;
7+
assert s3.startsWith("abc");
8+
}
9+
10+
public void test2() {
11+
String s1 = "";
12+
String s2 = "abc";
13+
String s3 = s1 + s2;
14+
assert s3.length() == 3;
15+
assert s3.startsWith("abc");
16+
}
17+
18+
public void test3() {
19+
String s1 = "";
20+
String s2 = "";
21+
String s3 = s1 + s2;
22+
assert s3.length() == 0;
23+
assert s3.startsWith("");
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.test1 --property "java::Main.test1:()V.assertion.1" --property "java::Main.test1:()V.assertion.2"
4+
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
--
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.test2 --property "java::Main.test2:()V.assertion.1" --property "java::Main.test2:()V.assertion.2"
4+
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL$
8+
--
9+
--
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.test3 --property "java::Main.test3:()V.assertion.1" --property "java::Main.test3:()V.assertion.2"
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class Main {
2+
public void test1(String s1) {
3+
String s2 = "abc";
4+
assert (s1 + s2).startsWith("abc");
5+
}
6+
7+
public void test2(String s) { assert ("" + s).startsWith("abc"); }
8+
9+
public void test3(String s) { assert (s + s).startsWith("abc"); }
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Main.class
3+
--function Main.test1 --property "java::Main.test1:(Ljava/lang/String;)V.assertion.1"
4+
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
--
10+
This test checks that constant propagation does not happen, since a constant
11+
result cannot be determined from the arguments to `+`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Main.class
3+
--function Main.test2 --property "java::Main.test2:(Ljava/lang/String;)V.assertion.1"
4+
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
--
10+
This test checks that constant propagation does not happen, since a constant
11+
result cannot be determined from the arguments to `+`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Main.class
3+
--function Main.test3 --property "java::Main.test3:(Ljava/lang/String;)V.assertion.1"
4+
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
^VERIFICATION FAILED$
8+
--
9+
--
10+
This test checks that constant propagation does not happen, since a constant
11+
result cannot be determined from the arguments to `+`.
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Main {
2+
public void test() {
3+
String s = new String();
4+
assert s.isEmpty();
5+
assert s.startsWith("");
6+
}
7+
}
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+
--

0 commit comments

Comments
 (0)