Commit Graph

47 Commits

Author SHA1 Message Date
Jan Svoboda 0f7d4105c6 [clang][deps] Only generate absolute paths when asked to
Add option to `clang-scan-deps` to enable/disable generation of command-line arguments with absolute paths. This is essentially a revert of D100533, but with improved naming and added test.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D101051
2021-04-26 10:53:41 +02:00
Jan Svoboda 850e01a34d [clang][deps] Check extra args in tests
These flags are being generated by `clang-scan-deps` and it makes sense to ensure it keeps doing so.
2021-04-22 14:10:08 +02:00
Jan Svoboda 398f253400 [clang][deps] Include "-cc1" in the arguments
To simplify tools consuming dependency scanning results, prepend the "-cc1" argument by default.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D100942
2021-04-22 10:57:56 +02:00
Sylvain Audi 8c16c8b7ef Reland "[clang-scan-deps] Add support for clang-cl"
This reverts commit 199c397482.
This time, clang-scan-deps's search for output argument in clang-cl command line will now ignore arguments preceded by "-Xclang".
That way, it won't detect a /o argument in "-Xclang -ivfsoverlay -Xclang /opt/subpath"

Initial patch description:
clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

Differential Revision: https://reviews.llvm.org/D92191
2021-04-21 07:56:39 -04:00
Alexandre Ganea 199c397482 Revert "[clang-scan-deps] Add support for clang-cl"
This reverts commit bb26fa8c28.
2021-04-19 17:45:18 -04:00
Jan Svoboda 0a92e09c07 [clang][deps] Generate the full command-line for modules
This patch uses the new `CompilerInvocation::generateCC1CommandLine` to generate the full canonical command line for modular dependencies, instead of only appending additional arguments.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D100534
2021-04-19 14:32:49 +02:00
Jan Svoboda 2b73565210 [clang][deps] Remove the -full-command-line flag
This patch removes the `-full-command-line` option from `clang-scan-deps`. It's only used with `-format=experimental-full`, where omitting the command lines doesn't make much sense. There are no tests without `-full-command-line`.

Depends on D100531.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D100533
2021-04-19 12:28:02 +02:00
Jan Svoboda 32219c8c44 [clang][deps] Simplify function discovering .pcm and .modulemap files
This patch simplifies (and renames) the `appendCommonModuleArguments` function.

It no longer tries to construct the command line for explicitly building modules. Instead, it only performs the DFS traversal of modular dependencies and queries the callbacks to collect paths to `.pcm` and `.modulemap` files.

This makes it more flexible and usable in two contexts:

* Generating additional command line arguments for the main TU in modular build. The `std::vector<std::string>` output parameters can be used to manually generate appropriate command line flags.
* Generate full command line for a module. The output parameters can be the corresponding parts of `CompilerInvocation`. (In a follow-up patch.)

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D100531
2021-04-19 12:11:39 +02:00
Sylvain Audi bb26fa8c28 [clang-scan-deps] Add support for clang-cl
clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

Differential Revision: https://reviews.llvm.org/D92191
2021-04-17 14:22:51 -04:00
Sylvain Audi 488a19d00c [clang-scan-deps] Support double-dashes in clang command lines
This fixes argument injection in clang command lines, by adding them before "--".

Previously, the arguments were injected at the end of the command line and could be added after "--", which would be wrongly interpreted as input file paths.

This fix is needed for a subsequent patch, see D92191.

Differential Revision: https://reviews.llvm.org/D95099
2021-04-17 14:22:51 -04:00
Sylvain Audi 5f53d28fa6 Revert "[clang-scan-deps] Support clang-cl"
Reverting, as it breaks build on mac.

This reverts commit 640ad76911.
2020-12-14 13:32:38 -05:00
Sylvain Audi 640ad76911 [clang-scan-deps] Support clang-cl
clang-scan-deps contains some command line parsing and modifications.
This patch adds support for clang-cl command options.

Differential Revision: https://reviews.llvm.org/D92191
2020-12-14 12:06:05 -05:00
Sylvain Audi 79ba7967f4 [clang-scan-deps] Improve argument parsing to find target object file path.
Support the joined version of -o (-ofilepath), and ensure we use the last provided -o option.

Differential Revision: https://reviews.llvm.org/D92330
2020-12-01 15:04:15 -05:00
Sylvain Audi 79105e4644 [clang-scan-deps] Fix for input file given as relative path in compilation database "command" entry.
Differential Revision: https://reviews.llvm.org/D91204
2020-11-12 08:48:17 -05:00
Michael Spencer 356a4b433b [clang][clang-scan-deps] Aggregate the full dependency information.
Differential Revision: https://reviews.llvm.org/D70268

This is a recommit of f978ea4983 with a fix for the PowerPC failure.

