File tree 3 files changed +29
-1
lines changed
regression/cbmc/lhs-pointer-aliases-constant
3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change @@ -247,9 +247,12 @@ class goto_symex_statet final : public goto_statet
247
247
// / Returns true if \p lvalue is a read-only object, such as the null object
248
248
static bool is_read_only_object (const exprt &lvalue)
249
249
{
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.
250
253
return lvalue.id () == ID_string_constant || lvalue.id () == ID_null_object ||
251
254
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 ;
253
256
}
254
257
255
258
private:
You can’t perform that action at this time.
0 commit comments