[clang] [OpenMP][clang][HIP][CUDA] fix weak alias emit on device compilation (PR #164326)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 24 13:54:41 PDT 2025


================
@@ -4065,8 +4065,40 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 
   // If this is an alias definition (which otherwise looks like a declaration)
   // emit it now.
-  if (Global->hasAttr<AliasAttr>())
+  if (Global->hasAttr<AliasAttr>()) {
+    if (LangOpts.OpenMPIsTargetDevice || LangOpts.CUDA) {
+      const auto *AA = Global->getAttr<AliasAttr>();
+      assert(AA && "Not an alias?");
+      GlobalDecl AliaseeGD;
+      if (!lookupRepresentativeDecl(AA->getAliasee(), AliaseeGD)) {
+        if (LangOpts.CUDA)
+          // Failed to find aliasee on device side, skip emitting
----------------
Jason-VanBeusekom wrote:

`LangOpts.CUDA` is true for both HIP and CUDA cases for both host and device compilation, this is not a hard error as this is triggered during host compilation for a device only alias and during device compilation for a host only alais 

in [16c1a68](https://github.com/llvm/llvm-project/pull/164326/commits/16c1a6888b87644f24c07a75c067d9e25eb1ac3e) I refactored this and added comments to hopefully clear this up. I also added a comment below going into depth about the various states in the refactor and when they are triggered.

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


More information about the cfe-commits mailing list