[PATCH] D51060: [gold] -thinlto-object-suffix-replace: don't append new suffix if path does not end with old suffix

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 19:12:33 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL340380: [gold] -thinlto-object-suffix-replace: don't append new suffix if path does not… (authored by MaskRay, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D51060

Files:
  llvm/trunk/test/tools/gold/X86/thinlto_object_suffix_replace.ll
  llvm/trunk/tools/gold/gold-plugin.cpp


Index: llvm/trunk/test/tools/gold/X86/thinlto_object_suffix_replace.ll
===================================================================
--- llvm/trunk/test/tools/gold/X86/thinlto_object_suffix_replace.ll
+++ llvm/trunk/test/tools/gold/X86/thinlto_object_suffix_replace.ll
@@ -27,6 +27,17 @@
 ; RUN:    -shared %t1.thinlink.bc -o %t3
 ; RUN: diff %t1.o.thinlto.bc.orig %t1.o.thinlto.bc
 
+; If filename does not end with old suffix, no suffix change should occur,
+; so ".thinlto.bc" will simply be appended to the input file name.
+; RUN: rm -f %t1.thinlink.bc.thinlto.bc
+; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
+; RUN:    -m elf_x86_64 \
+; RUN:    --plugin-opt=thinlto \
+; RUN:    --plugin-opt=thinlto-index-only \
+; RUN:    --plugin-opt=thinlto-object-suffix-replace=".abc;.o" \
+; RUN:    -shared %t1.thinlink.bc -o /dev/null
+; RUN: ls %t1.thinlink.bc.thinlto.bc
+
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
Index: llvm/trunk/tools/gold/gold-plugin.cpp
===================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp
+++ llvm/trunk/tools/gold/gold-plugin.cpp
@@ -667,13 +667,9 @@
 /// suffix matching \p OldSuffix with \p NewSuffix.
 static std::string getThinLTOObjectFileName(StringRef Path, StringRef OldSuffix,
                                             StringRef NewSuffix) {
-  if (OldSuffix.empty() && NewSuffix.empty())
-    return Path;
-  StringRef NewPath = Path;
-  NewPath.consume_back(OldSuffix);
-  std::string NewNewPath = NewPath;
-  NewNewPath += NewSuffix;
-  return NewNewPath;
+  if (Path.consume_back(OldSuffix))
+    return (Path + NewSuffix).str();
+  return Path;
 }
 
 // Returns true if S is valid as a C language identifier.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51060.161877.patch
Type: text/x-patch
Size: 1791 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180822/d5bcaa34/attachment.bin>


More information about the llvm-commits mailing list