r214606 - In the case of mangling collisions, make an attempt to note both definitions
Richard Smith
richard-llvm at metafoo.co.uk
Fri Aug 1 17:50:17 PDT 2014
Author: rsmith
Date: Fri Aug 1 19:50:16 2014
New Revision: 214606
URL: http://llvm.org/viewvc/llvm-project?rev=214606&view=rev
Log:
In the case of mangling collisions, make an attempt to note both definitions
involved.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=214606&r1=214605&r2=214606&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Aug 1 19:50:16 2014
@@ -549,9 +549,9 @@ StringRef CodeGenModule::getMangledName(
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::getBlockMangled
else
MangleCtx.mangleBlock(cast<DeclContext>(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::EmitGlobalFunctionDe
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;
}
Modified: cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp?rev=214606&r1=214605&r2=214606&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/duplicate-mangled-name.cpp Fri Aug 1 19:50:16 2014
@@ -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}}
}
More information about the cfe-commits
mailing list