Print quoted backslashes in LLVM IR as \\ instead of \5C

This improves readability of Windows path string literals in LLVM IR.
The LLVM assembler has supported \\ in IR strings for a long time, but
the lexer doesn't tolerate escaped quotes, so they have to be printed as
\22 for now.

llvm-svn: 374415
This commit is contained in:
Reid Kleckner 2019-10-10 18:31:57 +00:00
parent e9529a942a
commit 67d440b949
6 changed files with 10 additions and 9 deletions

View File

@ -60,7 +60,9 @@ void llvm::SplitString(StringRef Source,
void llvm::printEscapedString(StringRef Name, raw_ostream &Out) {
for (unsigned i = 0, e = Name.size(); i != e; ++i) {
unsigned char C = Name[i];
if (isPrint(C) && C != '\\' && C != '"')
if (C == '\\')
Out << '\\' << C;
else if (isPrint(C) && C != '"')
Out << C;
else
Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);

View File

@ -1,6 +1,6 @@
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
; CHECK: ^0 = module: (path: ".\5Cf4folder\5Cabc.o", hash: (0, 0, 0, 0, 0))
; CHECK: ^0 = module: (path: ".\\f4folder\\abc.o", hash: (0, 0, 0, 0, 0))
^0 = module: (path: ".\5Cf4folder\5Cabc.o", hash: (0, 0, 0, 0, 0))
^0 = module: (path: ".\5Cf4folder\\abc.o", hash: (0, 0, 0, 0, 0))
^1 = gv: (guid: 15822663052811949562, summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2)))

View File

@ -1,8 +1,7 @@
; Make sure that llvm-as/llvm-dis properly assemble/disassemble the
; source_filename.
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
; CHECK: source_filename = "C:\5Cpath\5Cwith\5Cbackslashes\5Ctest.cc"
source_filename = "C:\5Cpath\5Cwith\5Cbackslashes\5Ctest.cc"
; CHECK: source_filename = "C:\\path\\with\\backslashes\\test.cc"
source_filename = "C:\\path\\with\5Cbackslashes\\test.cc"

View File

@ -103,7 +103,7 @@ body: |
name: test2
body: |
bb.0.entry:
; CHECK: , @"\01Hello@$%09 \5C World,",
; CHECK: , @"\01Hello@$%09 \\ World,",
$rax = MOV64rm $rip, 1, _, @"\01Hello@$%09 \\ World,", _
$eax = MOV32rm killed $rax, 1, _, 0, _
RETQ $eax

View File

@ -109,7 +109,7 @@ TEST(StringExtrasTest, printEscapedString) {
std::string str;
raw_string_ostream OS(str);
printEscapedString("ABCdef123&<>\\\"'\t", OS);
EXPECT_EQ("ABCdef123&<>\\5C\\22'\\09", OS.str());
EXPECT_EQ("ABCdef123&<>\\\\\\22'\\09", OS.str());
}
TEST(StringExtrasTest, printHTMLEscaped) {

View File

@ -164,7 +164,7 @@ TEST_F(MDStringTest, PrintingComplex) {
std::string Str;
raw_string_ostream oss(Str);
s->print(oss);
EXPECT_STREQ("!\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str());
EXPECT_STREQ("!\"\\00\\0A\\22\\\\\\FF\"", oss.str().c_str());
}
typedef MetadataTest MDNodeTest;