]> granicus.if.org Git - clang/commitdiff
Fix invocation of Gold plugin with LTO after r355331
authorNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Wed, 13 Mar 2019 23:54:52 +0000 (23:54 +0000)
committerNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Wed, 13 Mar 2019 23:54:52 +0000 (23:54 +0000)
The above commit breaks the usage of PGO and LTO when -fprofile-use is
supplied without a path. This patch changes the usage of this argument
to be inline with its use in addPGOAndCoverageFlags().

Differential revision: https://reviews.llvm.org/D59304

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356111 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/CommonArgs.cpp
test/Driver/cspgo-lto.c [new file with mode: 0644]

index eb22f8d24f84ad7c34369aa3d470eea63a868a8d..2a99ce39fab21118615b255774293574f52fe952 100644 (file)
@@ -464,8 +464,12 @@ void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args,
       CmdArgs.push_back(
           Args.MakeArgString("-plugin-opt=cs-profile-path=default_%m.profraw"));
   } else if (ProfileUseArg) {
+    SmallString<128> Path(
+        ProfileUseArg->getNumValues() == 0 ? "" : ProfileUseArg->getValue());
+    if (Path.empty() || llvm::sys::fs::is_directory(Path))
+      llvm::sys::path::append(Path, "default.profdata");
     CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=cs-profile-path=") +
-                                         ProfileUseArg->getValue()));
+                                         Path));
   }
 
   // Need this flag to turn on new pass manager via Gold plugin.
diff --git a/test/Driver/cspgo-lto.c b/test/Driver/cspgo-lto.c
new file mode 100644 (file)
index 0000000..52d4f24
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: touch %t.o
+//
+// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto=thin \
+// RUN:   -fprofile-use 2>&1 | FileCheck %s
+
+// CHECK: -plugin-opt=cs-profile-path=default.profdata