Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fsyntax-only -verify |
Chris Lattner | 7380466 | 2008-02-21 01:42:41 +0000 | [diff] [blame] | 2 | |
| 3 | #define _AS1 __attribute__((address_space(1))) |
| 4 | #define _AS2 __attribute__((address_space(2))) |
| 5 | #define _AS3 __attribute__((address_space(3))) |
| 6 | |
Tanya Lattner | 27a84d0 | 2009-09-30 20:47:43 +0000 | [diff] [blame] | 7 | void bar(_AS2 int a); // expected-error {{parameter may not be qualified with an address space}} |
| 8 | |
| 9 | void foo(_AS3 float *a, |
| 10 | _AS1 float b) // expected-error {{parameter may not be qualified with an address space}} |
| 11 | { |
Chris Lattner | 35d276f | 2009-02-27 18:53:28 +0000 | [diff] [blame] | 12 | _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}} |
Chris Lattner | 7380466 | 2008-02-21 01:42:41 +0000 | [diff] [blame] | 13 | _AS1 float * _AS2 *B; |
| 14 | |
Nate Begeman | c8e89a8 | 2008-03-14 18:07:10 +0000 | [diff] [blame] | 15 | int _AS1 _AS2 *Y; // expected-error {{multiple address spaces specified for type}} |
Chris Lattner | 7380466 | 2008-02-21 01:42:41 +0000 | [diff] [blame] | 16 | int *_AS1 _AS2 *Z; // expected-error {{multiple address spaces specified for type}} |
| 17 | |
Nate Begeman | c8e89a8 | 2008-03-14 18:07:10 +0000 | [diff] [blame] | 18 | _AS1 int local; // expected-error {{automatic variable qualified with an address space}} |
Nate Begeman | 8e7dafe | 2008-03-25 18:36:32 +0000 | [diff] [blame] | 19 | _AS1 int array[5]; // expected-error {{automatic variable qualified with an address space}} |
| 20 | _AS1 int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}} |
Nate Begeman | 5af27e0 | 2008-03-14 00:22:18 +0000 | [diff] [blame] | 21 | |
John McCall | efadb77 | 2009-07-28 06:52:18 +0000 | [diff] [blame] | 22 | __attribute__((address_space(-1))) int *_boundsA; // expected-error {{address space is negative}} |
| 23 | __attribute__((address_space(0xFFFFFF))) int *_boundsB; |
| 24 | __attribute__((address_space(0x1000000))) int *_boundsC; // expected-error {{address space is larger than the maximum supported}} |
| 25 | // chosen specifically to overflow 32 bits and come out reasonable |
| 26 | __attribute__((address_space(4294967500))) int *_boundsD; // expected-error {{address space is larger than the maximum supported}} |
| 27 | |
Tanya Lattner | 27a84d0 | 2009-09-30 20:47:43 +0000 | [diff] [blame] | 28 | *a = 5.0f + b; |
Chris Lattner | 7380466 | 2008-02-21 01:42:41 +0000 | [diff] [blame] | 29 | } |
Chris Lattner | 863ea9a | 2009-01-12 00:08:58 +0000 | [diff] [blame] | 30 | |
| 31 | struct _st { |
| 32 | int x, y; |
| 33 | } s __attribute ((address_space(1))) = {1, 1}; |
| 34 | |
Chris Lattner | ecca753 | 2009-04-13 06:04:39 +0000 | [diff] [blame] | 35 | |
| 36 | // rdar://6774906 |
| 37 | __attribute__((address_space(256))) void * * const base = 0; |
| 38 | void * get_0(void) { |
John McCall | 86c05f3 | 2011-02-01 00:10:29 +0000 | [diff] [blame] | 39 | return base[0]; // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}} |
Chris Lattner | ecca753 | 2009-04-13 06:04:39 +0000 | [diff] [blame] | 40 | } |
| 41 | |
John McCall | 40249e7 | 2011-02-01 23:28:01 +0000 | [diff] [blame] | 42 | __attribute__((address_space(1))) char test3_array[10]; |
| 43 | void test3(void) { |
| 44 | extern void test3_helper(char *p); // expected-note {{passing argument to parameter 'p' here}} |
| 45 | test3_helper(test3_array); // expected-error {{changes address space of pointer}} |
| 46 | } |
Peter Collingbourne | 020972d | 2011-07-27 20:30:05 +0000 | [diff] [blame] | 47 | |
| 48 | typedef void ft(void); |
| 49 | _AS1 ft qf; // expected-error {{function type may not be qualified with an address space}} |
| 50 | typedef _AS1 ft qft; // expected-error {{function type may not be qualified with an address space}} |