summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Mangler.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-15 01:32:03 +0000
committerChris Lattner <sabre@nondot.org>2005-11-15 01:32:03 +0000
commit7c727b2736202ff5a32a3c042e063d1546edfcb4 (patch)
treee934390e92c483ed90cda844b97ea42ae7717c4e /llvm/lib/VMCore/Mangler.cpp
parent76ac0685681b4a4855ab909b0f22bd9312f569be (diff)
downloadbcm5719-llvm-7c727b2736202ff5a32a3c042e063d1546edfcb4.tar.gz
bcm5719-llvm-7c727b2736202ff5a32a3c042e063d1546edfcb4.zip
Fix handling of multiple unnamed globals with the same type
llvm-svn: 24362
Diffstat (limited to 'llvm/lib/VMCore/Mangler.cpp')
-rw-r--r--llvm/lib/VMCore/Mangler.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/VMCore/Mangler.cpp b/llvm/lib/VMCore/Mangler.cpp
index 5257ca13a0c..f68959abe64 100644
--- a/llvm/lib/VMCore/Mangler.cpp
+++ b/llvm/lib/VMCore/Mangler.cpp
@@ -132,6 +132,11 @@ std::string Mangler::getValueName(const GlobalValue *GV) {
// - Otherwise, mangling occurs if global collides with existing name.
if (isa<Function>(GV) && cast<Function>(GV)->getIntrinsicID()) {
Name = GV->getName(); // Is an intrinsic function
+ } else if (!GV->hasName()) {
+ // Must mangle the global into a unique ID.
+ unsigned TypeUniqueID = getTypeID(GV->getType());
+ static unsigned GlobalID = 0;
+ Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(GlobalID++);
} else if (!MangledGlobals.count(GV)) {
Name = makeNameProper(GV->getName(), Prefix);
} else {
@@ -144,10 +149,8 @@ std::string Mangler::getValueName(const GlobalValue *GV) {
void Mangler::InsertName(GlobalValue *GV,
std::map<std::string, GlobalValue*> &Names) {
- if (!GV->hasName()) { // We must mangle unnamed globals.
- MangledGlobals.insert(GV);
+ if (!GV->hasName()) // We must mangle unnamed globals.
return;
- }
// Figure out if this is already used.
GlobalValue *&ExistingValue = Names[GV->getName()];
OpenPOWER on IntegriCloud