]> granicus.if.org Git - clang/commitdiff
[OpenCL][PR42031] Prevent deducing addr space in type alias.
authorAnastasia Stulova <anastasia.stulova@arm.com>
Wed, 5 Jun 2019 14:50:01 +0000 (14:50 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Wed, 5 Jun 2019 14:50:01 +0000 (14:50 +0000)
Similar to typedefs we shouldn't deduce addr space in
type alias.

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

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

lib/Sema/SemaType.cpp
test/SemaOpenCLCXX/address-space-deduction.cl

index 27f034bd1404ec607f6ae91529201c9de11bc069..47de398d4fde201c27747dffa8f169a841d2b17c 100644 (file)
@@ -7401,6 +7401,9 @@ static void deduceOpenCLImplicitAddrSpace(TypeProcessingState &State,
       (D.getContext() == DeclaratorContext::MemberContext &&
        (!IsPointee &&
         D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)) ||
+      // Do not deduce addr space of non-pointee in type alias because it
+      // doesn't define any object.
+      (D.getContext() == DeclaratorContext::AliasDeclContext && !IsPointee) ||
       // 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.
index d6dcc853a60cdda2aa9f9189b2406c788a21c036..6b2a07cad748b7ce0ae40be5579b165b9875721c 100644 (file)
@@ -1,12 +1,26 @@
-//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify | FileCheck %s
 
 //expected-no-diagnostics
 
-//CHECK: |-VarDecl  foo {{.*}} 'const __global int' constexpr cinit
+//CHECK: |-VarDecl {{.*}} foo 'const __global int'
 constexpr int foo = 0;
 
 class c {
 public:
-  //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
+  //CHECK: `-VarDecl {{.*}} foo2 'const __global int'
   static constexpr int foo2 = 0;
 };
+
+struct c1 {};
+
+// We only deduce addr space in type alias in pointer types.
+//CHECK: TypeAliasDecl {{.*}} alias_c1 'c1'
+using alias_c1 = c1;
+//CHECK: TypeAliasDecl {{.*}} alias_c1_ptr '__generic c1 *'
+using alias_c1_ptr = c1 *;
+
+struct c2 {
+  alias_c1 y;
+  alias_c1_ptr ptr = &y;
+};
+