Author: hfinkel Date: Wed Aug 16 14:34:27 2017 New Revision: 311041 URL: http://llvm.org/viewvc/llvm-project?rev=311041&view=rev Log: 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. Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/test/Driver/opt-record.c Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=311041&r1=311040&r2=311041&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Aug 16 14:34:27 2017 @@ -4261,10 +4261,13 @@ void Clang::ConstructJob(Compilation &C, 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()); Modified: cfe/trunk/test/Driver/opt-record.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/opt-record.c?rev=311041&r1=311040&r2=311041&view=diff ============================================================================== --- cfe/trunk/test/Driver/opt-record.c (original) +++ cfe/trunk/test/Driver/opt-record.c Wed Aug 16 14:34:27 2017 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits