File tree Expand file tree Collapse file tree 4 files changed +67
-0
lines changed Expand file tree Collapse file tree 4 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ #pragma pack(push, 1)
4
+ struct S
5
+ {
6
+ int a [2 ];
7
+ int x ;
8
+ };
9
+ #pragma pack(pop)
10
+
11
+ #ifdef _MSC_VER
12
+ # define _Static_assert (x , m ) static_assert(x, m)
13
+ #endif
14
+
15
+ int main ()
16
+ {
17
+ int A [3 ];
18
+ _Static_assert (sizeof (A ) == sizeof (struct S ), "" );
19
+ struct S * s = A ;
20
+ s -> a [2 ] = 42 ;
21
+ assert (* ((int * )s + 2 ) == 42 );
22
+ assert (s -> x == 42 );
23
+ assert (A [2 ] == 42 );
24
+ }
Original file line number Diff line number Diff line change
1
+ KNOWNBUG
2
+ main.c
3
+ --no-simplify
4
+ ^VERIFICATION SUCCESSFUL$
5
+ ^EXIT=0$
6
+ ^SIGNAL=0$
7
+ --
8
+ ^warning: ignoring
9
+ --
10
+ This test passes when using the simplifier, but results in "WITH" expressions
11
+ that update elements outside their bounds without the simplifier.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ #pragma pack(push, 1)
4
+ struct SU
5
+ {
6
+ union {
7
+ int a [2 ];
8
+ } u ;
9
+ int x ;
10
+ };
11
+ #pragma pack(pop)
12
+
13
+ int main ()
14
+ {
15
+ struct SU su ;
16
+ su .u .a [2 ] = 42 ;
17
+ assert (* ((int * )& su + 2 ) == 42 );
18
+ assert (su .x == 42 );
19
+ }
Original file line number Diff line number Diff line change
1
+ KNOWNBUG
2
+ main.c
3
+
4
+ ^VERIFICATION SUCCESSFUL$
5
+ ^EXIT=0$
6
+ ^SIGNAL=0$
7
+ --
8
+ ^warning: ignoring
9
+ --
10
+ Field sensitivity makes it (currently) impossible to update bytes outside the
11
+ particular field. One possible way to address this is rewriting subscripted
12
+ array accesses to pointer dereferencing, as the C standard describes. Here, this
13
+ would amount to using *(&su.u.a[0] + 2) instead of su.u.a[2].
You can’t perform that action at this time.
0 commit comments