]> granicus.if.org Git - clang/commitdiff
[OpenCL] Deduce static data members to __global addr space.
authorAnastasia Stulova <anastasia.stulova@arm.com>
Thu, 2 May 2019 14:40:40 +0000 (14:40 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Thu, 2 May 2019 14:40:40 +0000 (14:40 +0000)
Similarly to static variables in OpenCL, static class data
members should be deduced to __global addr space.

Differential Revision: https://reviews.llvm.org/D61304

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359789 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/SemaOpenCLCXX/address-space-deduction.cl [new file with mode: 0644]

index 32e57eb925c31036b818306d6b4fe392aabfd950..3b25595a33a6f9274dd5825d83eb47c5bac4f807 100644 (file)
@@ -7308,8 +7308,10 @@ static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State,
        // otherwise it will fail some sema check.
       IsFuncReturnType || IsFuncType ||
       // Do not deduce addr space for member types of struct, except the pointee
-      // type of a pointer member type.
-      (D.getContext() == DeclaratorContext::MemberContext && !IsPointee) ||
+      // type of a pointer member type or static data members.
+      (D.getContext() == DeclaratorContext::MemberContext &&
+       (!IsPointee &&
+        D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)) ||
       // Do not deduce addr space for types used to define a typedef and the
       // typedef itself, except the pointee type of a pointer type which is used
       // to define the typedef.
diff --git a/test/SemaOpenCLCXX/address-space-deduction.cl b/test/SemaOpenCLCXX/address-space-deduction.cl
new file mode 100644 (file)
index 0000000..d6dcc85
--- /dev/null
@@ -0,0 +1,12 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify
+
+//expected-no-diagnostics
+
+//CHECK: |-VarDecl  foo {{.*}} 'const __global int' constexpr cinit
+constexpr int foo = 0;
+
+class c {
+public:
+  //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
+  static constexpr int foo2 = 0;
+};