set the temporary bit on MCSymbols correctly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98124 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 358521e..4978fba 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -911,8 +911,8 @@
 
   // Otherwise, emit with .set (aka assignment).
   MCSymbol *SetLabel =
-    OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "set" +
-                                 Twine(SetCounter++));
+    OutContext.GetOrCreateTemporarySymbol(Twine(MAI->getPrivateGlobalPrefix()) +
+                                          "set" + Twine(SetCounter++));
   OutStreamer.EmitAssignment(SetLabel, Diff);
   OutStreamer.EmitSymbolValue(SetLabel, Size, 0/*AddrSpace*/);
 }
@@ -1553,15 +1553,15 @@
 /// exception handling tables.
 void AsmPrinter::printLabelInst(const MachineInstr *MI) const {
   MCSymbol *Sym = 
-    OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) +
+    OutContext.GetOrCreateTemporarySymbol(Twine(MAI->getPrivateGlobalPrefix()) +
                                  "label" + Twine(MI->getOperand(0).getImm()));
   OutStreamer.EmitLabel(Sym);
 }
 
 void AsmPrinter::printLabel(unsigned Id) const {
   MCSymbol *Sym = 
-    OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) +
-                                 "label" + Twine(Id));
+    OutContext.GetOrCreateTemporarySymbol(Twine(MAI->getPrivateGlobalPrefix()) +
+                                          "label" + Twine(Id));
   OutStreamer.EmitLabel(Sym);
 }
 
@@ -1603,15 +1603,14 @@
                           "_" + FnName.str() + "_" + BB->getName(), 
                           Mangler::Private);
 
-  return OutContext.GetOrCreateSymbol(NameResult.str());
+  return OutContext.GetOrCreateTemporarySymbol(NameResult.str());
 }
 
 /// GetCPISymbol - Return the symbol for the specified constant pool entry.
 MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
-  SmallString<60> Name;
-  raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "CPI"
-    << getFunctionNumber() << '_' << CPID;
-  return OutContext.GetOrCreateSymbol(Name.str());
+  return OutContext.GetOrCreateTemporarySymbol
+    (Twine(MAI->getPrivateGlobalPrefix()) + "CPI" + Twine(getFunctionNumber())
+     + "_" + Twine(CPID));
 }
 
 /// GetJTISymbol - Return the symbol for the specified jump table entry.
@@ -1622,10 +1621,9 @@
 /// GetJTSetSymbol - Return the symbol for the specified jump table .set
 /// FIXME: privatize to AsmPrinter.
 MCSymbol *AsmPrinter::GetJTSetSymbol(unsigned UID, unsigned MBBID) const {
-  SmallString<60> Name;
-  raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix()
-    << getFunctionNumber() << '_' << UID << "_set_" << MBBID;
-  return OutContext.GetOrCreateSymbol(Name.str());
+  return OutContext.GetOrCreateTemporarySymbol
+  (Twine(MAI->getPrivateGlobalPrefix()) + Twine(getFunctionNumber()) + "_" +
+   Twine(UID) + "_set_" + Twine(MBBID));
 }
 
 /// GetGlobalValueSymbol - Return the MCSymbol for the specified global
@@ -1633,7 +1631,10 @@
 MCSymbol *AsmPrinter::GetGlobalValueSymbol(const GlobalValue *GV) const {
   SmallString<60> NameStr;
   Mang->getNameWithPrefix(NameStr, GV, false);
-  return OutContext.GetOrCreateSymbol(NameStr.str());
+  
+  if (!GV->hasPrivateLinkage())
+    return OutContext.GetOrCreateSymbol(NameStr.str());
+  return OutContext.GetOrCreateTemporarySymbol(NameStr.str());
 }
 
 /// GetSymbolWithGlobalValueBase - Return the MCSymbol for a symbol with
@@ -1645,7 +1646,9 @@
   SmallString<60> NameStr;
   Mang->getNameWithPrefix(NameStr, GV, ForcePrivate);
   NameStr.append(Suffix.begin(), Suffix.end());
-  return OutContext.GetOrCreateSymbol(NameStr.str());
+  if (!GV->hasPrivateLinkage() && !ForcePrivate)
+    return OutContext.GetOrCreateSymbol(NameStr.str());
+  return OutContext.GetOrCreateTemporarySymbol(NameStr.str());
 }
 
 /// GetExternalSymbolSymbol - Return the MCSymbol for the specified
