mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 09:56:07 +00:00

Summary: Address spaces are used in several embedded and GPU targets to describe accesses to different types of memory. Currently we use the address space enumerations to control which address spaces are considered supersets of eachother, however this is also a target level property as described by the C standard's passing mentions. This patch allows the address space checks to use the target information to decide if a pointer conversion is legal. For AMDGPU and NVPTX, all supported address spaces can be converted to the default address space. More semantic checks can be added on top of this, for now I'm mainly looking to get more standard semantics working for C/C++. Right now the address space conversions must all be done explicitly in C/C++ unlike the offloading languages which define their own custom address spaces that just map to the same target specific ones anyway. The main question is if this behavior is a function of the target or the language.
22 lines
1.3 KiB
C
22 lines
1.3 KiB
C
// RUN: %clang_cc1 %s -triple nvptx64-nvidia-cuda -fsyntax-only -verify
|
|
|
|
#define _AS0 __attribute__((address_space(0)))
|
|
#define _AS1 __attribute__((address_space(1)))
|
|
#define _AS2 __attribute__((address_space(2)))
|
|
#define _AS3 __attribute__((address_space(3)))
|
|
#define _AS4 __attribute__((address_space(4)))
|
|
#define _AS5 __attribute__((address_space(5)))
|
|
#define _AS999 __attribute__((address_space(999)))
|
|
|
|
void *p1(void _AS1 *p) { return p; }
|
|
void *p2(void _AS2 *p) { return p; } // expected-error {{returning '_AS2 void *' from a function with result type 'void *' changes address space of pointer}}
|
|
void *p3(void _AS3 *p) { return p; }
|
|
void *p4(void _AS4 *p) { return p; }
|
|
void *p5(void _AS5 *p) { return p; }
|
|
void *pi(void _AS999 *p) { return p; } // expected-error {{returning '_AS999 void *' from a function with result type 'void *' changes address space of pointer}}
|
|
void *pc(void __attribute__((opencl_local)) *p) { return p; } // expected-error {{returning '__local void *' from a function with result type 'void *' changes address space of pointer}}
|
|
void _AS1 *r0(void _AS1 *p) { return p; }
|
|
void _AS1 *r1(void *p) { return p; } // expected-error {{returning 'void *' from a function with result type '_AS1 void *' changes address space of pointer}}
|
|
void _AS1 *r2(void *p) { return (void _AS1 *)p; }
|
|
|