Skip to content

Constant propagation of CProverString.setLength() and CProverString.setCharAt() #5134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.cprover.CProverString;

public class Test
{
public void testSuccess1()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No negative tests? Setting out of range for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not included test cases for the error cases here as those will be handled by the models in the future. I'll add tests for those cases once we have models that use the CProverString primitives.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but we should check that they aren't accidentally const propagated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, added more tests.

{
StringBuffer sb = new StringBuffer("abc");
CProverString.setCharAt(sb, 0, 'd');
assert sb.toString().equals("dbc");
}

public void testSuccess2()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setCharAt(sb, 2, 'd');
assert sb.toString().equals("abd");
}

public void testNoPropagation1()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setCharAt(sb, -1, 'd');
assert sb.toString().equals("dbc");
}

public void testNoPropagation2()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setCharAt(sb, 3, 'd');
assert sb.toString().equals("dbc");
}

public void testNoPropagation3(StringBuffer sb)
{
CProverString.setCharAt(sb, 1, 'd');
assert sb.toString().equals("dbc");
}

public void testNoPropagation4(int index)
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setCharAt(sb, index, 'd');
assert sb.toString().equals("dbc");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--function Test.testNoPropagation1 --show-vcc --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property 'java::Test.testNoPropagation1:()V.assertion.1'
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--function Test.testNoPropagation2 --show-vcc --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property 'java::Test.testNoPropagation2:()V.assertion.1'
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--function Test.testNoPropagation3 --show-vcc --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property 'java::Test.testNoPropagation3:(Ljava/lang/StringBuffer;)V.assertion.1'
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--function Test.testNoPropagation4 --show-vcc --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property 'java::Test.testNoPropagation4:(I)V.assertion.1'
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess1 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess2 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import org.cprover.CProverString;

public class Test
{
public void testSuccess1()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setLength(sb, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test setting to same length (i.e. 3 in this case)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

assert sb.toString().equals("");
}

public void testSuccess2()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setLength(sb, 2);
assert sb.toString().equals("ab");
}

public void testSuccess3()
{
StringBuffer sb = new StringBuffer("abc");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test extension by more than one char

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

CProverString.setLength(sb, 3);
assert sb.toString().equals("abc");
}

public void testSuccess4()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setLength(sb, 4);
assert sb.toString().equals("abc\u0000");
}

public void testSuccess5()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setLength(sb, 5);
assert sb.toString().equals("abc\u0000\u0000");
}

public void testSuccess6(StringBuffer sb)
{
CProverString.setLength(sb, 0);
assert sb.toString().equals("");
}

public void testNoPropagation1()
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setLength(sb, -1);
assert sb.toString().equals("abc");
}

public void testNoPropagation2(StringBuffer sb)
{
CProverString.setLength(sb, 3);
assert sb.toString().equals("abc");
}

public void testNoPropagation3(int newLength)
{
StringBuffer sb = new StringBuffer("abc");
CProverString.setLength(sb, newLength);
assert sb.toString().equals("abc");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--function Test.testNoPropagation1 --show-vcc --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property 'java::Test.testNoPropagation1:()V.assertion.1'
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--function Test.testNoPropagation2 --show-vcc --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property 'java::Test.testNoPropagation2:(Ljava/lang/StringBuffer;)V.assertion.1'
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE symex-driven-lazy-loading-expected-failure
Test.class
--function Test.testNoPropagation3 --show-vcc --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --property 'java::Test.testNoPropagation3:(I)V.assertion.1'
^Generated [0-9]+ VCC\(s\), 1 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess1 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess2 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess3 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess4 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess5 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--function Test.testSuccess5 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^Generated [0-9]+ VCC\(s\), 0 remaining after simplification$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
12 changes: 9 additions & 3 deletions jbmc/src/java_bytecode/java_string_library_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1528,11 +1528,17 @@ void java_string_library_preprocesst::initialize_conversion_table()
["java::org.cprover.CProverString.offsetByCodePoints:(Ljava/lang/"
"String;II)I"] = ID_cprover_string_offset_by_code_point_func;
cprover_equivalent_to_java_assign_function
["java::org.cprover.CProverString.setCharAt:(Ljava/lang/String;IC)V"] =
ID_cprover_string_char_set_func;
["java::org.cprover.CProverString.setCharAt:(Ljava/lang/"
"StringBuffer;IC)V"] = ID_cprover_string_char_set_func;
cprover_equivalent_to_java_assign_function
["java::org.cprover.CProverString.setCharAt:(Ljava/lang/"
"StringBuilder;IC)V"] = ID_cprover_string_char_set_func;
cprover_equivalent_to_java_assign_function
["java::org.cprover.CProverString.setLength:(Ljava/lang/String;I)V"] =
["java::org.cprover.CProverString.setLength:(Ljava/lang/StringBuffer;I)V"] =
ID_cprover_string_set_length_func;
cprover_equivalent_to_java_assign_function
["java::org.cprover.CProverString.setLength:(Ljava/lang/"
"StringBuilder;I)V"] = ID_cprover_string_set_length_func;
cprover_equivalent_to_java_string_returning_function
["java::org.cprover.CProverString.subSequence:(Ljava/lang/String;II)Ljava/"
"lang/CharSequence;"] = ID_cprover_string_substring_func;
Expand Down
Loading