2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 %s -fsyntax-only -verify
2008-02-21 09:42:41 +08:00
# define _AS1 __attribute__((address_space(1)))
# define _AS2 __attribute__((address_space(2)))
# define _AS3 __attribute__((address_space(3)))
2009-10-01 04:47:43 +08:00
void bar ( _AS2 int a ) ; // expected-error {{parameter may not be qualified with an address space}}
2013-02-27 05:16:00 +08:00
void foo ( _AS3 float * a ,
2009-10-01 04:47:43 +08:00
_AS1 float b ) // expected-error {{parameter may not be qualified with an address space}}
{
2009-02-28 02:53:28 +08:00
_AS2 * x ; // expected-warning {{type specifier missing, defaults to 'int'}}
2008-02-21 09:42:41 +08:00
_AS1 float * _AS2 * B ;
2008-03-15 02:07:10 +08:00
int _AS1 _AS2 * Y ; // expected-error {{multiple address spaces specified for type}}
2008-02-21 09:42:41 +08:00
int * _AS1 _AS2 * Z ; // expected-error {{multiple address spaces specified for type}}
2018-06-20 16:31:24 +08:00
int * _AS1 _AS1 * M ; // expected-warning {{multiple identical address spaces specified for type}}
2008-02-21 09:42:41 +08:00
2008-03-15 02:07:10 +08:00
_AS1 int local ; // expected-error {{automatic variable qualified with an address space}}
2008-03-26 02:36:32 +08:00
_AS1 int array [ 5 ] ; // expected-error {{automatic variable qualified with an address space}}
_AS1 int arrarr [ 5 ] [ 5 ] ; // expected-error {{automatic variable qualified with an address space}}
2008-03-14 08:22:18 +08:00
2009-07-28 14:52:18 +08:00
__attribute__ ( ( address_space ( - 1 ) ) ) int * _boundsA ; // expected-error {{address space is negative}}
2017-04-12 01:24:23 +08:00
__attribute__ ( ( address_space ( 0x7FFFFF ) ) ) int * _boundsB ; // expected-error {{address space is larger than the maximum supported}}
2009-07-28 14:52:18 +08:00
__attribute__ ( ( address_space ( 0x1000000 ) ) ) int * _boundsC ; // expected-error {{address space is larger than the maximum supported}}
// chosen specifically to overflow 32 bits and come out reasonable
__attribute__ ( ( address_space ( 4294967500 ) ) ) int * _boundsD ; // expected-error {{address space is larger than the maximum supported}}
2009-10-01 04:47:43 +08:00
* a = 5.0f + b ;
2008-02-21 09:42:41 +08:00
}
2009-01-12 08:08:58 +08:00
struct _st {
int x , y ;
} s __attribute ( ( address_space ( 1 ) ) ) = { 1 , 1 } ;
2009-04-13 14:04:39 +08:00
// rdar://6774906
__attribute__ ( ( address_space ( 256 ) ) ) void * * const base = 0 ;
void * get_0 ( void ) {
2011-02-01 08:10:29 +08:00
return base [ 0 ] ; // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}}
2009-04-13 14:04:39 +08:00
}
2011-02-02 07:28:01 +08:00
__attribute__ ( ( address_space ( 1 ) ) ) char test3_array [ 10 ] ;
void test3 ( void ) {
extern void test3_helper ( char * p ) ; // expected-note {{passing argument to parameter 'p' here}}
test3_helper ( test3_array ) ; // expected-error {{changes address space of pointer}}
}
2011-07-28 04:30:05 +08:00
typedef void ft ( void ) ;
_AS1 ft qf ; // expected-error {{function type may not be qualified with an address space}}
typedef _AS1 ft qft ; // expected-error {{function type may not be qualified with an address space}}
2013-02-27 05:16:00 +08:00
typedef _AS2 int AS2Int ;
struct HasASFields
{
_AS2 int as_field ; // expected-error {{field may not be qualified with an address space}}
AS2Int typedef_as_field ; // expected-error {{field may not be qualified with an address space}}
} ;
// Assertion failure was when the field was accessed
void access_as_field ( )
{
struct HasASFields x ;
( void ) bar . as_field ;
}
2013-07-04 12:10:46 +08:00
typedef int PR4997 __attribute__ ( ( address_space ( Foobar ) ) ) ; // expected-error {{use of undeclared identifier 'Foobar'}}
2013-07-30 22:10:17 +08:00
__attribute__ ( ( address_space ( " 12 " ) ) ) int * i ; // expected-error {{'address_space' attribute requires an integer constant}}
2015-09-30 21:49:55 +08:00
// Clang extension doesn't forbid operations on pointers to different address spaces.
char * cmp ( _AS1 char * x , _AS2 char * y ) {
2019-05-07 11:20:17 +08:00
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}}
2016-05-12 02:38:21 +08:00
}
2018-09-06 03:22:40 +08:00
2020-05-21 03:22:30 +08:00
char * sub ( _AS1 char * x , _AS2 char * y ) {
return x - y ; // expected-error {{arithmetic operation with operands of type ('_AS1 char *' and '_AS2 char *') which are pointers to non-overlapping address spaces}}
}
2018-09-06 03:22:40 +08:00
struct SomeStruct {
int a ;
long b ;
int c ;
} ;
// Compound literals in function scope are lvalues with automatic storage duration,
// so they cannot realistically be qualified with an address space.
void as_compound_literal ( ) {
( _AS1 struct SomeStruct ) { 1 , 2 , 3 } ; // expected-error {{compound literal in function scope may not be qualified with an address space}}
( _AS1 char [ ] ) { " test " } ; // expected-error {{compound literal in function scope may not be qualified with an address space}}
( _AS1 char [ ] ) { ' a ' , ' b ' , ' c ' } ; // expected-error {{compound literal in function scope may not be qualified with an address space}}
}