[PATCH] D104036: [clang][deps] Prevent unintended modifications of the original TU command-line

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 10 07:54:53 PDT 2021


jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

One of the goals of the dependency scanner is to provide command-lines that can be used to build modular dependencies of a translation unit. The only modifications to these command-lines should be for the purposes of explicit modular build.

The current version of dependency scanner leaks its implementation details into the command-lines for modular dependencies.

The first problem is that the `clang-scan-deps` tool adjusts the original textual command-line (adding `-Eonly -M -MT <target> -sys-header-deps -Wno-error -o /dev/null `, removing `--serialize-diagnostics`) in order to set up the `DependencyScanning` library. This has been addressed in D103461 <https://reviews.llvm.org/D103461>, D104012 <https://reviews.llvm.org/D104012>, D104030 <https://reviews.llvm.org/D104030>, D104031 <https://reviews.llvm.org/D104031>, D104033 <https://reviews.llvm.org/D104033> and moved into the library which directly adjusts a `CompilerInvocation` instead.

The `DependencyScanning` library now received the unmodifies `CompilerInvocation`, sets it up internally and uses it for the implicit build.

To prevent leaking the implementation details to the resulting command-lines (which get generated from this `CompilerInvocation`), this patch immediately makes a deep copy of the original invocation, stores the copy and uses it to generate the command-lines instead of the modified one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104036

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Inputs/preserved-args/cdb.json.template
  clang/test/ClangScanDeps/Inputs/preserved-args/mod.h
  clang/test/ClangScanDeps/Inputs/preserved-args/module.modulemap
  clang/test/ClangScanDeps/Inputs/preserved-args/tu.c
  clang/test/ClangScanDeps/preserved-args.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104036.351174.patch
Type: text/x-patch
Size: 8910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210610/17b16a13/attachment-0001.bin>


More information about the cfe-commits mailing list