blob: b5adb31f22c90ecd9f3180414e828aa22af84ecf [file] [log] [blame]
Chris Lattner3b427b32007-10-11 00:18:28 +00001// RUN: clang -fsyntax-only -verify %s
Chris Lattnerd3fb6ad2007-08-30 17:51:09 +00002
3#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
4
5typedef struct P { int i; float f; } PT;
6struct external_sun3_core
7{
8 unsigned c_regs;
9
10 PT X[100];
11
12};
13
14void swap()
15{
16 int x;
17 x = offsetof(struct external_sun3_core, c_regs);
18 x = __builtin_offsetof(struct external_sun3_core, X[42].f);
19
20 x = __builtin_offsetof(struct external_sun3_core, X[42].f2); // expected-error {{no member named 'f2'}}
21 x = __builtin_offsetof(int, X[42].f2); // expected-error {{offsetof requires struct}}
Anders Carlsson5a1deb82008-01-29 15:56:48 +000022
23 int a[__builtin_offsetof(struct external_sun3_core, X) == 4 ? 1 : -1];
24 int b[__builtin_offsetof(struct external_sun3_core, X[42]) == 340 ? 1 : -1];
Chris Lattnere0c54142008-01-30 06:46:30 +000025 int c[__builtin_offsetof(struct external_sun3_core, X[42].f2) == 344 ? 1 : -1]; // expected-error {{no member named 'f2'}}
Chris Lattnerd3fb6ad2007-08-30 17:51:09 +000026}
27
Chris Lattnere0c54142008-01-30 06:46:30 +000028
29struct s1 { int a; };
30extern int v1[offsetof (struct s1, a) == 0];
31
32struct s2 { int a; };
33extern int v2[__INTADDR__ (&((struct s2 *) 0)->a) == 0];
34
35struct s3 { int a; };
36extern int v3[__builtin_offsetof(struct s3, a) == 0];