xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/address_spaces.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -verify
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc #define _AS1 __attribute__((address_space(1)))
4*f4a2713aSLionel Sambuc #define _AS2 __attribute__((address_space(2)))
5*f4a2713aSLionel Sambuc #define _AS3 __attribute__((address_space(3)))
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc void bar(_AS2 int a); // expected-error {{parameter may not be qualified with an address space}}
8*f4a2713aSLionel Sambuc 
foo(_AS3 float * a,_AS1 float b)9*f4a2713aSLionel Sambuc void foo(_AS3 float *a,
10*f4a2713aSLionel Sambuc          _AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
11*f4a2713aSLionel Sambuc {
12*f4a2713aSLionel Sambuc   _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
13*f4a2713aSLionel Sambuc   _AS1 float * _AS2 *B;
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc   int _AS1 _AS2 *Y;   // expected-error {{multiple address spaces specified for type}}
16*f4a2713aSLionel Sambuc   int *_AS1 _AS2 *Z;  // expected-error {{multiple address spaces specified for type}}
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc   _AS1 int local;     // expected-error {{automatic variable qualified with an address space}}
19*f4a2713aSLionel Sambuc   _AS1 int array[5];  // expected-error {{automatic variable qualified with an address space}}
20*f4a2713aSLionel Sambuc   _AS1 int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}}
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc   __attribute__((address_space(-1))) int *_boundsA; // expected-error {{address space is negative}}
23*f4a2713aSLionel Sambuc   __attribute__((address_space(0xFFFFFF))) int *_boundsB;
24*f4a2713aSLionel Sambuc   __attribute__((address_space(0x1000000))) int *_boundsC; // expected-error {{address space is larger than the maximum supported}}
25*f4a2713aSLionel Sambuc   // chosen specifically to overflow 32 bits and come out reasonable
26*f4a2713aSLionel Sambuc   __attribute__((address_space(4294967500))) int *_boundsD; // expected-error {{address space is larger than the maximum supported}}
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc   *a = 5.0f + b;
29*f4a2713aSLionel Sambuc }
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc struct _st {
32*f4a2713aSLionel Sambuc  int x, y;
33*f4a2713aSLionel Sambuc } s __attribute ((address_space(1))) = {1, 1};
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc // rdar://6774906
37*f4a2713aSLionel Sambuc __attribute__((address_space(256))) void * * const base = 0;
get_0(void)38*f4a2713aSLionel Sambuc void * get_0(void) {
39*f4a2713aSLionel Sambuc   return base[0];  // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}}
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc __attribute__((address_space(1))) char test3_array[10];
test3(void)43*f4a2713aSLionel Sambuc void test3(void) {
44*f4a2713aSLionel Sambuc   extern void test3_helper(char *p); // expected-note {{passing argument to parameter 'p' here}}
45*f4a2713aSLionel Sambuc   test3_helper(test3_array); // expected-error {{changes address space of pointer}}
46*f4a2713aSLionel Sambuc }
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc typedef void ft(void);
49*f4a2713aSLionel Sambuc _AS1 ft qf; // expected-error {{function type may not be qualified with an address space}}
50*f4a2713aSLionel Sambuc typedef _AS1 ft qft; // expected-error {{function type may not be qualified with an address space}}
51*f4a2713aSLionel Sambuc 
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc typedef _AS2 int AS2Int;
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc struct HasASFields
56*f4a2713aSLionel Sambuc {
57*f4a2713aSLionel Sambuc   _AS2 int as_field; // expected-error {{field may not be qualified with an address space}}
58*f4a2713aSLionel Sambuc    AS2Int typedef_as_field; // expected-error {{field may not be qualified with an address space}}
59*f4a2713aSLionel Sambuc };
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc // Assertion failure was when the field was accessed
access_as_field()62*f4a2713aSLionel Sambuc void access_as_field()
63*f4a2713aSLionel Sambuc {
64*f4a2713aSLionel Sambuc     struct HasASFields x;
65*f4a2713aSLionel Sambuc     (void) bar.as_field;
66*f4a2713aSLionel Sambuc }
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc typedef int PR4997 __attribute__((address_space(Foobar))); // expected-error {{use of undeclared identifier 'Foobar'}}
69*f4a2713aSLionel Sambuc __attribute__((address_space("12"))) int *i; // expected-error {{'address_space' attribute requires an integer constant}}
70