[PATCH] D150723: clang/openmp: Fix alignment for ThreadID Address variables

Tom Stellard via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 16 14:02:43 PDT 2023


tstellar created this revision.
tstellar added a reviewer: jlpeyton.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
tstellar requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150723

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp


Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2143,7 +2143,11 @@
 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150723.522780.patch
Type: text/x-patch
Size: 804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230516/7a7954be/attachment.bin>


More information about the cfe-commits mailing list