Skip to content

[TG-8994] Tolerate a constant on the LHS of an assignment #4998

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
Aug 12, 2019
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
15 changes: 15 additions & 0 deletions regression/cbmc/lhs-pointer-aliases-constant/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <assert.h>

int main(int argc, char **argv)
{
int x;
const char *c = "Hello world";

int *p = (argc ? &x : (int *)c);

*p = 1;

assert(*p == 1);

return 0;
}
10 changes: 10 additions & 0 deletions regression/cbmc/lhs-pointer-aliases-constant/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
test.c

^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
--
This checks that we tolerate an apparent write to a string constant, which of course
can't happen in reality but may appear to happen due to over-approximate alias analysis.
5 changes: 4 additions & 1 deletion src/goto-symex/goto_symex_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,12 @@ class goto_symex_statet final : public goto_statet
/// Returns true if \p lvalue is a read-only object, such as the null object
static bool is_read_only_object(const exprt &lvalue)
{
// Note ID_constant can occur due to a partial write to a string constant,
// (i.e. something like byte_extract int from "hello" offset 2), which
// simplifies to a plain constant.
return lvalue.id() == ID_string_constant || lvalue.id() == ID_null_object ||
lvalue.id() == "zero_string" || lvalue.id() == "is_zero_string" ||
lvalue.id() == "zero_string_length";
lvalue.id() == "zero_string_length" || lvalue.id() == ID_constant;
}

private:
Expand Down