This is an archive of the discontinued LLVM Phabricator instance.

[clang][deps] Generate the full command-line for modules
ClosedPublic

Authored by jansvoboda11 on Apr 15 2021, 1:21 AM.

Details

Summary

This patch uses the new CompilerInvocation::generateCC1CommandLine to generate the full canonical command line for modular dependencies, instead of only appending additional arguments.

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Apr 15 2021, 1:21 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2021, 1:21 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dexonsmith added inline comments.Apr 15 2021, 4:35 PM
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
78–80

Looks like this will be a deep copy, but it doesn't look like it's being modified. Can this just be a const &, taken in the ModuleDeps constructor? Or is there a lifetime reason this needs to be as it is?

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
25

Should this call any of the resetNonModularOptions() functions, or are those intentionally omitted?

26–27

Should FrontendOpts gain a resetNonModularOptions()?

63

I think guaranteed copy elision means this won't be a deep copy of the return, but it might be nice to add a move constructor for CompilerInvocation so it's more obvious.

Share ModuleDeps::Invocation

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
78–80

It can't be const & for two reasons:

  1. The current code value-initializes ModuleDeps in two places and truly initializes it later in ModuleDepCollectorPP::handleTopLevelModule. We'd have to go with something like optional<reference_wrapper<CompilerInvocation>> to be able to delay the initialization.
  2. The lifetime of the CompilerInvocation is a bit wild, but the reference most likely wouldn't outlive ModuleDeps (depends on the client).

I think the best solution would be to extract the shared_ptr from CompilerInstance, share it across ModuleDeps instances and only do a deep copy when actually generating the command line.

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
25

My intent for this patch was to simply take the work @Bigcheese has done downstream with -remove-preceeding-explicit-module-build-incompatible-options and port it to CompilerInvocation.

Calling resetNonModularOptions() here would be the next step I intend to do in a future patch.

I also think disabling implicit module maps here is not correct, as that seems to disable inferred top-level modules.

26–27

Most likely yes. I'd like to look into it in a next patch.

63

That's intentional. The deep copy is performed inside the function.

Shouldn't the move constructor of CompilerInvocation be defaulted?

jansvoboda11 added inline comments.Apr 16 2021, 5:14 AM
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
63

s/defaulted/implicitly-defined/

dexonsmith accepted this revision.Apr 16 2021, 7:42 AM

LGTM, just a couple of other comments inline.

clang/include/clang/Frontend/CompilerInstance.h
230

Is get*Ptr() already used in CompilerInstance? If so, matching that style sounds great. Otherwise I have a slight preference for getShared*().

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
78–80

Using shared_ptr seems right given the lifetime issues.

FWIW, I think const CompilerInvocation* is probably simpler to work with than Optional<reference_wrapper<const CompilerInvocation>>.

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
63

Explicitly declaring a copy constructor suppresses the implicit move constructor. But adding a move with = default is probably all that's needed.

This revision is now accepted and ready to land.Apr 16 2021, 7:42 AM

Thanks for the review!

clang/include/clang/Frontend/CompilerInstance.h
230

Yes, this naming pattern is already used:

  • std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const
  • std::shared_ptr<Preprocessor> getPreprocessorPtr()

and getShared*() is not being used.

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
63

I see, thanks for pointing that out. I explicitly defaulted move constructor/assignment in D100473.

This revision was landed with ongoing or failed builds.Apr 19 2021, 5:32 AM
This revision was automatically updated to reflect the committed changes.