The issue was that:
* `CompilerInstance::ExecuteAction` calls
  `getTarget().adjust(getLangOpts());`.
* `PPCTargetInfo::adjust` changes `LangOptions::HasAltivec`.
* This happens after the first few calls to `getModuleHash`.

There’s even a FIXME saying:
```
  // FIXME: We shouldn't need to do this, the target should be immutable once
  // created. This complexity should be lifted elsewhere.
```

This only showed up on PowerPC because it's one of the few targets that
almost always changes a hashed langopt.

I looked into addressing the fixme, but that would be a much larger
change, and it's not the only thing that happens in `ExecuteAction` that
can change the module context hash. Instead I changed the code to not
call `getModuleHash` until after it has been modified in `ExecuteAction`.
2020-01-23 16:58:50 -08:00
Michael Spencer 5bcd34a03f Revert "[clang][clang-scan-deps] Aggregate the full dependency information."
This reverts commit f978ea4983.

It broke clang-ppc64be-linux, but not sure why yet.
2019-12-11 16:35:55 -08:00
Michael Spencer f978ea4983 [clang][clang-scan-deps] Aggregate the full dependency information.
Differential Revision: https://reviews.llvm.org/D70268
2019-12-11 14:40:51 -08:00
Alex Lorenz 389530524b [clang-scan-deps] do not skip empty #if/#elif in the minimizer to avoid missing `__has_include` dependencies
This patch makes the minimizer more conservative to avoid missing dependency files that are brought in by __has_include
PP expressions that occur in a condition of an #if/#elif that was previously skipped. The __has_include PP expressions
can be used in an #if/#elif either directly, or through macro expansion, so we can't detect them at the time of minimization.

Differential Revision: https://reviews.llvm.org/D70936
2019-12-02 18:47:22 -08:00
Michael Spencer d816d9bdc5 [clang][ScanDeps] Fix issue with multiple commands with the same input.
Previously, given a CompilationDatabase with two commands for the same
source file we would report that file twice with the union of the
dependencies for each command both times.

This was due to the way `ClangTool` runs actions given an input source
file (see the comment in `DependencyScanningTool.cpp`). This commit adds
a `SingleCommandCompilationDatabase` that is created with each
`CompileCommand` in the original CDB, which is then used for each
`ClangTool` invocation. This gives us a single run of
`DependencyScanningAction` per `CompileCommand`.

I looked at using `AllTUsToolExecutor` which is a parallel tool
executor, but I'm not sure it's suitable for `clang-scan-deps` as it
does a lot more sharing of state than `AllTUsToolExecutor` expects.

Differential Revision: https://reviews.llvm.org/D69643
2019-10-31 14:22:01 -07:00
Reid Kleckner 52194350cf Disable new clang-scan-deps test on Windows due to backslash path matching problems 2019-10-30 15:51:34 -07:00
Michael Spencer 33a745e6fe [clang][clang-scan-deps] Add support for extracting full module dependencies.
This is a recommit of d8a4ef0e68 with the nondeterminism fixed.

This adds experimental support for extracting a Clang module dependency graph
from a compilation database. The output format is experimental and will change.
It is currently a concatenation of JSON outputs for each compilation. Future
patches will change this to deduplicate modules between compilations.

Differential Revision: https://reviews.llvm.org/D69420
2019-10-30 15:27:27 -07:00
Michael Spencer 1c88d66223 Revert "[clang][clang-scan-deps] Add support for extracting full module dependencies."
This reverts commit d8a4ef0e68.

This commit broke some of the bots. I believe it's due to nondeterminism. Will fix and recommit.
2019-10-30 15:16:38 -07:00
Michael Spencer d8a4ef0e68 [clang][clang-scan-deps] Add support for extracting full module dependencies.
This adds experimental support for extracting a Clang module dependency graph
from a compilation database. The output format is experimental and will change.
It is currently a concatenation of JSON outputs for each compilation. Future
patches will change this to deduplicate modules between compilations.

Differential Revision: https://reviews.llvm.org/D69420
2019-10-30 14:46:17 -07:00
Michael Spencer dddec1f184 [clang][clang-scan-deps] Add -fcxx-modules to test for Darwin. 2019-10-28 17:37:25 -07:00
Michael Spencer 9ab6d8236b [clang-scan-deps] Add basic support for modules.
This fixes two issues that prevent simple uses of modules from working.

* We would previously minimize _every_ file opened by clang, even module maps
  and module pcm files. Now we only minimize files with known extensions. It
  would be better if we knew which files clang intended to open as a source
  file, but this works for now.

* We previously cached every lookup, even failed lookups. This is a problem
  because clang stats the module cache directory before building a module and
  creating that directory. If we cache that failure then the subsequent pcm
  load doesn't see the module cache and fails.

Overall this still leaves us building minmized modules on disk during scanning.
This will need to be improved eventually for performance, but this is correct,
and works for now.

