1 // RUN: %clang_cc1 %s -fsyntax-only -verify 2 3 #define AS1 __attribute__((address_space(1))) 4 #define AS2 __attribute__((address_space(2), annotate("foo"))) 5 #define AS_ND __attribute__((address_space(2), noderef)) 6 7 #define AS(i) address_space(i) 8 #define AS3 __attribute__((AS(3))) 9 #define AS5 __attribute__((address_space(5))) char 10 normal_case()11void normal_case() { 12 int *p = 0; 13 __attribute__((address_space(1))) int *q = p; // expected-error{{initializing '__attribute__((address_space(1))) int *' with an expression of type 'int *' changes address space of pointer}} 14 } 15 cmp(AS1 char * x,AS2 char * y)16char *cmp(AS1 char *x, AS2 char *y) { 17 return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type ('AS1 char *' and 'AS2 char *') which are pointers to non-overlapping address spaces}} 18 } 19 20 __attribute__((address_space(1))) char test_array[10]; test3(void)21void test3(void) { 22 extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}} 23 test3_helper(test_array); // expected-error{{passing '__attribute__((address_space(1))) char *' to parameter of type 'char *' changes address space of pointer}} 24 } 25 26 char AS2 *test4_array; test4(void)27void test4(void) { 28 extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}} 29 test3_helper(test4_array); // expected-error{{passing 'AS2 char *' to parameter of type 'char *' changes address space of pointer}} 30 } 31 func()32void func() { 33 char AS1 *x; 34 char AS3 *x2; 35 AS5 *x3; 36 char *y; 37 y = x; // expected-error{{assigning 'AS1 char *' to 'char *' changes address space of pointer}} 38 y = x2; // expected-error{{assigning 'AS3 char *' to 'char *' changes address space of pointer}} 39 y = x3; // expected-error{{assigning '__attribute__((address_space(5))) char *' to 'char *' changes address space of pointer}} 40 } 41 multiple_attrs(AS_ND int * x)42void multiple_attrs(AS_ND int *x) { 43 __attribute__((address_space(2))) int *y = x; // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}} 44 } 45 override_macro_name()46void override_macro_name() { 47 #define ATTRS __attribute__((noderef)) // expected-note{{previous definition is here}} 48 ATTRS 49 #define ATTRS __attribute__((address_space(1))) // expected-warning{{'ATTRS' macro redefined}} 50 ATTRS 51 int *x; 52 53 int AS_ND *y = x; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS int *' changes address space of pointer}} 54 } 55 partial_macro_declaration()56void partial_macro_declaration() { 57 #define ATTRS2 __attribute__((noderef)) 58 ATTRS2 __attribute__((address_space(1))) int *x; 59 60 int AS_ND *y = x; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS2 int __attribute__((address_space(1))) *' changes address space of pointer}} 61 62 // The attribute not wrapped with a macro should be printed regularly. 63 #define ATTRS3 __attribute__((address_space(1))) 64 ATTRS3 __attribute__((noderef)) int *x2; 65 66 int AS_ND *y2 = x2; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS3 int * __attribute__((noderef))' changes address space of pointer}} 67 } 68