[PATCH] D90073: [Clang][CodeGen] fix failed assertion

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 10:41:40 PDT 2020


nickdesaulniers updated this revision to Diff 300733.
nickdesaulniers added a comment.

- dyn_cast, else


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90073/new/

https://reviews.llvm.org/D90073

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/alias.c


Index: clang/test/CodeGen/alias.c
===================================================================
--- clang/test/CodeGen/alias.c
+++ clang/test/CodeGen/alias.c
@@ -109,3 +109,9 @@
 // CHECKGLOBALS: @test12_alias = alias void (), void ()* @test12
 void test12(void) {}
 inline void test12_alias(void) __attribute__((gnu_inline, alias("test12")));
+
+// Test that a non visible (-Wvisibility) type doesn't assert.
+// CHECKGLOBALS: @test13_alias = alias {}, bitcast (void (i32)* @test13 to {}*)
+enum a_type { test13_a };
+void test13(enum a_type y) {}
+void test13_alias(enum undeclared_type y) __attribute__((alias ("test13")));
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4637,8 +4637,10 @@
     Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
                                     llvm::PointerType::getUnqual(DeclTy),
                                     /*D=*/nullptr);
-    LT = getLLVMLinkageVarDefinition(cast<VarDecl>(GD.getDecl()),
-                                     D->getType().isConstQualified());
+    if (const auto *VD = dyn_cast<VarDecl>(GD.getDecl()))
+      LT = getLLVMLinkageVarDefinition(VD, D->getType().isConstQualified());
+    else
+      LT = getFunctionLinkage(GD);
   }
 
   // Create the new alias itself, but don't set a name yet.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90073.300733.patch
Type: text/x-patch
Size: 1420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201026/7ad5bdd2/attachment.bin>


More information about the cfe-commits mailing list