Differential Revision: https://reviews.llvm.org/D68835
2019-10-24 16:19:11 -07:00
Kousik Kumar 9e7e36d4c2 Revert "Include sanitize blacklist and other extra deps as part of scan-deps output"
This test is failing on Windows bots, revert for now (will check the right fix and retry the patch).

Summary: This reverts commit 962ca076e5.

Reviewers: Bigcheese, jkorous, arphaman

Subscribers: dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69079

llvm-svn: 375079
2019-10-17 04:50:12 +00:00
Kousik Kumar 962ca076e5 Include sanitize blacklist and other extra deps as part of scan-deps output
Summary:
Clang's -M mode includes these extra dependencies in its output and clang-scan-deps
should have equivalent behavior, so adding these extradeps to output just like
how its being done for ".d" file generation mode.

Reviewers: arphaman, dexonsmith, Bigcheese, jkorous

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69017

llvm-svn: 375074
2019-10-17 02:14:44 +00:00
Jan Korous 9d0a84f5f3 [NFC] Fix ClangScanDeps/static-analyzer.c test on Windows
Follow-up to c5d14b5c6f

llvm-svn: 374821
2019-10-14 21:06:11 +00:00
Jan Korous c5d14b5c6f [clang-scan-deps] Support for clang --analyze in clang-scan-deps
The goal is to have 100% fidelity in clang-scan-deps behavior when
--analyze is present in compilation command.

At the same time I don't want to break clang-tidy which expects
__static_analyzer__ macro defined as built-in.

I introduce new cc1 options (-setup-static-analyzer) that controls
the macro definition and is conditionally set in driver.

Differential Revision: https://reviews.llvm.org/D68093

llvm-svn: 374815
2019-10-14 20:15:01 +00:00
Kousik Kumar 4abac53302 In openFileForRead don't cache erroneous entries if the error relates to them being directories. Add tests.
Summary:
It seems that when the CachingFileSystem is first given a file to open that is actually a directory, it incorrectly
caches that path to be errenous and throws an error when subsequently a directory open call is made for the same
path.
This change makes it so that we do NOT cache a path if it turns out we asked for a file when its a directory.

Reviewers: arphaman

Subscribers: dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68193

llvm-svn: 374366
2019-10-10 15:29:01 +00:00
Alex Lorenz 172e8a7a5d [clang-scan-deps] strip the --serialize-diagnostics argument
This ensures that clang-scan-deps won't write out diagnostics when
scanning dependencies.

llvm-svn: 372444
2019-09-21 00:17:26 +00:00
Alex Lorenz ee30b0ecc2 [clang-scan-deps] Fix for headers having the same name as a directory
Scan deps tool crashes when called on a C++ file, containing an include
that has the same name as a directory.
The tool crashes since it finds foo/dir and tries to read that as a file and fails.

Patch by: kousikk (Kousik Kumar)

Differential Revision: https://reviews.llvm.org/D67091

llvm-svn: 371903
2019-09-13 22:12:02 +00:00
Alex Lorenz 57a014d31f [clang-scan-deps] remove dots and dots dots from the reported file dependency paths
This resolves differences observed on LLVM + Clang when running the comparison between canonical
dependencies (full preprocessing, no file manager reused), and dependencies obtained
when the file manager was reused between the full preprocessing invocations.

llvm-svn: 371751
2019-09-12 18:03:24 +00:00
Jan Korous b51a285c4c [clang-scan-deps] Add dependency targets
Differential Revision: https://reviews.llvm.org/D67475

llvm-svn: 371697
2019-09-12 00:48:45 +00:00
Alex Lorenz ca6e60971e [clang-scan-deps] add skip excluded conditional preprocessor block preprocessing optimization
This commit adds an optimization to clang-scan-deps and clang's preprocessor that skips excluded preprocessor
blocks by bumping the lexer pointer, and not lexing the tokens until reaching appropriate #else/#endif directive.
The skip positions and lexer offsets are computed when the file is minimized, directly from the minimized tokens.

On an 18-core iMacPro with macOS Catalina Beta I got 10-15% speed-up from this optimization when running clang-scan-deps on
the compilation database for a recent LLVM and Clang (3511 files).

Differential Revision: https://reviews.llvm.org/D67127

llvm-svn: 371656
2019-09-11 20:40:31 +00:00
Jan Korous 9607f5d802 [clang-scan-deps][NFC] Fix tests - prevent FileCheck matching test dir path
Differential Revision: https://reviews.llvm.org/D67379

llvm-svn: 371578
2019-09-11 00:30:26 +00:00
Alex Lorenz 0377ca641c Introduce a DirectoryEntryRef that stores both a reference and an
accessed name to the directory entry

