diff options
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 2 | ||||
-rw-r--r-- | clang/test/ClangScanDeps/response-file-clang-cl.c | 56 | ||||
-rw-r--r-- | clang/test/Driver/cl-options.c | 3 | ||||
-rw-r--r-- | clang/tools/clang-scan-deps/ClangScanDeps.cpp | 9 |
4 files changed, 66 insertions, 4 deletions
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 18de878..15cf58f 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1030,7 +1030,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA, // If user provided -o, that is the dependency target, except // when we are only generating a dependency file. - Arg *OutputOpt = Args.getLastArg(options::OPT_o); + Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo); if (OutputOpt && Output.getType() != types::TY_Dependencies) { DepTarget = OutputOpt->getValue(); } else { diff --git a/clang/test/ClangScanDeps/response-file-clang-cl.c b/clang/test/ClangScanDeps/response-file-clang-cl.c new file mode 100644 index 0000000..b543231 --- /dev/null +++ b/clang/test/ClangScanDeps/response-file-clang-cl.c @@ -0,0 +1,56 @@ +// Check that the scanner can adjust arguments by reading .rsp files in advance. + +// RUN: rm -rf %t +// RUN: split-file %s %t + +// First run the tests with a .cdb +// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json +// RUN: sed -e "s|DIR|%/t|g" %t/args_nested.template > %t/args_nested.rsp + +// RUN: cp %t/args_compilation.rsp %t/args.rsp +// RUN: clang-scan-deps --compilation-database %t/cdb.json > %t/deps.json +// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s + +// RUN: cp %t/args_preprocess.rsp %t/args.rsp +// RUN: clang-scan-deps --compilation-database %t/cdb.json > %t/deps.json +// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s + + +// Now run the tests again with a in-place compilation database +// RUN: cd %t + +// RUN: cp args_compilation.rsp args.rsp +// RUN: clang-scan-deps -o deps.json -- %clang_cl @args.rsp +// RUN: cat deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s + +// RUN: cp args_preprocess.rsp args.rsp +// RUN: clang-scan-deps -o deps.json -- %clang_cl @args.rsp +// RUN: cat deps.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s + +// Here we ensure that we got a qualified .obj with its full path, since that's what we're passing with /Fo +// CHECK: [[PREFIX]]/tu.obj: + +//--- cdb.json.template +[{ + "file": "DIR/tu.cpp", + "directory": "DIR", + "command": "clang-cl @DIR/args.rsp" +}] + +//--- args_compilation.rsp +@args_nested.rsp +/c + +//--- args_preprocess.rsp +@args_nested.rsp +/E + +//--- args_nested.template +/I include +tu.cpp +/FoDIR/tu.obj + +//--- include/header.h + +//--- tu.cpp +#include "header.h" diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index 75f49de..733f243 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -740,9 +740,10 @@ // NOCLANG-SAME: "-vectorize-slp" // NOCLANG-NOT: "--dependent-lib=msvcrt" -// RUN: %clang_cl -O2 -MD /clang:-fno-slp-vectorize /clang:-MD /clang:-MF /clang:my_dependency_file.dep -### -- %s 2>&1 | FileCheck -check-prefix=CLANG %s +// RUN: %clang_cl -O2 -MD /clang:-fno-slp-vectorize /clang:-MD /clang:-MF /clang:my_dependency_file.dep /c /Fo%/t/cl-options.obj -### -- %s 2>&1 | FileCheck -DPREFIX=%/t -check-prefix=CLANG %s // CLANG: "--dependent-lib=msvcrt" // CLANG-SAME: "-dependency-file" "my_dependency_file.dep" +// CLANG-SAME: "-MT" "[[PREFIX]]/cl-options.obj" // CLANG-NOT: "--dependent-lib=libcmt" // CLANG-NOT: "-vectorize-slp" diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp index f42af7e..036e57c8 100644 --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -86,6 +86,8 @@ static bool DeprecatedDriverCommand; static ResourceDirRecipeKind ResourceDirRecipe; static bool Verbose; static bool PrintTiming; +static llvm::BumpPtrAllocator Alloc; +static llvm::StringSaver Saver{Alloc}; static std::vector<const char *> CommandLine; #ifndef NDEBUG @@ -99,8 +101,6 @@ static bool RoundTripArgs = DoRoundTripDefault; static void ParseArgs(int argc, char **argv) { ScanDepsOptTable Tbl; llvm::StringRef ToolName = argv[0]; - llvm::BumpPtrAllocator Alloc; - llvm::StringSaver Saver{Alloc}; llvm::opt::InputArgList Args = Tbl.parseArgs(argc, argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) { llvm::errs() << Msg << '\n'; @@ -792,6 +792,11 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) { llvm::cl::PrintOptionValues(); + // Expand response files in advance, so that we can "see" all the arguments + // when adjusting below. + Compilations = expandResponseFiles(std::move(Compilations), + llvm::vfs::getRealFileSystem()); + // The command options are rewritten to run Clang in preprocessor only mode. auto AdjustingCompilations = std::make_unique<tooling::ArgumentsAdjustingCompilations>( |