Skip to content

Fix issue testgen#119 #802

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
merged 4 commits into from
Apr 12, 2017
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.
9 changes: 9 additions & 0 deletions regression/strings/bug-test-gen-119-2/StringValueOfLong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class StringValueOfLong
{
public static void main()
{
long longValue = 10000000000L; // L suffix indicates long
String tmp=String.valueOf(longValue);
assert tmp.equals("10000000000");
}
}
7 changes: 7 additions & 0 deletions regression/strings/bug-test-gen-119-2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FUTURE
StringValueOfLong.class
--refine-strings
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
Binary file not shown.
10 changes: 10 additions & 0 deletions regression/strings/bug-test-gen-119/StringValueOfBool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class StringValueOfBool
{
public static void main()
{
boolean booleanValue = false;

String tmp=String.valueOf(booleanValue);
assert tmp.equals("false");
}
}
7 changes: 7 additions & 0 deletions regression/strings/bug-test-gen-119/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FUTURE
StringValueOfBool.class
--refine-strings
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
289 changes: 164 additions & 125 deletions src/goto-programs/string_refine_preprocess.cpp

Large diffs are not rendered by default.

39 changes: 18 additions & 21 deletions src/solvers/refinement/string_constraint_generator_valueof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,42 +228,39 @@ string_exprt string_constraint_generatort::add_axioms_from_bool(
const exprt &b, const refined_string_typet &ref_type)
{
string_exprt res=fresh_string(ref_type);
const typet &index_type=ref_type.get_index_type();
const typet &char_type=ref_type.get_char_type();

assert(b.type()==bool_typet() || b.type().id()==ID_c_bool);

typecast_exprt eq(b, bool_typet());

string_exprt true_string=add_axioms_for_constant("true", ref_type);
string_exprt false_string=add_axioms_for_constant("false", ref_type);

// We add axioms:
// a1 : eq => res = |"true"|
// a2 : forall i < |"true"|. eq => res[i]="true"[i]
// a3 : !eq => res = |"false"|
// a4 : forall i < |"false"|. !eq => res[i]="false"[i]

implies_exprt a1(eq, res.axiom_for_has_same_length_as(true_string));
std::string str_true="true";
implies_exprt a1(eq, res.axiom_for_has_length(str_true.length()));
axioms.push_back(a1);
symbol_exprt qvar=fresh_univ_index("QA_equal_true", index_type);
string_constraintt a2(
qvar,
true_string.length(),
eq,
equal_exprt(res[qvar], true_string[qvar]));
axioms.push_back(a2);

implies_exprt a3(
not_exprt(eq), res.axiom_for_has_same_length_as(false_string));
for(std::size_t i=0; i<str_true.length(); i++)
{
exprt chr=from_integer(str_true[i], char_type);
implies_exprt a2(eq, equal_exprt(res[i], chr));
axioms.push_back(a2);
}

std::string str_false="false";
implies_exprt a3(not_exprt(eq), res.axiom_for_has_length(str_false.length()));
axioms.push_back(a3);

symbol_exprt qvar1=fresh_univ_index("QA_equal_false", index_type);
string_constraintt a4(
qvar,
false_string.length(),
not_exprt(eq),
equal_exprt(res[qvar1], false_string[qvar1]));
axioms.push_back(a4);
for(std::size_t i=0; i<str_false.length(); i++)
{
exprt chr=from_integer(str_false[i], char_type);
implies_exprt a4(not_exprt(eq), equal_exprt(res[i], chr));
axioms.push_back(a4);
}

return res;
}
Expand Down