blob: 2b8cfbfa68f59cf8c9b4b046da3a53f90f30ee48 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -verify -fsyntax-only
Steve Naroffbcb2b612008-02-29 23:30:25 +00002struct xx { int bitf:1; };
3
4struct entry { struct xx *whatever;
5 int value;
6 int bitf:1; };
Chris Lattnerf82228f2007-11-16 17:46:48 +00007void add_one(int *p) { (*p)++; }
8
9void test() {
10 register struct entry *p;
11 add_one(&p->value);
Steve Naroffbcb2b612008-02-29 23:30:25 +000012 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}}
Chris Lattnerf82228f2007-11-16 17:46:48 +000016}
17
18void foo() {
19 register int x[10];
20 &x[10]; // expected-error {{address of register variable requested}}
Anders Carlsson369dee42008-02-01 07:15:58 +000021
22 register int *y;
23
24 int *x2 = &y; // expected-error {{address of register variable requested}}
25 int *x3 = &y[10];
Chris Lattnerf82228f2007-11-16 17:46:48 +000026}
27
Steve Naroffbcb2b612008-02-29 23:30:25 +000028void testVectorComponentAccess() {
29 typedef float v4sf __attribute__ ((vector_size (16)));
30 static v4sf q;
Nate Begemanb104b1f2009-02-15 22:45:20 +000031 float* r = &q[0]; // expected-error {{address of vector element requested}}
Steve Naroffbcb2b612008-02-29 23:30:25 +000032}
Chris Lattnerf82228f2007-11-16 17:46:48 +000033
Nate Begemanb104b1f2009-02-15 22:45:20 +000034typedef __attribute__(( ext_vector_type(4) )) float float4;
35
36float *testExtVectorComponentAccess(float4 x) {
37 return &x.w; // expected-error {{address of vector element requested}}
38}
Daniel Dunbar1e76ce62008-08-04 20:02:37 +000039
40void f0() {
41 register int *x0;
42 int *_dummy0 = &(*x0);
43
44 register int *x1;
45 int *_dummy1 = &(*(x1 + 1));
46}
47
Eli Friedman23d58ce2009-04-20 08:23:18 +000048// FIXME: The checks for this function are broken; we should error
49// on promoting a register array to a pointer! (C99 6.3.2.1p3)
Daniel Dunbar1e76ce62008-08-04 20:02:37 +000050void f1() {
51 register int x0[10];
Eli Friedman23d58ce2009-04-20 08:23:18 +000052 int *_dummy00 = x0; // fixme-error {{address of register variable requested}}
53 int *_dummy01 = &(*x0); // fixme-error {{address of register variable requested}}
Daniel Dunbar1e76ce62008-08-04 20:02:37 +000054
55 register int x1[10];
Eli Friedman23d58ce2009-04-20 08:23:18 +000056 int *_dummy1 = &(*(x1 + 1)); // fixme-error {{address of register variable requested}}
Daniel Dunbar1e76ce62008-08-04 20:02:37 +000057
58 register int *x2;
59 int *_dummy2 = &(*(x2 + 1));
60
61 register int x3[10][10][10];
Eli Friedman23d58ce2009-04-20 08:23:18 +000062 int (*_dummy3)[10] = &x3[0][0]; // expected-error {{address of register variable requested}}
Daniel Dunbar1e76ce62008-08-04 20:02:37 +000063
64 register struct { int f0[10]; } x4;
65 int *_dummy4 = &x4.f0[2]; // expected-error {{address of register variable requested}}
66}
67
68void f2() {
69 register int *y;
70
71 int *_dummy0 = &y; // expected-error {{address of register variable requested}}
72 int *_dummy1 = &y[10];
73}
74
75void f3() {
76 extern void f4();
77 void (*_dummy0)() = &****f4;
78}
79
80void f4() {
81 register _Complex int x;
82
83 int *_dummy0 = &__real__ x; // expected-error {{address of register variable requested}}
84}
85
86void f5() {
87 register int arr[2];
88
89 /* This is just here because if we happened to support this as an
90 lvalue we would need to give a warning. Note that gcc warns about
91 this as a register before it warns about it as an invalid
92 lvalue. */
93 int *_dummy0 = &(int*) arr; // expected-error {{address expression must be an lvalue or a function designator}}
94 int *_dummy1 = &(arr + 1); // expected-error {{address expression must be an lvalue or a function designator}}
95}
96
Daniel Dunbar33ad0122008-09-03 21:54:21 +000097void f6(register int x) {
98 int * dummy0 = &x; // expected-error {{address of register variable requested}}
99}
Eli Friedman23d58ce2009-04-20 08:23:18 +0000100
101char* f7() {
102 register struct {char* x;} t1 = {"Hello"};
103 char* dummy1 = &(t1.x[0]);
104
105 struct {int a : 10;} t2;
106 int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
107
108 void* t3 = &(*(void*)0);
109}
Peter Collingbourne1c860d52011-04-19 18:51:51 +0000110
111void f8() {
112 void *dummy0 = &f8(); // expected-error {{address expression must be an lvalue or a function designator}}
113
114 extern void v;
115 void *dummy1 = &(1 ? v : f8()); // expected-error {{address expression must be an lvalue or a function designator}}
116
117 void *dummy2 = &(f8(), v); // expected-error {{address expression must be an lvalue or a function designator}}
118
119 void *dummy3 = &({ ; }); // expected-error {{address expression must be an lvalue or a function designator}}
120}