68 lines · c
1// RUN: %clang_cc1 %s -fsyntax-only -verify2 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))) char10 11void normal_case(void) {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 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];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 26char AS2 *test4_array;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 32void func(void) {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 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 46void override_macro_name(void) {47#define ATTRS __attribute__((noderef)) // expected-note{{previous definition is here}}48 ATTRS49#define ATTRS __attribute__((address_space(1))) // expected-warning{{'ATTRS' macro redefined}}50 ATTRS51 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 56void partial_macro_declaration(void) {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