Skip to content

CHC solver: use address_of on RHS in counterexample traces #7218

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
Oct 8, 2022
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
2 changes: 1 addition & 1 deletion regression/cprover/trace/trace_malloc1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ trace_malloc1.c
^EXIT=10$
^SIGNAL=0$
^Trace for main\.assertion\.1:$
^ 5 main::\$tmp::return_value_malloc := heap-1$
^ 5 main::\$tmp::return_value_malloc := address_of\(heap-1\)$
^ 5 main::1::p := cast\(❝heap-1❞, signedbv\[32\]\*\)$
^ 7 \[cast\(❝heap-1❞, signedbv\[32\]\*\) \+ 10\] := 1$
^ 8 \[cast\(❝heap-1❞, signedbv\[32\]\*\) \+ 20\] := 2$
Expand Down
2 changes: 1 addition & 1 deletion regression/cprover/trace/trace_pointer2.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ trace_pointer2.c
^EXIT=10$
^SIGNAL=0$
^Trace for main\.assertion\.1:$
^ 6 main::1::x := element_address\(❝main::1::array❞, 0\)$
^ 6 main::1::x := address_of\(main::1::array\[0\]\)$
^ 7 main::1::array\[2\] := 123$
--
2 changes: 1 addition & 1 deletion regression/cprover/trace/trace_pointer3.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ trace_pointer3.c
^EXIT=10$
^SIGNAL=0$
^Trace for main\.assertion\.1:$
^ 8 main::1::p := ❝x❞$
^ 8 main::1::p := address_of\(x\)$
^ 9 x\.b := 123$
--
2 changes: 1 addition & 1 deletion regression/cprover/trace/trace_struct1.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ trace_struct1.c
^EXIT=10$
^SIGNAL=0$
^Trace for main\.assertion\.1:$
^ 10 main::1::p := ❝x❞\.❝c❞$
^ 10 main::1::p := address_of\(x\.c\)$
^ 11 x\.c := 789$
--
21 changes: 17 additions & 4 deletions src/cprover/report_traces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ optionalt<exprt> address_to_lvalue(exprt src)
return {};
}

static exprt use_address_of(exprt src)
{
auto src_lvalue_opt = address_to_lvalue(src);
if(src_lvalue_opt.has_value())
return address_of_exprt(*src_lvalue_opt);
else
return src;
}

void show_trace(
const std::vector<framet> &frames,
const propertyt &property,
Expand Down Expand Up @@ -123,13 +132,17 @@ void show_trace(
consolet::out() << std::setw(4) << ' ';
}

auto lvalue_opt = address_to_lvalue(update.address);
if(lvalue_opt.has_value())
consolet::out() << format(*lvalue_opt);
// use an l-value expression for better readability, if possible
auto lhs_lvalue_opt = address_to_lvalue(update.address);
if(lhs_lvalue_opt.has_value())
consolet::out() << format(*lhs_lvalue_opt);
else
consolet::out() << '[' << format(update.address) << ']';

consolet::out() << " := " << format(update.value);
// use address_of for better readability
auto value_with_address_of = use_address_of(update.value);

consolet::out() << " := " << format(value_with_address_of);
consolet::out() << '\n';
}
}
Expand Down