[PATCH] D95099: [clang-scan-deps] : Support -- in clang command lines.

Sylvain Audi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 21 13:40:20 PST 2021


saudi added inline comments.


================
Comment at: clang/test/ClangScanDeps/Inputs/regular_cdb.json:12-16
 {
   "directory": "DIR",
-  "command": "clang -E DIR/regular_cdb_input.cpp -IInputs -o adena.o",
+  "command": "clang -E -IInputs -o adena.o -- DIR/regular_cdb_input.cpp",
   "file": "DIR/regular_cdb_input.cpp"
 }
----------------
dexonsmith wrote:
> It's not obvious to me how this exercises the new `-resource-dir` logic. Can you walk me through it?
clang tools like `clang-scan-deps` may edit the provided clang command line, especially to override the resource directory with their own default value in case it is not found as an argument.

This patch avoids inserting new arguments after `--`, since they would be wrongly interpreted as extra input files.

By adding `--` in this test, we broadly verify that no argument inserted by `clang-scan-deps` is treated as an extra input file. `-resource-dir` is merely one possible case. 

Note that `-resource-dir` case is a bit special: `clang-scan-deps` will first try to force its value using the result of `clang -print-resource-dir`  (see `ClangScanDeps.cpp`).
Yet, this heuristic may fail (and it does in this clang-scan-deps test, where the clang command is not given as an absolute path). In that case `ClangTool` will also try to add `-resource-dir` (see `Tooling.cpp`).




================
Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:480
         }
+        AdjustedArgs.insert(AdjustedArgs.end(), ArgsEnd, Args.end());
         return AdjustedArgs;
----------------
dexonsmith wrote:
> Can we use `AdjustedArgs.append(LastFlag, Args.end())` here?
`AdjustedArgs` is of type `tooling::CommandLineArguments` which inherits from `std::vector`, it doesn't have `append()`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95099/new/

https://reviews.llvm.org/D95099



More information about the cfe-commits mailing list