[llvm-commits] [llvm] r81683 - /llvm/trunk/lib/MC/MCSymbol.cpp

Chris Lattner sabre at nondot.org
Sun Sep 13 11:11:09 PDT 2009


Author: lattner
Date: Sun Sep 13 13:11:09 2009
New Revision: 81683

URL: http://llvm.org/viewvc/llvm-project?rev=81683&view=rev
Log:
fix MCSymbol printing on darwin to exactly match the mangler (handling of \n and " in a symbol name).

Modified:
    llvm/trunk/lib/MC/MCSymbol.cpp

Modified: llvm/trunk/lib/MC/MCSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSymbol.cpp?rev=81683&r1=81682&r2=81683&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCSymbol.cpp (original)
+++ llvm/trunk/lib/MC/MCSymbol.cpp Sun Sep 13 13:11:09 2009
@@ -65,6 +65,23 @@
   }
 }
 
+/// PrintMangledQuotedName - On systems that support quoted symbols, we still
+/// have to escape some (obscure) characters like " and \n which would break the
+/// assembler's lexing.
+static void PrintMangledQuotedName(raw_ostream &OS, StringRef Str) {
+  OS << '"';
+
+  for (unsigned i = 0, e = Str.size(); i != e; ++i) {
+    if (Str[i] == '"')
+      OS << "_QQ_";
+    else if (Str[i] == '\n')
+      OS << "_NL_";
+    else
+      OS << Str[i];
+  }
+  OS << '"';
+}
+
 
 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
   if (MAI == 0 || !NameNeedsEscaping(getName(), *MAI)) {
@@ -72,14 +89,17 @@
     return;
   }
 
-  // On darwin and other systems that allow quoted names, just do that.
-  if (MAI->doesAllowQuotesInName()) {
-    OS << '"' << getName() << '"';
-    return;
-  }
-  
-  // Otherwise, we have to mangle the name.
-  PrintMangledName(OS, getName());
+  // On systems that do not allow quoted names, print with mangling.
+  if (!MAI->doesAllowQuotesInName())
+    return PrintMangledName(OS, getName());
+
+  // If the string contains a double quote or newline, we still have to mangle
+  // it.
+  if (getName().find('"') != std::string::npos ||
+      getName().find('\n') != std::string::npos)
+    return PrintMangledQuotedName(OS, getName());
+    
+  OS << '"' << getName() << '"';
 }
 
 void MCSymbol::dump() const {





More information about the llvm-commits mailing list