Skip to content

Commit 11a9bae

Browse files
Naghasanbader
authored andcommitted
[AST] Enable expression of OpenCL language address spaces an attribute
Summary: Enable a way to set OpenCL language address space using attributes in addition to existing keywords. Signed-off-by: Victor Lomuller [email protected] Reviewers: aaron.ballman, Anastasia Subscribers: yaxunl, ebevhan, cfe-commits, Naghasan Tags: #clang Differential Revision: https://reviews.llvm.org/D71005 Signed-off-by: Alexey Bader <[email protected]>
1 parent f5767e2 commit 11a9bae

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

clang/include/clang/Basic/Attr.td

+5-5
Original file line numberDiff line numberDiff line change
@@ -1120,27 +1120,27 @@ def OpenCLAccess : Attr {
11201120
}
11211121

11221122
def OpenCLPrivateAddressSpace : TypeAttr {
1123-
let Spellings = [Keyword<"__private">, Keyword<"private">];
1123+
let Spellings = [Keyword<"__private">, Keyword<"private">, Clang<"opencl_private">];
11241124
let Documentation = [OpenCLAddressSpacePrivateDocs];
11251125
}
11261126

11271127
def OpenCLGlobalAddressSpace : TypeAttr {
1128-
let Spellings = [Keyword<"__global">, Keyword<"global">];
1128+
let Spellings = [Keyword<"__global">, Keyword<"global">, Clang<"opencl_global">];
11291129
let Documentation = [OpenCLAddressSpaceGlobalDocs];
11301130
}
11311131

11321132
def OpenCLLocalAddressSpace : TypeAttr {
1133-
let Spellings = [Keyword<"__local">, Keyword<"local">];
1133+
let Spellings = [Keyword<"__local">, Keyword<"local">, Clang<"opencl_local">];
11341134
let Documentation = [OpenCLAddressSpaceLocalDocs];
11351135
}
11361136

11371137
def OpenCLConstantAddressSpace : TypeAttr {
1138-
let Spellings = [Keyword<"__constant">, Keyword<"constant">];
1138+
let Spellings = [Keyword<"__constant">, Keyword<"constant">, Clang<"opencl_constant">];
11391139
let Documentation = [OpenCLAddressSpaceConstantDocs];
11401140
}
11411141

11421142
def OpenCLGenericAddressSpace : TypeAttr {
1143-
let Spellings = [Keyword<"__generic">, Keyword<"generic">];
1143+
let Spellings = [Keyword<"__generic">, Keyword<"generic">, Clang<"opencl_generic">];
11441144
let Documentation = [OpenCLAddressSpaceGenericDocs];
11451145
}
11461146

clang/lib/Sema/SemaType.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -7407,6 +7407,16 @@ static void HandleLifetimeBoundAttr(TypeProcessingState &State,
74077407
}
74087408
}
74097409

7410+
static bool isAddressSpaceKind(const ParsedAttr &attr) {
7411+
auto attrKind = attr.getKind();
7412+
7413+
return attrKind == ParsedAttr::AT_AddressSpace ||
7414+
attrKind == ParsedAttr::AT_OpenCLPrivateAddressSpace ||
7415+
attrKind == ParsedAttr::AT_OpenCLGlobalAddressSpace ||
7416+
attrKind == ParsedAttr::AT_OpenCLLocalAddressSpace ||
7417+
attrKind == ParsedAttr::AT_OpenCLConstantAddressSpace ||
7418+
attrKind == ParsedAttr::AT_OpenCLGenericAddressSpace;
7419+
}
74107420

74117421
static void processTypeAttrs(TypeProcessingState &state, QualType &type,
74127422
TypeAttrLocation TAL,
@@ -7445,11 +7455,11 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
74457455
if (!IsTypeAttr)
74467456
continue;
74477457
}
7448-
} else if (TAL != TAL_DeclChunk &&
7449-
attr.getKind() != ParsedAttr::AT_AddressSpace) {
7458+
} else if (TAL != TAL_DeclChunk && !isAddressSpaceKind(attr)) {
74507459
// Otherwise, only consider type processing for a C++11 attribute if
74517460
// it's actually been applied to a type.
7452-
// We also allow C++11 address_space attributes to pass through.
7461+
// We also allow C++11 address_space and
7462+
// OpenCL language address space attributes to pass through.
74537463
continue;
74547464
}
74557465
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
2+
3+
// Verify that the language address space attribute is
4+
// understood correctly by clang.
5+
6+
void langas() {
7+
// CHECK: VarDecl {{.*}} x_global '__global int *'
8+
__attribute__((opencl_global)) int *x_global;
9+
10+
// CHECK: VarDecl {{.*}} z_global '__global int *'
11+
[[clang::opencl_global]] int *z_global;
12+
13+
// CHECK: VarDecl {{.*}} x_local '__local int *'
14+
__attribute__((opencl_local)) int *x_local;
15+
16+
// CHECK: VarDecl {{.*}} z_local '__local int *'
17+
[[clang::opencl_local]] int *z_local;
18+
19+
// CHECK: VarDecl {{.*}} x_constant '__constant int *'
20+
__attribute__((opencl_constant)) int *x_constant;
21+
22+
// CHECK: VarDecl {{.*}} z_constant '__constant int *'
23+
[[clang::opencl_constant]] int *z_constant;
24+
25+
// CHECK: VarDecl {{.*}} x_private 'int *'
26+
__attribute__((opencl_private)) int *x_private;
27+
28+
// CHECK: VarDecl {{.*}} z_private 'int *'
29+
[[clang::opencl_private]] int *z_private;
30+
31+
// CHECK: VarDecl {{.*}} x_generic '__generic int *'
32+
__attribute__((opencl_generic)) int *x_generic;
33+
34+
// CHECK: VarDecl {{.*}} z_generic '__generic int *'
35+
[[clang::opencl_generic]] int *z_generic;
36+
}

clang/test/SemaOpenCL/address-spaces.cl

+16
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,19 @@ __kernel void k() {
248248
unsigned data[16];
249249
func_with_array_param(data);
250250
}
251+
252+
void func_multiple_addr2(void) {
253+
typedef __private int private_int_t;
254+
__private __attribute__((opencl_global)) int var1; // expected-error {{multiple address spaces specified for type}}
255+
__private __attribute__((opencl_global)) int *var2; // expected-error {{multiple address spaces specified for type}}
256+
__attribute__((opencl_global)) private_int_t var3; // expected-error {{multiple address spaces specified for type}}
257+
__attribute__((opencl_global)) private_int_t *var4; // expected-error {{multiple address spaces specified for type}}
258+
__attribute__((opencl_private)) private_int_t var5; // expected-warning {{multiple identical address spaces specified for type}}
259+
__attribute__((opencl_private)) private_int_t *var6; // expected-warning {{multiple identical address spaces specified for type}}
260+
#if __OPENCL_CPP_VERSION__
261+
[[clang::opencl_private]] __global int var7; // expected-error {{multiple address spaces specified for type}}
262+
[[clang::opencl_private]] __global int *var8; // expected-error {{multiple address spaces specified for type}}
263+
[[clang::opencl_private]] private_int_t var9; // expected-warning {{multiple identical address spaces specified for type}}
264+
[[clang::opencl_private]] private_int_t *var10; // expected-warning {{multiple identical address spaces specified for type}}
265+
#endif // !__OPENCL_CPP_VERSION__
266+
}

0 commit comments

Comments
 (0)