xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/expr-address-of.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -verify -fsyntax-only
2*f4a2713aSLionel Sambuc struct xx { int bitf:1; };
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc struct entry { struct xx *whatever;
5*f4a2713aSLionel Sambuc                int value;
6*f4a2713aSLionel Sambuc                int bitf:1; };
add_one(int * p)7*f4a2713aSLionel Sambuc void add_one(int *p) { (*p)++; }
8*f4a2713aSLionel Sambuc 
test()9*f4a2713aSLionel Sambuc void test() {
10*f4a2713aSLionel Sambuc  register struct entry *p;
11*f4a2713aSLionel Sambuc  add_one(&p->value);
12*f4a2713aSLionel Sambuc  struct entry pvalue;
13*f4a2713aSLionel Sambuc  add_one(&p->bitf);  // expected-error {{address of bit-field requested}}
14*f4a2713aSLionel Sambuc  add_one(&pvalue.bitf); // expected-error {{address of bit-field requested}}
15*f4a2713aSLionel Sambuc  add_one(&p->whatever->bitf); // expected-error {{address of bit-field requested}}
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
foo()18*f4a2713aSLionel Sambuc void foo() {
19*f4a2713aSLionel Sambuc   register int x[10];
20*f4a2713aSLionel Sambuc   &x[10];              // expected-error {{address of register variable requested}}
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc   register int *y;
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc   int *x2 = &y; // expected-error {{address of register variable requested}}
25*f4a2713aSLionel Sambuc   int *x3 = &y[10];
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
testVectorComponentAccess()28*f4a2713aSLionel Sambuc void testVectorComponentAccess() {
29*f4a2713aSLionel Sambuc   typedef float v4sf __attribute__ ((vector_size (16)));
30*f4a2713aSLionel Sambuc   static v4sf q;
31*f4a2713aSLionel Sambuc   float* r = &q[0]; // expected-error {{address of vector element requested}}
32*f4a2713aSLionel Sambuc }
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc typedef __attribute__(( ext_vector_type(4) ))  float float4;
35*f4a2713aSLionel Sambuc 
testExtVectorComponentAccess(float4 x)36*f4a2713aSLionel Sambuc float *testExtVectorComponentAccess(float4 x) {
37*f4a2713aSLionel Sambuc   return &x.w; // expected-error {{address of vector element requested}}
38*f4a2713aSLionel Sambuc }
39*f4a2713aSLionel Sambuc 
f0()40*f4a2713aSLionel Sambuc void f0() {
41*f4a2713aSLionel Sambuc   register int *x0;
42*f4a2713aSLionel Sambuc   int *_dummy0 = &(*x0);
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc   register int *x1;
45*f4a2713aSLionel Sambuc   int *_dummy1 = &(*(x1 + 1));
46*f4a2713aSLionel Sambuc }
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc // FIXME: The checks for this function are broken; we should error
49*f4a2713aSLionel Sambuc // on promoting a register array to a pointer! (C99 6.3.2.1p3)
f1()50*f4a2713aSLionel Sambuc void f1() {
51*f4a2713aSLionel Sambuc   register int x0[10];
52*f4a2713aSLionel Sambuc   int *_dummy00 = x0; // fixme-error {{address of register variable requested}}
53*f4a2713aSLionel Sambuc   int *_dummy01 = &(*x0); // fixme-error {{address of register variable requested}}
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc   register int x1[10];
56*f4a2713aSLionel Sambuc   int *_dummy1 = &(*(x1 + 1)); // fixme-error {{address of register variable requested}}
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc   register int *x2;
59*f4a2713aSLionel Sambuc   int *_dummy2 = &(*(x2 + 1));
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc   register int x3[10][10][10];
62*f4a2713aSLionel Sambuc   int (*_dummy3)[10] = &x3[0][0]; // expected-error {{address of register variable requested}}
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc   register struct { int f0[10]; } x4;
65*f4a2713aSLionel Sambuc   int *_dummy4 = &x4.f0[2]; // expected-error {{address of register variable requested}}
66*f4a2713aSLionel Sambuc }
67*f4a2713aSLionel Sambuc 
f2()68*f4a2713aSLionel Sambuc void f2() {
69*f4a2713aSLionel Sambuc   register int *y;
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc   int *_dummy0 = &y; // expected-error {{address of register variable requested}}
72*f4a2713aSLionel Sambuc   int *_dummy1 = &y[10];
73*f4a2713aSLionel Sambuc }
74*f4a2713aSLionel Sambuc 
f3()75*f4a2713aSLionel Sambuc void f3() {
76*f4a2713aSLionel Sambuc   extern void f4();
77*f4a2713aSLionel Sambuc   void (*_dummy0)() = &****f4;
78*f4a2713aSLionel Sambuc }
79*f4a2713aSLionel Sambuc 
f4()80*f4a2713aSLionel Sambuc void f4() {
81*f4a2713aSLionel Sambuc   register _Complex int x;
82*f4a2713aSLionel Sambuc 
83*f4a2713aSLionel Sambuc   int *_dummy0 = &__real__ x; // expected-error {{address of register variable requested}}
84*f4a2713aSLionel Sambuc }
85*f4a2713aSLionel Sambuc 
f5()86*f4a2713aSLionel Sambuc void f5() {
87*f4a2713aSLionel Sambuc   register int arr[2];
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc   /* This is just here because if we happened to support this as an
90*f4a2713aSLionel Sambuc      lvalue we would need to give a warning. Note that gcc warns about
91*f4a2713aSLionel Sambuc      this as a register before it warns about it as an invalid
92*f4a2713aSLionel Sambuc      lvalue. */
93*f4a2713aSLionel Sambuc   int *_dummy0 = &(int*) arr; // expected-error {{cannot take the address of an rvalue}}
94*f4a2713aSLionel Sambuc   int *_dummy1 = &(arr + 1); // expected-error {{cannot take the address of an rvalue}}
95*f4a2713aSLionel Sambuc }
96*f4a2713aSLionel Sambuc 
f6(register int x)97*f4a2713aSLionel Sambuc void f6(register int x) {
98*f4a2713aSLionel Sambuc   int * dummy0 = &x; // expected-error {{address of register variable requested}}
99*f4a2713aSLionel Sambuc }
100*f4a2713aSLionel Sambuc 
f7()101*f4a2713aSLionel Sambuc char* f7() {
102*f4a2713aSLionel Sambuc   register struct {char* x;} t1 = {"Hello"};
103*f4a2713aSLionel Sambuc   char* dummy1 = &(t1.x[0]);
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc   struct {int a : 10;} t2;
106*f4a2713aSLionel Sambuc   int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
107*f4a2713aSLionel Sambuc 
108*f4a2713aSLionel Sambuc   void* t3 = &(*(void*)0);
109*f4a2713aSLionel Sambuc }
110*f4a2713aSLionel Sambuc 
f8()111*f4a2713aSLionel Sambuc void f8() {
112*f4a2713aSLionel Sambuc   void *dummy0 = &f8(); // expected-error {{cannot take the address of an rvalue of type 'void'}}
113*f4a2713aSLionel Sambuc 
114*f4a2713aSLionel Sambuc   extern void v;
115*f4a2713aSLionel Sambuc   void *dummy1 = &(1 ? v : f8()); // expected-error {{cannot take the address of an rvalue of type 'void'}}
116*f4a2713aSLionel Sambuc 
117*f4a2713aSLionel Sambuc   void *dummy2 = &(f8(), v); // expected-error {{cannot take the address of an rvalue of type 'void'}}
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc   void *dummy3 = &({ ; }); // expected-error {{cannot take the address of an rvalue of type 'void'}}
120*f4a2713aSLionel Sambuc }
121