[llvm] r264936 - Use existing PrintEscapedString in AssemblyWriter

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 15:17:29 PDT 2016


Author: tejohnson
Date: Wed Mar 30 17:17:28 2016
New Revision: 264936

URL: http://llvm.org/viewvc/llvm-project?rev=264936&view=rev
Log:
Use existing PrintEscapedString in AssemblyWriter

r264884 introduced a helper to escape the backslashes in the source file
path, but I since discovered an existing mechanism to escape strings.

Modified:
    llvm/trunk/lib/IR/AsmWriter.cpp
    llvm/trunk/test/Assembler/source-filename-backslash.ll

Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=264936&r1=264935&r2=264936&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Wed Mar 30 17:17:28 2016
@@ -2203,22 +2203,6 @@ void AssemblyWriter::writeOperandBundles
   Out << " ]";
 }
 
-/// Escape any backslashes in the source file (e.g. Windows paths)
-/// before emitting, so that it is parsed properly by the lexer on input.
-static void EscapeBackslashes(std::string Str,
-                              SmallVectorImpl<char> &Res) {
-  for (auto C : Str) {
-    switch (C) {
-    default:
-      break;
-    case '\\':
-      Res.push_back('\\');
-      break;
-    }
-    Res.push_back(C);
-  }
-}
-
 void AssemblyWriter::printModule(const Module *M) {
   Machine.initialize();
 
@@ -2232,9 +2216,9 @@ void AssemblyWriter::printModule(const M
     Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
 
   if (!M->getSourceFileName().empty()) {
-    SmallString<128> EscapedName;
-    EscapeBackslashes(M->getSourceFileName(), EscapedName);
-    Out << "source_filename = \"" << EscapedName << "\"\n";
+    Out << "source_filename = \"";
+    PrintEscapedString(M->getSourceFileName(), Out);
+    Out << "\"\n";
   }
 
   const std::string &DL = M->getDataLayoutStr();

Modified: llvm/trunk/test/Assembler/source-filename-backslash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/source-filename-backslash.ll?rev=264936&r1=264935&r2=264936&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/source-filename-backslash.ll (original)
+++ llvm/trunk/test/Assembler/source-filename-backslash.ll Wed Mar 30 17:17:28 2016
@@ -4,5 +4,5 @@
 
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
 
-; CHECK: source_filename = "C:\\path\\with\\backslashes\\test.cc"
-source_filename = "C:\\path\\with\\backslashes\\test.cc"
+; CHECK: source_filename = "C:\5Cpath\5Cwith\5Cbackslashes\5Ctest.cc"
+source_filename = "C:\5Cpath\5Cwith\5Cbackslashes\5Ctest.cc"




More information about the llvm-commits mailing list