From: Richard Smith Date: Sat, 2 Aug 2014 00:50:16 +0000 (+0000) Subject: In the case of mangling collisions, make an attempt to note both definitions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=775e4c92e5b72d971111ac35a4e9a5073daa12a3;p=clang In the case of mangling collisions, make an attempt to note both definitions involved. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214606 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 08063352f2..8b6aae2161 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -549,9 +549,9 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) { Str = II->getName(); } - auto &Mangled = Manglings.GetOrCreateValue(Str); - Mangled.second = GD; - return FoundStr = Mangled.first(); + // Keep the first result in the case of a mangling collision. + auto Result = Manglings.insert(std::make_pair(Str, GD)); + return FoundStr = Result.first->first(); } StringRef CodeGenModule::getBlockMangledName(GlobalDecl GD, @@ -571,9 +571,8 @@ StringRef CodeGenModule::getBlockMangledName(GlobalDecl GD, else MangleCtx.mangleBlock(cast(D), BD, Out); - auto &Mangled = Manglings.GetOrCreateValue(Out.str()); - Mangled.second = BD; - return Mangled.first(); + auto Result = Manglings.insert(std::make_pair(Out.str(), BD)); + return Result.first->first(); } llvm::GlobalValue *CodeGenModule::GetGlobalValue(StringRef Name) { @@ -2192,6 +2191,9 @@ 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; } diff --git a/test/CodeGenCXX/duplicate-mangled-name.cpp b/test/CodeGenCXX/duplicate-mangled-name.cpp index 65bfa22ac6..e57012e8c4 100644 --- a/test/CodeGenCXX/duplicate-mangled-name.cpp +++ b/test/CodeGenCXX/duplicate-mangled-name.cpp @@ -4,7 +4,7 @@ class MyClass { static void meth(); }; -void MyClass::meth() { } +void MyClass::meth() { } // expected-note {{previous}} extern "C" { void _ZN7MyClass4methEv() { } // expected-error {{definition with same mangled name as another definition}} }