-
Notifications
You must be signed in to change notification settings - Fork 341
[clang][include-tree] Load even spurious modular dependencies #8011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
clang/test/ClangScanDeps/modules-include-tree-implementation-transitive.c
Show resolved
Hide resolved
clang/test/ClangScanDeps/modules-include-tree-implementation-transitive.c
Show resolved
Hide resolved
Pushed new commit that approaches the fix from different angle. It introduces new include-tree node that attempts to mimic what happens in implicit builds and non-caching explicit builds: Spurious.pcm is loaded, the Missing submodule is found to be missing, and the header is included textually instead. Loading Spurious.pcm also loads Mod.pcm, so importing Mod for visibility only has the desired effect of making its symbols visible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we upstream the PPCallbacks change. Relatedly, should anywhere you have if (SuggestedModule && ModuleImported)
be simplified to if (ModuleImported)
? It seems like SuggestedModule
should never be null if we're importing it, right?
Yes, if this approach gets a green light, I'll upstream this change.
That's correct. I'll update any current uses of |
Sorry, I should've mentioned this is more of a proof-of-concept that I wanted to get some high-level feedback on. I'm happy to implement the TODO and deal with errors properly if we agree this approach makes sense. |
clang/test/ClangScanDeps/modules-include-tree-implementation-transitive.c
Show resolved
Hide resolved
3b2e935
to
ed3e1e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a couple of small suggestions
if (auto *Import = std::get_if<PPCachedActions::IncludeModule>(&Include)) { | ||
}; | ||
|
||
auto LoadModule = [&](const PPCachedActions::IncludeModule *Import) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe factor HandleIncludeMod
to call LoadModule
and make the diagnostic part conditional? The error-handling logic is sufficiently interesting to not want it repeated.
// RUN: FileCheck %s -input-file %t/tu-include-tree.txt -DPREFIX=%/t | ||
// CHECK: [[PREFIX]]/tu.m llvmcas:// | ||
// CHECK-NEXT: 1:1 <built-in> llvmcas:// | ||
// CHECK-NEXT: 2:1 (Module) Spurious.Missing [[PREFIX]]/frameworks/Spurious.framework/Headers/Missing.h llvmcas:// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should mark this as a spurious import explicitly in the output for readability. Either inline or you could split it across lines and indent the import + tree.
…allback (#81061) This patch provides more information to the `PPCallbacks::InclusionDirective()` hook. We now always pass the suggested module, regardless of whether it was actually imported or not. The extra `bool ModuleImported` parameter then denotes whether the header `#include` will be automatically translated into import the the module. The main change is in `clang/lib/Lex/PPDirectives.cpp`, where we take care to not modify `SuggestedModule` after it's been populated by `LookupHeaderIncludeOrImport()`. We now exclusively use the `SM` (`ModuleToImport`) variable instead, which has been equivalent to `SuggestedModule` until now. This allows us to use the original non-modified `SuggestedModule` for the callback itself. (This patch turns out to be necessary for swiftlang#8011).
cd70936
to
a3fdbdc
Compare
…allback (llvm#81061) This patch provides more information to the `PPCallbacks::InclusionDirective()` hook. We now always pass the suggested module, regardless of whether it was actually imported or not. The extra `bool ModuleImported` parameter then denotes whether the header `#include` will be automatically translated into import the the module. The main change is in `clang/lib/Lex/PPDirectives.cpp`, where we take care to not modify `SuggestedModule` after it's been populated by `LookupHeaderIncludeOrImport()`. We now exclusively use the `SM` (`ModuleToImport`) variable instead, which has been equivalent to `SuggestedModule` until now. This allows us to use the original non-modified `SuggestedModule` for the callback itself. (This patch turns out to be necessary for #8011). (cherry picked from commit da95d92)
With implicit modules, some modular dependencies can be "spurious". By that I mean that `#include "Header.h"` results in a PCM file load, but the header ends up being included textually anyways. (This can happen in situations that would trigger the `-Wincomplete-umbrella` warning.) This patch ensures this behavior is preserved with include-tree. Previously, include-tree would simply textually include the header file and skip the PCM file load. This now ensures consistent behavior in edge-cases like the one in the attached test case (with `-fmodule-name=X`). rdar://121220983 (cherry picked from commit b230339)
…allback (llvm#81061) This patch provides more information to the `PPCallbacks::InclusionDirective()` hook. We now always pass the suggested module, regardless of whether it was actually imported or not. The extra `bool ModuleImported` parameter then denotes whether the header `#include` will be automatically translated into import the the module. The main change is in `clang/lib/Lex/PPDirectives.cpp`, where we take care to not modify `SuggestedModule` after it's been populated by `LookupHeaderIncludeOrImport()`. We now exclusively use the `SM` (`ModuleToImport`) variable instead, which has been equivalent to `SuggestedModule` until now. This allows us to use the original non-modified `SuggestedModule` for the callback itself. (This patch turns out to be necessary for swiftlang#8011). Change-Id: I6f64614c4468ae4737b20609e065d69390d2e443
With implicit modules, some modular dependencies can be "spurious". By that I mean that
#include "Header.h"
results in a PCM file load, but the header ends up being included textually anyways. (This can happen in situations that would trigger the-Wincomplete-umbrella
warning.)This patch ensures this behavior is preserved with include-tree. Previously, include-tree would simply textually include the header file and skip the PCM file load. This now ensures consistent behavior in edge-cases like the one in the attached test case (with
-fmodule-name=X
).rdar://121220983