Author: Nick Desaulniers Date: 2020-10-26T11:37:55-07:00 New Revision: c8f84bd0947d770a5df5e15d568a25a4f190df0b
URL: https://github.com/llvm/llvm-project/commit/c8f84bd0947d770a5df5e15d568a25a4f190df0b DIFF: https://github.com/llvm/llvm-project/commit/c8f84bd0947d770a5df5e15d568a25a4f190df0b.diff LOG: [Clang][CodeGen] fix failed assertion Ensure we can emit symbol aliases via function attribute even when function signatures contain incomplete types. Via bugreport: https://reviews.llvm.org/D66492#2350947 Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D90073 Added: Modified: clang/lib/CodeGen/CodeGenModule.cpp clang/test/CodeGen/alias.c Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index fd13321b777e..2a7fb4ff88ac 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4684,8 +4684,10 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { 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. diff --git a/clang/test/CodeGen/alias.c b/clang/test/CodeGen/alias.c index 21483cfb950b..41939cbe43b3 100644 --- a/clang/test/CodeGen/alias.c +++ b/clang/test/CodeGen/alias.c @@ -109,3 +109,9 @@ static void test11_foo(void) __attribute__((alias("test11"))); // 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"))); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits