blob: a53bb4da00034804c00f2988cb9ba1a53e5e9f68 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -fsyntax-only -verify
Chris Lattner73804662008-02-21 01:42:41 +00002
3#define _AS1 __attribute__((address_space(1)))
4#define _AS2 __attribute__((address_space(2)))
5#define _AS3 __attribute__((address_space(3)))
6
Tanya Lattner27a84d02009-09-30 20:47:43 +00007void bar(_AS2 int a); // expected-error {{parameter may not be qualified with an address space}}
8
9void foo(_AS3 float *a,
10 _AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
11{
Chris Lattner35d276f2009-02-27 18:53:28 +000012 _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
Chris Lattner73804662008-02-21 01:42:41 +000013 _AS1 float * _AS2 *B;
14
Nate Begemanc8e89a82008-03-14 18:07:10 +000015 int _AS1 _AS2 *Y; // expected-error {{multiple address spaces specified for type}}
Chris Lattner73804662008-02-21 01:42:41 +000016 int *_AS1 _AS2 *Z; // expected-error {{multiple address spaces specified for type}}
17
Nate Begemanc8e89a82008-03-14 18:07:10 +000018 _AS1 int local; // expected-error {{automatic variable qualified with an address space}}
Nate Begeman8e7dafe2008-03-25 18:36:32 +000019 _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 Begeman5af27e02008-03-14 00:22:18 +000021
John McCallefadb772009-07-28 06:52:18 +000022 __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 Lattner27a84d02009-09-30 20:47:43 +000028 *a = 5.0f + b;
Chris Lattner73804662008-02-21 01:42:41 +000029}
Chris Lattner863ea9a2009-01-12 00:08:58 +000030
31struct _st {
32 int x, y;
33} s __attribute ((address_space(1))) = {1, 1};
34
Chris Lattnerecca7532009-04-13 06:04:39 +000035
36// rdar://6774906
37__attribute__((address_space(256))) void * * const base = 0;
38void * get_0(void) {
John McCall86c05f32011-02-01 00:10:29 +000039 return base[0]; // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}}
Chris Lattnerecca7532009-04-13 06:04:39 +000040}
41
John McCall40249e72011-02-01 23:28:01 +000042__attribute__((address_space(1))) char test3_array[10];
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}