summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHal Finkel <hfinkel@anl.gov>2017-08-16 21:34:27 +0000
committerHal Finkel <hfinkel@anl.gov>2017-08-16 21:34:27 +0000
commit67814df3ea7e8147e3a3b27825659784dfe13a0d (patch)
tree09993af95c6c7e1f4cc029ad4c5e7dd8a3ecfcca
parent2414429962a6625058ce86ccf4e64bb9821b14fb (diff)
downloadbcm5719-llvm-67814df3ea7e8147e3a3b27825659784dfe13a0d.tar.gz
bcm5719-llvm-67814df3ea7e8147e3a3b27825659784dfe13a0d.zip
Base optimization-record file names on the final output
Using Output.getFilename() to construct the file name used for optimization recording in Clang::ConstructJob, when -c is provided, does not work correctly if we're not using the integrated assembler. With -no-integrated-as (or -save-temps) Output.getFilename() gives the name of the temporary assembly file, not the final output file. Instead, use the final output (as provided by -o). If this is not available, then fall back to using a name based on the input file. Fixes PR31532. llvm-svn: 311041
-rw-r--r--clang/lib/Driver/ToolChains/Clang.cpp11
-rw-r--r--clang/test/Driver/opt-record.c7
2 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index f817c9fc855..35dcf206abb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4261,10 +4261,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(A->getValue());
} else {
SmallString<128> F;
- if (Output.isFilename() && (Args.hasArg(options::OPT_c) ||
- Args.hasArg(options::OPT_S))) {
- F = Output.getFilename();
- } else {
+
+ if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
+ if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
+ F = FinalOutput->getValue();
+ }
+
+ if (F.empty()) {
// Use the input filename.
F = llvm::sys::path::stem(Input.getBaseInput());
diff --git a/clang/test/Driver/opt-record.c b/clang/test/Driver/opt-record.c
index 6e684878d44..e261d16260e 100644
--- a/clang/test/Driver/opt-record.c
+++ b/clang/test/Driver/opt-record.c
@@ -1,6 +1,13 @@
// RUN: %clang -### -S -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
// RUN: %clang -### -c -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c -o FOO.o -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -no-integrated-as -S -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -no-integrated-as -c -o FOO.o -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -save-temps -S -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -save-temps -c -o FOO.o -fsave-optimization-record %s 2>&1 | FileCheck %s
// RUN: %clang -### -c -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
+// RUN: %clang -### -no-integrated-as -c -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
+// RUN: %clang -### -save-temps -c -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
// RUN: %clang -### -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
// RUN: %clang -### -S -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
// RUN: %clang -### -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
OpenPOWER on IntegriCloud