Skip to content

Fix issue test-gen#172 #805

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 1 commit into from
Apr 12, 2017
Merged
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
53 changes: 41 additions & 12 deletions src/solvers/refinement/string_constraint_generator_valueof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,25 +642,35 @@ exprt string_constraint_generatort::add_axioms_for_correct_number_format(
binary_relation_exprt(chr, ID_ge, zero_char),
binary_relation_exprt(chr, ID_le, nine_char));

// TODO: we should have implications in the other direction for correct
// correct => |str| > 0
exprt non_empty=str.axiom_for_is_longer_than(from_integer(1, index_type));
axioms.push_back(implies_exprt(correct, non_empty));

// correct => (str[0] = '+' or '-' || '0' <= str[0] <= '9')
or_exprt correct_first(
or_exprt(starts_with_minus, starts_with_plus), starts_with_digit);
exprt has_first=str.axiom_for_is_longer_than(from_integer(1, index_type));
implies_exprt a1(correct, and_exprt(has_first, correct_first));
axioms.push_back(a1);
axioms.push_back(implies_exprt(correct, correct_first));

exprt not_too_long=str.axiom_for_is_shorter_than(max_size);
axioms.push_back(not_too_long);
// correct => str[0]='+' or '-' ==> |str| > 1
implies_exprt contains_digit(
or_exprt(starts_with_minus, starts_with_plus),
str.axiom_for_is_longer_than(from_integer(2, index_type)));
axioms.push_back(implies_exprt(correct, contains_digit));

symbol_exprt qvar=fresh_univ_index("number_format", index_type);
// correct => |str| < max_size
axioms.push_back(
implies_exprt(correct, str.axiom_for_is_shorter_than(max_size)));

// forall 1 <= qvar < |str| . correct => '0'<= str[qvar] <= '9'
symbol_exprt qvar=fresh_univ_index("number_format", index_type);
and_exprt is_digit(
binary_relation_exprt(str[qvar], ID_ge, zero_char),
binary_relation_exprt(str[qvar], ID_le, nine_char));

string_constraintt a2(
string_constraintt all_digits(
qvar, from_integer(1, index_type), str.length(), correct, is_digit);
axioms.push_back(all_digits);

axioms.push_back(a2);
return correct;
}

Expand Down Expand Up @@ -706,10 +716,29 @@ exprt string_constraint_generatort::add_axioms_for_parse_int(

for(unsigned j=1; j<size; j++)
{
sum=plus_exprt(
mult_exprt(sum, ten),
mult_exprt ten_sum(sum, ten);
if(j>=9)
{
// We have to be careful about overflows
div_exprt div(sum, ten);
equal_exprt no_overflow(div, sum);
axioms.push_back(no_overflow);
}

sum=plus_exprt_with_overflow_check(
ten_sum,
typecast_exprt(minus_exprt(str[j], zero_char), type));
first_value=mult_exprt(first_value, ten);

mult_exprt first(first_value, ten);
if(j>=9)
{
// We have to be careful about overflows
div_exprt div_first(first, ten);
implies_exprt no_overflow_first(
starts_with_digit, equal_exprt(div_first, first_value));
axioms.push_back(no_overflow_first);
}
first_value=first;
}

// If the length is `size`, we add axioms:
Expand Down