1 // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK,CHECKNOOCL
2 // RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN,WINNOOCL
3 // RUN: %clang_cc1 -cl-std=clc++ -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s --check-prefixes=CHECK,CHECKOCL
4 // RUN: %clang_cc1 -cl-std=clc++ -emit-llvm -triple x86_64-windows-msvc -o - %s | FileCheck %s --check-prefixes=WIN,WINOCL
5
6 // CHECKNOOCL-LABEL: define {{.*}}void @_Z2f0Pc
7 // WINNOOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAD@Z"
8 // CHECKOCL-LABEL: define {{.*}}void @_Z2f0PU9CLgenericc
9 // WINOCL-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_ASCLgeneric@$$CAD@__clang@@@Z"
f0(char * p)10 void f0(char *p) { }
11 // CHECK-LABEL: define {{.*}}void @_Z2f0PU3AS1c
12 // WIN-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_AS@$00$$CAD@__clang@@@Z"
f0(char * p)13 void f0(char __attribute__((address_space(1))) *p) { }
14
15 struct OpaqueType;
16 typedef OpaqueType __attribute__((address_space(100))) * OpaqueTypePtr;
17
18 // CHECK-LABEL: define {{.*}}void @_Z2f0PU5AS10010OpaqueType
19 // WIN-LABEL: define {{.*}}void @"?f0@@YAXPEAU?$_AS@$0GE@$$CAUOpaqueType@@@__clang@@@Z"
f0(OpaqueTypePtr)20 void f0(OpaqueTypePtr) { }
21
22 // CHECK-LABEL: define {{.*}}void @_Z2f1PU3AS1Kc
23 // WIN-LABEL: define {{.*}}void @"?f1@@YAXPEAU?$_AS@$00$$CBD@__clang@@@Z"
f1(char const * p)24 void f1(char __attribute__((address_space(1))) const *p) {}
25
26 // Ensure we can do return values, which change in MS mode.
27 // CHECK-LABEL: define {{.*}}ptr addrspace(1) @_Z2f1PU3AS2Kc
28 // WIN-LABEL: define {{.*}}ptr addrspace(1) @"?f1@@YAPEAU?$_AS@$00$$CAM@__clang@@PEAU?$_AS@$01$$CBD@2@@Z"
f1(char const * p)29 __attribute__((address_space(1))) float *f1(char __attribute__((address_space(2))) const *p) { return 0;}
30
31 #if !defined(__OPENCL_CPP_VERSION__)
32 // Return value of address space without a pointer is invalid in opencl.
33 // Ensure we skip return values, since non-pointers aren't supposed to have an AS.
34 // CHECKNOOCL-LABEL: define {{.*}}float @_Z2f2PU3AS2Kc
35 // WINNOOCL-LABEL: define {{.*}}float @"?f2@@YA?AMQEAU?$_AS@$01$$CBD@__clang@@@Z"
f2(char const * const p)36 __attribute__((address_space(1))) float f2(char __attribute__((address_space(2))) const * const p) { return 0;}
37 #endif
38
39 #ifdef __OPENCL_CPP_VERSION__
40 // CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f0PU9CLprivatec
41 // WINOCL-LABEL: define {{.*}}void @"?ocl_f0@@YAXPEAU?$_ASCLprivate@$$CAD@__clang@@@Z"
ocl_f0(char __private * p)42 void ocl_f0(char __private *p) { }
43
44 struct ocl_OpaqueType;
45 typedef ocl_OpaqueType __global * ocl_OpaqueTypePtr;
46 typedef ocl_OpaqueType __attribute__((opencl_global_host)) * ocl_OpaqueTypePtrH;
47 typedef ocl_OpaqueType
48 __attribute__((opencl_global_device)) *
49 ocl_OpaqueTypePtrD;
50
51 // CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f0PU8CLglobal14ocl_OpaqueType
52 // WINOCL-LABEL: define {{.*}}void @"?ocl_f0@@YAXPEAU?$_ASCLglobal@$$CAUocl_OpaqueType@@@__clang@@@Z"
ocl_f0(ocl_OpaqueTypePtr)53 void ocl_f0(ocl_OpaqueTypePtr) { }
54
55 // CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f1PU10CLconstantKc
56 // WINOCL-LABEL: define {{.*}}void @"?ocl_f1@@YAXPEAU?$_ASCLconstant@$$CBD@__clang@@@Z"
ocl_f1(char __constant const * p)57 void ocl_f1(char __constant const *p) {}
58
59 // Ensure we can do return values, which change in MS mode.
60 // CHECKOCL-LABEL: define {{.*}}ptr @_Z6ocl_f1PU9CLgenericKc
61 // WINOCL-LABEL: define {{.*}}ptr @"?ocl_f1@@YAPEAU?$_ASCLconstant@$$CAM@__clang@@PEAU?$_ASCLgeneric@$$CBD@2@@Z"
ocl_f1(char __generic const * p)62 __constant float *ocl_f1(char __generic const *p) { return 0;}
63
64 // Ensure we skip return values, since non-pointers aren't supposed to have an AS.
65 // CHECKOCL-LABEL: define {{.*}}ptr @_Z6ocl_f2PU9CLgenericKc
66 // WINOCL-LABEL: define {{.*}}ptr @"?ocl_f2@@YAPEAU?$_ASCLgeneric@$$CAM@__clang@@QEAU?$_ASCLgeneric@$$CBD@2@@Z"
ocl_f2(__generic char const * const p)67 __generic float *ocl_f2(__generic char const * const p) { return 0;}
68
69 // CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f3PU6CLhost14ocl_OpaqueType
70 // WINOCL-LABEL: define {{.*}}void @"?ocl_f3@@YAXPEAU?$_ASCLhost@$$CAUocl_OpaqueType@@@__clang@@@Z"
ocl_f3(ocl_OpaqueTypePtrH)71 void ocl_f3(ocl_OpaqueTypePtrH) {}
72
73 // CHECKOCL-LABEL: define {{.*}}void @_Z6ocl_f4PU8CLdevice14ocl_OpaqueType
74 // WINOCL-LABEL: define {{.*}}void @"?ocl_f4@@YAXPEAU?$_ASCLdevice@$$CAUocl_OpaqueType@@@__clang@@@Z"
ocl_f4(ocl_OpaqueTypePtrD)75 void ocl_f4(ocl_OpaqueTypePtrD) {}
76 #endif
77