annotate clang/test/Sema/expr-address-of.c @ 207:2e18cbf3894f

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