Author: Tom Stellard
Date: 2023-05-31T09:11:59-07:00
New Revision: e88fe8181e360a7596c930c1036f08b7af4925ae

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

LOG: clang/openmp: Fix alignment for ThreadID Address variables

There are places in the runtime, like __kmp_init_indirect_csptr, which
assume these pointers are aligned to sizeof(void*), so make sure we emit
them with the correct alignment.

Fixes #62668

Reviewed By: jlpeyton

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

Added: 
    

Modified: 
    clang/lib/CodeGen/CGOpenMPRuntime.cpp
    clang/test/OpenMP/for_reduction_codegen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 5957e59097709..2feab9e9a3322 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2143,7 +2143,11 @@ Address 
CGOpenMPRuntime::emitThreadIDAddress(CodeGenFunction &CGF,
 llvm::Value *CGOpenMPRuntime::getCriticalRegionLock(StringRef CriticalName) {
   std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
   std::string Name = getName({Prefix, "var"});
-  return OMPBuilder.getOrCreateInternalVariable(KmpCriticalNameTy, Name);
+  llvm::GlobalVariable *G = 
OMPBuilder.getOrCreateInternalVariable(KmpCriticalNameTy, Name);
+  llvm::Align PtrAlign = 
OMPBuilder.M.getDataLayout().getPointerABIAlignment(G->getAddressSpace());
+  if (PtrAlign > llvm::Align(G->getAlignment()))
+    G->setAlignment(PtrAlign);
+  return G;
 }
 
 namespace {

diff  --git a/clang/test/OpenMP/for_reduction_codegen.cpp 
b/clang/test/OpenMP/for_reduction_codegen.cpp
index 9c3bc03c2e16e..2866a79f6de4b 100644
--- a/clang/test/OpenMP/for_reduction_codegen.cpp
+++ b/clang/test/OpenMP/for_reduction_codegen.cpp
@@ -1,4 +1,4 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --check-globals --include-generated-funcs 
--replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" 
"reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _ 
--global-value-regex ".gomp_critical_user[a-zA-Z_.]+"
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-apple-darwin10 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap %s 
--check-prefix=CHECK1
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-apple-darwin10 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -std=c++11 
-include-pch %t -verify %s -emit-llvm -o - | FileCheck 
-allow-deprecated-dag-overlap %s --check-prefix=CHECK1
@@ -527,6 +527,14 @@ int main() {
 
 
 #endif
+//.
+// CHECK1: @.gomp_critical_user_.reduction.var = common global [8 x i32] 
zeroinitializer, align 8
+// CHECK1: @.gomp_critical_user_.atomic_reduction.var = common global [8 x 
i32] zeroinitializer, align 8
+//.
+// CHECK3: @.gomp_critical_user_.reduction.var = common global [8 x i32] 
zeroinitializer, align 8
+//.
+// CHECK4: @.gomp_critical_user_.reduction.var = common global [8 x i32] 
zeroinitializer, align 8
+//.
 // CHECK1-LABEL: define {{[^@]+}}@main
 // CHECK1-SAME: () #[[ATTR0:[0-9]+]] {
 // CHECK1-NEXT:  entry:


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to