[clang] cbe8b57 - [Clang] Allow the combination of loader_uninitialized and address spaces

Johannes Doerfert via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 23 09:21:57 PDT 2021


Author: Johannes Doerfert
Date: 2021-04-23T11:21:52-05:00
New Revision: cbe8b57a675537183eaf8c32eaa6087cea3fc5da

URL: https://github.com/llvm/llvm-project/commit/cbe8b57a675537183eaf8c32eaa6087cea3fc5da
DIFF: https://github.com/llvm/llvm-project/commit/cbe8b57a675537183eaf8c32eaa6087cea3fc5da.diff

LOG: [Clang] Allow the combination of loader_uninitialized and address spaces

When an object is allocated in a non-default address space we do not
need to check for a constructor if it is not initialized and has a
trivial constructor (which we won't call then).

Reviewed By: JonChesterfield

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaDecl.cpp
    clang/test/CodeGen/attr-loader-uninitialized.c
    clang/test/OpenMP/declare_target_codegen.cpp
    clang/test/Sema/attr-loader-uninitialized.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8a718249d8549..e910896153029 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12640,6 +12640,8 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
           return;
         }
       }
+      // The declaration is unitialized, no need for further checks.
+      return;
     }
 
     VarDecl::DefinitionKind DefKind = Var->isThisDeclarationADefinition();

diff  --git a/clang/test/CodeGen/attr-loader-uninitialized.c b/clang/test/CodeGen/attr-loader-uninitialized.c
index 98fb6c0dd42e0..2a97c47b6cdb6 100644
--- a/clang/test/CodeGen/attr-loader-uninitialized.c
+++ b/clang/test/CodeGen/attr-loader-uninitialized.c
@@ -18,7 +18,19 @@ typedef struct
 } s;
 
 // CHECK: @i ={{.*}} global %struct.s undef
+// CHECK: @j1 ={{.*}}addrspace(1) global %struct.s undef
+// CHECK: @j2 ={{.*}}addrspace(2) global %struct.s undef
+// CHECK: @j3 ={{.*}}addrspace(3) global %struct.s undef
+// CHECK: @j4 ={{.*}}addrspace(4) global %struct.s undef
+// CHECK: @j5 ={{.*}}addrspace(5) global %struct.s undef
+// CHECK: @j99 ={{.*}}addrspace(99) global %struct.s undef
 s i __attribute__((loader_uninitialized));
+s j1 __attribute__((loader_uninitialized, address_space(1)));
+s j2 __attribute__((loader_uninitialized, address_space(2)));
+s j3 __attribute__((loader_uninitialized, address_space(3)));
+s j4 __attribute__((loader_uninitialized, address_space(4)));
+s j5 __attribute__((loader_uninitialized, address_space(5)));
+s j99 __attribute__((loader_uninitialized, address_space(99)));
 
 // CHECK: @private_extern_ok = hidden global i32 undef
 __private_extern__ int private_extern_ok __attribute__((loader_uninitialized));

diff  --git a/clang/test/OpenMP/declare_target_codegen.cpp b/clang/test/OpenMP/declare_target_codegen.cpp
index 4b9bb41bd9179..d6e97e3bbfe70 100644
--- a/clang/test/OpenMP/declare_target_codegen.cpp
+++ b/clang/test/OpenMP/declare_target_codegen.cpp
@@ -37,6 +37,7 @@
 // CHECK-DAG: @fff_decl_tgt_ref_ptr = weak global i32* null
 // CHECK-DAG: @eee_decl_tgt_ref_ptr = weak global i32* null
 // CHECK-DAG: @{{.*}}maini1{{.*}}aaa = internal global i64 23,
+// CHECK-DAG: @pair = {{.*}}addrspace(3) global %struct.PAIR undef
 // CHECK-DAG: @b ={{ hidden | }}global i32 15,
 // CHECK-DAG: @d ={{ hidden | }}global i32 0,
 // CHECK-DAG: @c = external global i32,
@@ -264,6 +265,15 @@ void device_fun() {}
 // DEV5-NOT: define {{.*}}void {{.*}}host_fun{{.*}}
 #endif // OMP5
 
+struct PAIR {
+  int a;
+  int b;
+};
+
+#pragma omp declare target
+PAIR pair __attribute__((address_space(3), loader_uninitialized));
+#pragma omp end declare target
+
 #endif // HEADER
 
 #ifdef LOAD

diff  --git a/clang/test/Sema/attr-loader-uninitialized.cpp b/clang/test/Sema/attr-loader-uninitialized.cpp
index 54b018fd91eba..61ff36983a44a 100644
--- a/clang/test/Sema/attr-loader-uninitialized.cpp
+++ b/clang/test/Sema/attr-loader-uninitialized.cpp
@@ -5,7 +5,6 @@ static int local_ok __attribute__((loader_uninitialized));
 int hidden_ok __attribute__((visibility("hidden"))) __attribute__((loader_uninitialized));
 
 const int still_cant_be_const __attribute__((loader_uninitialized));
-// expected-error at -1 {{default initialization of an object of const type}}
 extern int external_rejected __attribute__((loader_uninitialized));
 // expected-error at -1 {{variable 'external_rejected' cannot be declared both 'extern' and with the 'loader_uninitialized' attribute}}
 


        


More information about the cfe-commits mailing list