From d8d94652b2345f596b3a62dbcd32cbb0a1a50856 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Wed, 30 Mar 2016 22:17:28 +0000 Subject: [PATCH] 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. llvm-svn: 264936 --- llvm/lib/IR/AsmWriter.cpp | 22 +++------------------- llvm/test/Assembler/source-filename-backslash.ll | 4 ++-- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 4750cf6..c64291cb 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -2203,22 +2203,6 @@ void AssemblyWriter::writeOperandBundles(ImmutableCallSite CS) { 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 &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 Module *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(); diff --git a/llvm/test/Assembler/source-filename-backslash.ll b/llvm/test/Assembler/source-filename-backslash.ll index 27b5198..8669401 100644 --- a/llvm/test/Assembler/source-filename-backslash.ll +++ b/llvm/test/Assembler/source-filename-backslash.ll @@ -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" -- 2.7.4