In the case of mangling collisions, make an attempt to note both definitions

involved.

llvm-svn: 214606
This commit is contained in:
Richard Smith 2014-08-02 00:50:16 +00:00
parent 063f425ea7
commit 6d0e97afcf
2 changed files with 9 additions and 7 deletions

View File

@ -549,9 +549,9 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
Str = II->getName(); Str = II->getName();
} }
auto &Mangled = Manglings.GetOrCreateValue(Str); // Keep the first result in the case of a mangling collision.
Mangled.second = GD; auto Result = Manglings.insert(std::make_pair(Str, GD));
return FoundStr = Mangled.first(); return FoundStr = Result.first->first();
} }
StringRef CodeGenModule::getBlockMangledName(GlobalDecl GD, StringRef CodeGenModule::getBlockMangledName(GlobalDecl GD,
@ -571,9 +571,8 @@ StringRef CodeGenModule::getBlockMangledName(GlobalDecl GD,
else else
MangleCtx.mangleBlock(cast<DeclContext>(D), BD, Out); MangleCtx.mangleBlock(cast<DeclContext>(D), BD, Out);
auto &Mangled = Manglings.GetOrCreateValue(Out.str()); auto Result = Manglings.insert(std::make_pair(Out.str(), BD));
Mangled.second = BD; return Result.first->first();
return Mangled.first();
} }
llvm::GlobalValue *CodeGenModule::GetGlobalValue(StringRef Name) { llvm::GlobalValue *CodeGenModule::GetGlobalValue(StringRef Name) {
@ -2192,6 +2191,9 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
if (!GV->isDeclaration()) { if (!GV->isDeclaration()) {
getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name); 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; return;
} }

View File

@ -4,7 +4,7 @@
class MyClass { class MyClass {
static void meth(); static void meth();
}; };
void MyClass::meth() { } void MyClass::meth() { } // expected-note {{previous}}
extern "C" { extern "C" {
void _ZN7MyClass4methEv() { } // expected-error {{definition with same mangled name as another definition}} void _ZN7MyClass4methEv() { } // expected-error {{definition with same mangled name as another definition}}
} }