1 // RUN: %clang_cc1 %s -fsyntax-only -verify 2 3 #define _AS1 __attribute__((address_space(1))) 4 #define _AS2 __attribute__((address_space(2))) 5 #define _AS3 __attribute__((address_space(3))) 6 7 void bar(_AS2 int a); // expected-error {{parameter may not be qualified with an address space}} 8 foo(_AS3 float * a,_AS1 float b)9void foo(_AS3 float *a, 10 _AS1 float b) // expected-error {{parameter may not be qualified with an address space}} 11 { 12 _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}} 13 _AS1 float * _AS2 *B; 14 15 int _AS1 _AS2 *Y; // expected-error {{multiple address spaces specified for type}} 16 int *_AS1 _AS2 *Z; // expected-error {{multiple address spaces specified for type}} 17 18 _AS1 int local; // expected-error {{automatic variable qualified with an address space}} 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}} 21 22 __attribute__((address_space(-1))) int *_boundsA; // expected-error {{address space is negative}} 23 __attribute__((address_space(0x7FFFFF))) 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 28 *a = 5.0f + b; 29 } 30 31 struct _st { 32 int x, y; 33 } s __attribute ((address_space(1))) = {1, 1}; 34 35 36 // rdar://6774906 37 __attribute__((address_space(256))) void * * const base = 0; get_0(void)38void * get_0(void) { 39 return base[0]; // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}} 40 } 41 42 __attribute__((address_space(1))) char test3_array[10]; test3(void)43void 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 } 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}} 51 52 53 typedef _AS2 int AS2Int; 54 55 struct HasASFields 56 { 57 _AS2 int as_field; // expected-error {{field may not be qualified with an address space}} 58 AS2Int typedef_as_field; // expected-error {{field may not be qualified with an address space}} 59 }; 60 61 // Assertion failure was when the field was accessed access_as_field()62void access_as_field() 63 { 64 struct HasASFields x; 65 (void) bar.as_field; 66 } 67 68 typedef int PR4997 __attribute__((address_space(Foobar))); // expected-error {{use of undeclared identifier 'Foobar'}} 69 __attribute__((address_space("12"))) int *i; // expected-error {{'address_space' attribute requires an integer constant}} 70 71 // Clang extension doesn't forbid operations on pointers to different address spaces. cmp(_AS1 char * x,_AS2 char * y)72char* cmp(_AS1 char *x, _AS2 char *y) { 73 return x < y ? x : y; // expected-warning {{pointer type mismatch ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *')}} 74 } 75