Skip to content

Commit 7ef8430

Browse files
authored
Merge pull request #4998 from smowton/smowton/fix/lhs-string-constant
[TG-8994] Tolerate a constant on the LHS of an assignment
2 parents 30b874c + e98540f commit 7ef8430

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <assert.h>
2+
3+
int main(int argc, char **argv)
4+
{
5+
int x;
6+
const char *c = "Hello world";
7+
8+
int *p = (argc ? &x : (int *)c);
9+
10+
*p = 1;
11+
12+
assert(*p == 1);
13+
14+
return 0;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
This checks that we tolerate an apparent write to a string constant, which of course
10+
can't happen in reality but may appear to happen due to over-approximate alias analysis.

src/goto-symex/goto_symex_state.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,12 @@ class goto_symex_statet final : public goto_statet
247247
/// Returns true if \p lvalue is a read-only object, such as the null object
248248
static bool is_read_only_object(const exprt &lvalue)
249249
{
250+
// Note ID_constant can occur due to a partial write to a string constant,
251+
// (i.e. something like byte_extract int from "hello" offset 2), which
252+
// simplifies to a plain constant.
250253
return lvalue.id() == ID_string_constant || lvalue.id() == ID_null_object ||
251254
lvalue.id() == "zero_string" || lvalue.id() == "is_zero_string" ||
252-
lvalue.id() == "zero_string_length";
255+
lvalue.id() == "zero_string_length" || lvalue.id() == ID_constant;
253256
}
254257

255258
private:

0 commit comments

Comments
 (0)