File tree 2 files changed +84
-0
lines changed
regression/cbmc/full_slice3
2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stddef.h>
3
+
4
+ // from linux/kernel.h
5
+ #ifndef container_of
6
+ #define container_of (ptr , type , member ) ({ \
7
+ const typeof(((type *) 0)->member) *__mptr = (ptr); \
8
+ (type *) ((char *) __mptr - offsetof(type, member));})
9
+ #endif
10
+
11
+ struct NetClientState {
12
+ int dummy ;
13
+ /* ... */
14
+ };
15
+
16
+ struct NICState {
17
+ struct NetClientState nc ;
18
+ struct NetClientState nc2 ;
19
+ void * opaque ;
20
+ /* ... */
21
+ };
22
+
23
+ typedef int OpenEthState ;
24
+
25
+ #define OPEN_ETH_STATE (a ) \
26
+ ((OpenEthState *) container_of(a, struct NICState, nc)->opaque)
27
+
28
+ #define OPEN_ETH_STATE2 (a ) \
29
+ ((OpenEthState *) container_of(a, struct NICState, nc2)->opaque)
30
+
31
+ static struct NetClientState * nc ;
32
+
33
+ int main ()
34
+ {
35
+ int x = 42 ;
36
+
37
+ struct NICState nic ;
38
+ #ifndef __GNUC__
39
+ int * xptr = 0 , * xptr2 = 0 ;
40
+ const struct NetClientState * __mptr1 = 0 , * __mptr2 = 0 ;
41
+ #endif
42
+ nic .opaque = & x ;
43
+ nc = & (nic .nc );
44
+
45
+ assert (x == 42 );
46
+ assert (* ((int * )nic .opaque ) == 42 );
47
+
48
+ #ifdef __GNUC__
49
+ int * xptr = OPEN_ETH_STATE (nc );
50
+ #else
51
+ __mptr1 = nc ;
52
+ xptr = (OpenEthState * )
53
+ ((struct NICState * )
54
+ ((char * ) __mptr1 - offsetof(struct NICState , nc )))-> opaque ;
55
+ #endif
56
+ assert (xptr == & x );
57
+ assert (* xptr == 42 );
58
+
59
+ nc = & (nic .nc2 );
60
+
61
+ #ifdef __GNUC__
62
+ int * xptr2 = OPEN_ETH_STATE2 (nc );
63
+ #else
64
+ __mptr2 = nc ;
65
+ xptr2 = (OpenEthState * )
66
+ ((struct NICState * )
67
+ ((char * ) __mptr2 - offsetof(struct NICState , nc2 )))-> opaque ;
68
+ #endif
69
+ assert (xptr2 == & x );
70
+ assert (* xptr2 == 42 );
71
+
72
+ return 0 ;
73
+ }
Original file line number Diff line number Diff line change
1
+ KNOWNBUG
2
+ main.c
3
+ --full-slice
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ ^warning: ignoring
9
+ ^CONVERSION ERROR$
10
+ --
11
+ Issue #2524
You can’t perform that action at this time.
0 commit comments