[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / expr-address-of.c
blob8881038b3241cec6e5af588269db6004250c8c7b
1 // RUN: %clang_cc1 %s -verify -fsyntax-only -Wno-strict-prototypes
2 struct xx { int bitf:1; };
4 struct entry { struct xx *whatever;
5 int value;
6 int bitf:1; };
7 void add_one(int *p) { (*p)++; }
9 void test(void) {
10 register struct entry *p;
11 add_one(&p->value);
12 struct entry pvalue;
13 add_one(&p->bitf); // expected-error {{address of bit-field requested}}
14 add_one(&pvalue.bitf); // expected-error {{address of bit-field requested}}
15 add_one(&p->whatever->bitf); // expected-error {{address of bit-field requested}}
18 void foo(void) {
19 register int x[10];
20 &x[10]; // expected-error {{address of register variable requested}}
22 register int *y;
24 int *x2 = &y; // expected-error {{address of register variable requested}}
25 int *x3 = &y[10];
28 void testVectorComponentAccess(void) {
29 typedef float v4sf __attribute__ ((vector_size (16)));
30 static v4sf q;
31 float* r = &q[0]; // expected-error {{address of vector element requested}}
34 typedef __attribute__(( ext_vector_type(4) )) float float4;
36 float *testExtVectorComponentAccess(float4 x) {
37 return &x.w; // expected-error {{address of vector element requested}}
40 void f0(void) {
41 register int *x0;
42 int *_dummy0 = &(*x0);
44 register int *x1;
45 int *_dummy1 = &(*(x1 + 1));
48 void f1(void) {
49 register int x0[10];
50 int *_dummy00 = x0; // expected-error {{address of register variable requested}}
51 int *_dummy01 = &(*x0); // expected-error {{address of register variable requested}}
53 register int x1[10];
54 int *_dummy1 = &(*(x1 + 1)); // expected-error {{address of register variable requested}}
56 register int *x2;
57 int *_dummy2 = &(*(x2 + 1));
59 register int x3[10][10][10];
60 int(*_dummy3)[10] = &x3[0][0]; // expected-error {{address of register variable requested}}
62 register struct { int f0[10]; } x4;
63 int *_dummy4 = &x4.f0[2]; // expected-error {{address of register variable requested}}
65 add_one(x0); // expected-error {{address of register variable requested}}
66 (void)sizeof(x0); // OK, not an array decay.
68 int *p = ((int *)x0)++; // expected-error {{address of register variable requested}}
71 void f2(void) {
72 register int *y;
74 int *_dummy0 = &y; // expected-error {{address of register variable requested}}
75 int *_dummy1 = &y[10];
78 void f3(void) {
79 extern void f4(void);
80 void (*_dummy0)(void) = &****f4;
83 void f4(void) {
84 register _Complex int x;
86 int *_dummy0 = &__real__ x; // expected-error {{address of register variable requested}}
89 void f5(void) {
90 register int arr[2];
92 int *_dummy0 = &(int*) arr; // expected-error {{address of register variable requested}}
93 int *_dummy1 = &(arr + 1); // expected-error {{address of register variable requested}}
96 void f6(register int x) {
97 int * dummy0 = &x; // expected-error {{address of register variable requested}}
100 char* f7(void) {
101 register struct {char* x;} t1 = {"Hello"};
102 char* dummy1 = &(t1.x[0]);
104 struct {int a : 10; struct{int b : 10;};} t2;
105 int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
106 int* dummy3 = &(t2.b); // expected-error {{address of bit-field requested}}
108 void* t3 = &(*(void*)0);
111 void f8(void) {
112 void *dummy0 = &f8(); // expected-error {{cannot take the address of an rvalue of type 'void'}}
114 extern void v;
115 void *dummy1 = &(1 ? v : f8()); // expected-error {{cannot take the address of an rvalue of type 'void'}}
117 void *dummy2 = &(f8(), v); // expected-error {{cannot take the address of an rvalue of type 'void'}}
119 void *dummy3 = &({ ; }); // expected-error {{cannot take the address of an rvalue of type 'void'}}
122 void f9(void) {
123 extern void knr();
124 void (*_dummy0)() = &****knr;