Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only |
Steve Naroff | bcb2b61 | 2008-02-29 23:30:25 +0000 | [diff] [blame] | 2 | struct xx { int bitf:1; }; |
| 3 | |
| 4 | struct entry { struct xx *whatever; |
| 5 | int value; |
| 6 | int bitf:1; }; |
Chris Lattner | f82228f | 2007-11-16 17:46:48 +0000 | [diff] [blame] | 7 | void add_one(int *p) { (*p)++; } |
| 8 | |
| 9 | void test() { |
| 10 | register struct entry *p; |
| 11 | add_one(&p->value); |
Steve Naroff | bcb2b61 | 2008-02-29 23:30:25 +0000 | [diff] [blame] | 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}} |
Chris Lattner | f82228f | 2007-11-16 17:46:48 +0000 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | void foo() { |
| 19 | register int x[10]; |
| 20 | &x[10]; // expected-error {{address of register variable requested}} |
Anders Carlsson | 369dee4 | 2008-02-01 07:15:58 +0000 | [diff] [blame] | 21 | |
| 22 | register int *y; |
| 23 | |
| 24 | int *x2 = &y; // expected-error {{address of register variable requested}} |
| 25 | int *x3 = &y[10]; |
Chris Lattner | f82228f | 2007-11-16 17:46:48 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Steve Naroff | bcb2b61 | 2008-02-29 23:30:25 +0000 | [diff] [blame] | 28 | void testVectorComponentAccess() { |
| 29 | typedef float v4sf __attribute__ ((vector_size (16))); |
| 30 | static v4sf q; |
Nate Begeman | b104b1f | 2009-02-15 22:45:20 +0000 | [diff] [blame] | 31 | float* r = &q[0]; // expected-error {{address of vector element requested}} |
Steve Naroff | bcb2b61 | 2008-02-29 23:30:25 +0000 | [diff] [blame] | 32 | } |
Chris Lattner | f82228f | 2007-11-16 17:46:48 +0000 | [diff] [blame] | 33 | |
Nate Begeman | b104b1f | 2009-02-15 22:45:20 +0000 | [diff] [blame] | 34 | typedef __attribute__(( ext_vector_type(4) )) float float4; |
| 35 | |
| 36 | float *testExtVectorComponentAccess(float4 x) { |
| 37 | return &x.w; // expected-error {{address of vector element requested}} |
| 38 | } |
Daniel Dunbar | 1e76ce6 | 2008-08-04 20:02:37 +0000 | [diff] [blame] | 39 | |
| 40 | void f0() { |
| 41 | register int *x0; |
| 42 | int *_dummy0 = &(*x0); |
| 43 | |
| 44 | register int *x1; |
| 45 | int *_dummy1 = &(*(x1 + 1)); |
| 46 | } |
| 47 | |
Eli Friedman | 23d58ce | 2009-04-20 08:23:18 +0000 | [diff] [blame] | 48 | // 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 Dunbar | 1e76ce6 | 2008-08-04 20:02:37 +0000 | [diff] [blame] | 50 | void f1() { |
| 51 | register int x0[10]; |
Eli Friedman | 23d58ce | 2009-04-20 08:23:18 +0000 | [diff] [blame] | 52 | int *_dummy00 = x0; // fixme-error {{address of register variable requested}} |
| 53 | int *_dummy01 = &(*x0); // fixme-error {{address of register variable requested}} |
Daniel Dunbar | 1e76ce6 | 2008-08-04 20:02:37 +0000 | [diff] [blame] | 54 | |
| 55 | register int x1[10]; |
Eli Friedman | 23d58ce | 2009-04-20 08:23:18 +0000 | [diff] [blame] | 56 | int *_dummy1 = &(*(x1 + 1)); // fixme-error {{address of register variable requested}} |
Daniel Dunbar | 1e76ce6 | 2008-08-04 20:02:37 +0000 | [diff] [blame] | 57 | |
| 58 | register int *x2; |
| 59 | int *_dummy2 = &(*(x2 + 1)); |
| 60 | |
| 61 | register int x3[10][10][10]; |
Eli Friedman | 23d58ce | 2009-04-20 08:23:18 +0000 | [diff] [blame] | 62 | int (*_dummy3)[10] = &x3[0][0]; // expected-error {{address of register variable requested}} |
Daniel Dunbar | 1e76ce6 | 2008-08-04 20:02:37 +0000 | [diff] [blame] | 63 | |
| 64 | register struct { int f0[10]; } x4; |
| 65 | int *_dummy4 = &x4.f0[2]; // expected-error {{address of register variable requested}} |
| 66 | } |
| 67 | |
| 68 | void f2() { |
| 69 | register int *y; |
| 70 | |
| 71 | int *_dummy0 = &y; // expected-error {{address of register variable requested}} |
| 72 | int *_dummy1 = &y[10]; |
| 73 | } |
| 74 | |
| 75 | void f3() { |
| 76 | extern void f4(); |
| 77 | void (*_dummy0)() = &****f4; |
| 78 | } |
| 79 | |
| 80 | void f4() { |
| 81 | register _Complex int x; |
| 82 | |
| 83 | int *_dummy0 = &__real__ x; // expected-error {{address of register variable requested}} |
| 84 | } |
| 85 | |
| 86 | void 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 Dunbar | 33ad012 | 2008-09-03 21:54:21 +0000 | [diff] [blame] | 97 | void f6(register int x) { |
| 98 | int * dummy0 = &x; // expected-error {{address of register variable requested}} |
| 99 | } |
Eli Friedman | 23d58ce | 2009-04-20 08:23:18 +0000 | [diff] [blame] | 100 | |
| 101 | char* 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 Collingbourne | 1c860d5 | 2011-04-19 18:51:51 +0000 | [diff] [blame] | 110 | |
| 111 | void 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 | } |