[clang] [clang][CUDA][HIP] Use host alignment for device definitions (PR #246922)

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 29 18:33:42 PST 2026


================
@@ -2817,7 +2817,13 @@ unsigned ASTContext::getMinGlobalAlignOfVar(uint64_t Size,
   // Make the default handling as that of a non-weak definition in the
   // current translation unit.
   bool HasNonWeakDef = !VD || (VD->hasDefinition() && !VD->isWeak());
-  return getTargetInfo().getMinGlobalAlign(Size, HasNonWeakDef);
+  unsigned Align = getTargetInfo().getMinGlobalAlign(Size, HasNonWeakDef);
+  // In CUDA/HIP device compilation, also apply the host's minimum to a
+  // variable defined here. The storage of other declarations may come from an
+  // object built without the host's rule.
+  if (LangOpts.CUDAIsDevice && AuxTarget && VD && HasNonWeakDef)
+    Align = std::max(Align, AuxTarget->getMinGlobalAlign(Size, HasNonWeakDef));
----------------
Artem-B wrote:

```
if (LangOpts.CUDAIsDevice && AuxTarget && VD && HasNonWeakDef)
    return std::max(Align, AuxTarget->getMinGlobalAlign(Size, HasNonWeakDef))
```

https://github.com/llvm/llvm-project/pull/246922


More information about the cfe-commits mailing list