From: Renato Golin Date: Wed, 15 Apr 2015 08:44:40 +0000 (+0000) Subject: Revert "[CodeGen] Fix crash with duplicated mangled name." X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90ae040cdfc037bb3fb64ac836f35948a1ceacca;p=clang Revert "[CodeGen] Fix crash with duplicated mangled name." This reverts commit r234767, as it was breaking all ARM buildbots for two days and the assert is not in the code, making it difficult to spot the error, which would keep the bots red for a few more days. New errors were silently introduced because of this bug, and we don't want this to escalate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234983 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 4dd965f24a..f60a68ab01 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1372,15 +1372,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { /*DontDefer=*/false); return; } - - if (llvm::GlobalValue *GV = GetGlobalValue(getMangledName(GD))) - if (!GV->isDeclaration()) { - getDiags().Report(FD->getLocation(), diag::err_duplicate_mangled_name); - GlobalDecl OldGD = Manglings.lookup(GV->getName()); - if (auto *Prev = OldGD.getDecl()) - getDiags().Report(Prev->getLocation(), diag::note_previous_definition); - return; - } } else { const auto *VD = cast(Global); assert(VD->isFileVarDecl() && "Cannot emit local var decl as global."); @@ -2414,6 +2405,14 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, } } + if (!GV->isDeclaration()) { + getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name); + GlobalDecl OldGD = Manglings.lookup(GV->getName()); + if (auto *Prev = OldGD.getDecl()) + getDiags().Report(Prev->getLocation(), diag::note_previous_definition); + return; + } + if (GV->getType()->getElementType() != Ty) { // If the types mismatch then we have to rewrite the definition. assert(GV->isDeclaration() && "Shouldn't replace non-declaration"); diff --git a/test/CodeGenCXX/duplicate-mangled-name2.cpp b/test/CodeGenCXX/duplicate-mangled-name2.cpp deleted file mode 100644 index e582733fd8..0000000000 --- a/test/CodeGenCXX/duplicate-mangled-name2.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -emit-llvm-only %s -verify -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -femit-all-decls -emit-llvm-only %s -verify - -void foo(void *p) __asm("_ZN1SC2Ev"); -void foo(void *p) { } // expected-note {{previous}} - -struct S { - S() {} // expected-error {{definition with same mangled name as another definition}} -} s; diff --git a/test/CodeGenCXX/duplicate-mangled-name3.cpp b/test/CodeGenCXX/duplicate-mangled-name3.cpp deleted file mode 100644 index 17dbc9bc85..0000000000 --- a/test/CodeGenCXX/duplicate-mangled-name3.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only %s -verify -// RUN: %clang_cc1 -triple %itanium_abi_triple -femit-all-decls -emit-llvm-only %s -verify - -extern "C" { - void _ZN1SC2Ev(void *p) { } // expected-note {{previous}} -} - -struct S { - S() {} // expected-error {{definition with same mangled name as another definition}} -} s;