This commit introduces a parallel API that returns a DirectoryEntryRef
to the FileManager, similar to the parallel FileEntryRef API. All
uses will have to be update in follow-up patches. The immediate use of the new API in this
patch fixes the issue where a file manager was reused in clang-scan-deps,
but reported an different file path whenever a framework lookup was done through a symlink.

Differential Revision: https://reviews.llvm.org/D67026

llvm-svn: 370562
2019-08-31 01:26:04 +00:00
Alex Lorenz 3944c9638e [clang-scan-deps] reuse the file manager across invocations of
the dependency scanner on a single worker thread

This behavior can be controlled using the new `-reuse-filemanager` clang-scan-deps
option. By default the file manager is reused.

The added test/ClangScanDeps/symlink.cpp is able to pass with
the reused filemanager after the related FileEntryRef changes
landed earlier. The test test/ClangScanDeps/subframework_header_dir_symlink.m
still fails when the file manager is reused (I run the FileCheck with not to
make it PASS). I will address this in a follow-up patch that improves
the DirectoryEntry name modelling in the FileManager.

llvm-svn: 370420
2019-08-29 22:56:38 +00:00
Alex Lorenz 3ffa688dfc clang-scan-deps: do not spawn threads when LLVM_ENABLE_THREADS is disabled
llvm-svn: 368640
2019-08-13 00:36:35 +00:00
Reid Kleckner 7859fed6ea Mark clang-scan-deps test as requiring thread support
Otherwise the test calls a pure virtual method and crashes. Perhaps this
could be improved.

llvm-svn: 368354
2019-08-08 21:45:59 +00:00
Alex Lorenz d27a5086a8 fix clang-scan-deps test to match filepaths on Windows
llvm-svn: 368092
2019-08-06 21:45:43 +00:00
Alex Lorenz e1f4c4aad2 [clang-scan-deps] Implementation of dependency scanner over minimized sources
This commit implements the fast dependency scanning mode in clang-scan-deps: the
preprocessing is done on files that are minimized using the dependency directives source minimizer.

A shared file system cache is used to ensure that the file system requests and source minimization
is performed only once. The cache assumes that the underlying filesystem won't change during the course
of the scan (or if it will, it will not affect the output), and it can't be evicted. This means that the
service and workers can be used for a single run of a dependency scanner, and can't be reused across multiple,
incremental runs. This is something that we'll most likely support in the future though.
Note that the driver still utilizes the underlying real filesystem.

This commit is also still missing the fast skipped PP block skipping optimization that I mentioned at EuroLLVM talk.
Additionally, the file manager is still not reused by the threads as well.

Differential Revision: https://reviews.llvm.org/D63907

llvm-svn: 368086
2019-08-06 20:43:25 +00:00
Alex Lorenz 2d57e7d657 [clang-scan-deps] use `-Wno-error` when scanning for dependencies
Warnings can be promoted to errors.
But that shouldn't prevent us from getting the dependencies!

Differential Revision: https://reviews.llvm.org/D64149

llvm-svn: 365065
2019-07-03 18:01:32 +00:00
Alex Lorenz d5f7196feb [clang-scan-deps] Introduce the DependencyScanning library with the
thread worker code and better error handling

This commit extracts out the code that will powers the fast scanning
worker into a new file in a new DependencyScanning library. The error
and output handling is improved so that the clients can gather
errors/results from the worker directly.

Differential Revision: https://reviews.llvm.org/D63681

llvm-svn: 364474
2019-06-26 21:11:51 +00:00
Alex Lorenz 459f733ef0 [clang-scan-deps] print the dependencies to stdout
and remove the need to use -MD options in the CDB

Differential Revision: https://reviews.llvm.org/D63579

llvm-svn: 364088
2019-06-21 18:24:55 +00:00
Alex Lorenz 7bfb43985f [test] NFC, udpate clang-scan-deps tests to not use -c to avoid driver issues when no integrated assembler is present
Caught by Douglas Yung.

llvm-svn: 363742
2019-06-18 21:36:30 +00:00
Alex Lorenz f36d83735e [clang-scan-deps] initial outline of the tool that runs preprocessor to find
dependencies over a JSON compilation database

This commit introduces an outline for the clang-scan-deps tool that will be
used to implement fast dependency discovery phase using implicit modules for
explicit module builds.

The initial version of the tool works by computing non-modular header dependencies
for files in the compilation database without any optimizations
(i.e. without source minimization from r362459).
The tool spawns a number of worker threads to run the clang compiler workers in parallel.

The immediate goal for clang-scan-deps is to create a ClangScanDeps library
which will be used to build up this tool to use the source minimization and
caching multi-threaded filesystem to implement the optimized non-incremental
dependency scanning phase for a non-modular build. This will allow us to do
benchmarks and comparisons for performance that the minimization and caching give us

Differential Revision: https://reviews.llvm.org/D60233

llvm-svn: 363204
2019-06-12 21:32:49 +00:00