[PATCH] D49090: [ThinLTO] Escape module paths when printing

Chris Jackson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 9 10:45:29 PDT 2018


chrisjackson created this revision.
chrisjackson added a reviewer: tejohnson.
Herald added subscribers: dexonsmith, inglorion.

We have located a bug in AssemblyWriter::printModuleSummaryIndex(). This
function outputs path strings incorrectly. Backslashes in the string are not
correctly escaped. Hence, only windows environments are affected.

Consequently, if a path name contains a backslash followed by two hexadecimal
characters, the sequence is incorrectly interpreted when the output is read by
another component. This mangles the path and results in error.

This patch fixes this issue by calling printEscapedString() to output the paths.


https://reviews.llvm.org/D49090

Files:
  lib/IR/AsmWriter.cpp
  test/Assembler/asm-path-writer.ll


Index: test/Assembler/asm-path-writer.ll
===================================================================
--- /dev/null
+++ test/Assembler/asm-path-writer.ll
@@ -0,0 +1,30 @@
+; REQUIRES: system-windows
+; RUN: mkdir -p %t.dir\f4folder
+; RUN: opt -module-summary %s -o %t.dir\f4folder\thinlto-alias.tmp.o
+; RUN: opt -module-summary %p\..\BitCode\Inputs\thinlto-alias.ll -o %t.dir\f4folder\thinlto-alias.tmp2.o
+; RUN: llvm-lto -thinlto -o %t.dir\f4folder\thinlto-alias %t.dir\f4folder\thinlto-alias.tmp.o %t.dir\f4folder\thinlto-alias.tmp2.o
+; RUN: llvm-dis  %t.dir\f4folder\thinlto-alias.thinlto.bc -o %t.dir\f4folder\thinlto-alias.thinlto.dis
+; RUN: llvm-as %t.dir\f4folder\thinlto-alias.thinlto.dis
+
+; ModuleID = 'thinlto-function-summary-callgraph.ll'
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nounwind uwtable
+define i32 @main() {
+entry:
+    call void (...) @analias()
+    ret i32 0
+}
+
+declare void @analias(...)
+
+; DIS: ^0 = module: (path: "{{.*}}", hash: (0, 0, 0, 0, 0))
+; DIS: ^1 = gv: (name: "analias", summaries: (alias: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^2))) ; guid = 12695095382722328222
+; DIS: ^2 = gv: (name: "aliasee", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 1))) ; guid = 17407585008595848568
+
+; COMBINED-DIS: ^0 = module: (path: "{{.*}}thinlto-alias.ll.tmp.o", hash: (0, 0, 0, 0, 0))
+; COMBINED-DIS: ^1 = module: (path: "{{.*}}thinlto-alias.ll.tmp2.o", hash: (0, 0, 0, 0, 0))
+; COMBINED-DIS: ^2 = gv: (guid: 12695095382722328222, summaries: (alias: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), aliasee: ^4)))
+; COMBINED-DIS: ^3 = gv: (guid: 15822663052811949562, summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 2, calls: ((callee: ^2)))))
+; COMBINED-DIS: ^4 = gv: (guid: 17407585008595848568, summaries: (function: (module: ^1, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0), insts: 1)))
Index: lib/IR/AsmWriter.cpp
===================================================================
--- lib/IR/AsmWriter.cpp
+++ lib/IR/AsmWriter.cpp
@@ -2618,8 +2618,9 @@
   unsigned i = 0;
   for (auto &ModPair : moduleVec) {
     Out << "^" << i++ << " = module: (";
-    Out << "path: \"" << ModPair.first << "\"";
-    Out << ", hash: (";
+    Out << "path: \"";
+    printEscapedString(ModPair.first, Out);
+    Out << "\", hash: (";
     FieldSeparator FS;
     for (auto Hash : ModPair.second)
       Out << FS << Hash;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49090.154637.patch
Type: text/x-patch
Size: 2715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180709/4a486302/attachment.bin>


More information about the llvm-commits mailing list