diff --git a/lib/CodeGen/AsmPrinter/DwarfException.cpp b/lib/CodeGen/AsmPrinter/DwarfException.cpp
index b85ae3b..47b829d 100644
--- a/lib/CodeGen/AsmPrinter/DwarfException.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfException.cpp
@@ -60,7 +60,7 @@
   raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix()
                             << LabelName << Asm->getFunctionNumber()
                             << "_" << Index;
-  MCSymbol *DotSym = Asm->OutContext.GetOrCreateSymbol(Name.str());
+  MCSymbol *DotSym = Asm->OutContext.GetOrCreateTemporarySymbol(Name.str());
   Asm->OutStreamer.EmitLabel(DotSym);
 
   return MCBinaryExpr::CreateSub(ExprRef,
diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
index 80d2907..7890e5c 100644
--- a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
@@ -45,15 +45,15 @@
   
   //assert(ID && "Should use getTempLabel if no ID");
   if (ID == 0) return getTempLabel(Name);
-  return Asm->OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix())
-                                           + Twine(Name) + Twine(ID));
+  return Asm->OutContext.GetOrCreateTemporarySymbol
+        (Twine(MAI->getPrivateGlobalPrefix()) + Twine(Name) + Twine(ID));
 }
 
 /// getTempLabel - Return the MCSymbol corresponding to the assembler temporary
 /// label with the specified name.
 MCSymbol *DwarfPrinter::getTempLabel(const char *Name) const {
-  return Asm->OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix())
-                                           + Name);
+  return Asm->OutContext.GetOrCreateTemporarySymbol
+     (Twine(MAI->getPrivateGlobalPrefix()) + Name);
 }
 
 
diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp
index 64134ce..32b1a7d 100644
--- a/lib/CodeGen/MachineBasicBlock.cpp
+++ b/lib/CodeGen/MachineBasicBlock.cpp
@@ -42,12 +42,11 @@
 /// getSymbol - Return the MCSymbol for this basic block.
 ///
 MCSymbol *MachineBasicBlock::getSymbol(MCContext &Ctx) const {
-  SmallString<60> Name;
   const MachineFunction *MF = getParent();
-  raw_svector_ostream(Name)
-    << MF->getTarget().getMCAsmInfo()->getPrivateGlobalPrefix() << "BB"
-    << MF->getFunctionNumber() << '_' << getNumber();
-  return Ctx.GetOrCreateSymbol(Name.str());
+  const char *Prefix = MF->getTarget().getMCAsmInfo()->getPrivateGlobalPrefix();
+  return Ctx.GetOrCreateTemporarySymbol(Twine(Prefix) + "BB" +
+                                        Twine(MF->getFunctionNumber()) + "_" +
+                                        Twine(getNumber()));
 }
 
 
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp
index 4377d5b..1e3cb1e 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -464,7 +464,9 @@
   SmallString<60> Name;
   raw_svector_ostream(Name)
     << Prefix << "JTI" << getFunctionNumber() << '_' << JTI;
-  return Ctx.GetOrCreateSymbol(Name.str());
+  if (isLinkerPrivate)
+    return Ctx.GetOrCreateSymbol(Name.str());
+  return Ctx.GetOrCreateTemporarySymbol(Name.str());
 }
 
 
diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index d127f53..6916831 100644
--- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -403,12 +403,15 @@
 
     // Add information about the stub reference to ELFMMI so that the stub
     // gets emitted by the asmprinter.
-    MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str());
+    MCSymbol *Sym = getContext().GetOrCreateTemporarySymbol(Name.str());
     MCSymbol *&StubSym = ELFMMI.getGVStubEntry(Sym);
     if (StubSym == 0) {
       Name.clear();
       Mang->getNameWithPrefix(Name, GV, false);
-      StubSym = getContext().GetOrCreateSymbol(Name.str());
+      if (GV->hasPrivateLinkage())
+        StubSym = getContext().GetOrCreateTemporarySymbol(Name.str());
+      else
+        StubSym = getContext().GetOrCreateSymbol(Name.str());
     }
 
     return TargetLoweringObjectFile::
@@ -749,12 +752,15 @@
 
     // Add information about the stub reference to MachOMMI so that the stub
     // gets emitted by the asmprinter.
-    MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str());
+    MCSymbol *Sym = getContext().GetOrCreateTemporarySymbol(Name.str());
     MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym);
     if (StubSym == 0) {
       Name.clear();
       Mang->getNameWithPrefix(Name, GV, false);
-      StubSym = getContext().GetOrCreateSymbol(Name.str());
+      if (GV->hasPrivateLinkage())
+        StubSym = getContext().GetOrCreateTemporarySymbol(Name.str());
+      else
+        StubSym = getContext().GetOrCreateSymbol(Name.str());
     }
 
     return TargetLoweringObjectFile::