-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][modules] Track Included Files Per Submodule #170215
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
Open
qiongsiwu
wants to merge
2
commits into
llvm:main
Choose a base branch
from
qiongsiwu:eng_151926891_02
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+215
−30
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2346,21 +2346,34 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, | |
| HeaderFileInfo HFI; | ||
| unsigned Flags = *d++; | ||
|
|
||
| OptionalFileEntryRef FE; | ||
| bool Included = (Flags >> 6) & 0x01; | ||
| if (Included) | ||
| if ((FE = getFile(key))) | ||
| // Not using \c Preprocessor::markIncluded(), since that would attempt to | ||
| // deserialize this header file info again. | ||
| Reader.getPreprocessor().getIncludedFiles().insert(*FE); | ||
|
|
||
| // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp. | ||
| HFI.isImport |= (Flags >> 5) & 0x01; | ||
| HFI.isPragmaOnce |= (Flags >> 4) & 0x01; | ||
| HFI.DirInfo = (Flags >> 1) & 0x07; | ||
| HFI.LazyControllingMacro = Reader.getGlobalIdentifierID( | ||
| M, endian::readNext<IdentifierID, llvm::endianness::little>(d)); | ||
|
|
||
| auto FE = getFile(key); | ||
| Preprocessor &PP = Reader.getPreprocessor(); | ||
| ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); | ||
|
|
||
| unsigned IncludedCount = | ||
| endian::readNext<uint32_t, llvm::endianness::little, unaligned>(d); | ||
| for (unsigned I = 0; I < IncludedCount; ++I) { | ||
| uint32_t LocalSMID = | ||
| endian::readNext<uint32_t, llvm::endianness::little, unaligned>(d); | ||
| if (!FE) | ||
| continue; | ||
|
|
||
| if (LocalSMID == 0) { | ||
| PP.markIncludedOnTopLevel(*FE); | ||
| } else { | ||
| SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); | ||
| Module *Mod = Reader.getSubmodule(GlobalSMID); | ||
| PP.markIncludedInModule(Mod, *FE); | ||
| } | ||
| } | ||
|
|
||
| assert((End - d) % 4 == 0 && | ||
| "Wrong data length in HeaderFileInfo deserialization"); | ||
| while (d != End) { | ||
|
|
@@ -2373,10 +2386,8 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, | |
| // implicit module import. | ||
| SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); | ||
| Module *Mod = Reader.getSubmodule(GlobalSMID); | ||
| ModuleMap &ModMap = | ||
| Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); | ||
|
|
||
| if (FE || (FE = getFile(key))) { | ||
| if (FE) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this change OK? |
||
| // FIXME: NameAsWritten | ||
| Module::Header H = {std::string(key.Filename), "", *FE}; | ||
| ModMap.addHeader(Mod, H, HeaderRole, /*Imported=*/true); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // This test checks that imports of headers that appeared in a different submodule than | ||
| // what is imported by the current TU don't affect the compilation. | ||
|
|
||
| // RUN: rm -rf %t | ||
| // RUN: split-file %s %t | ||
|
|
||
| //--- C/C.h | ||
| #include "Textual.h" | ||
| //--- C/module.modulemap | ||
| module C { header "C.h" } | ||
|
|
||
| //--- D/D1.h | ||
| #include "Textual.h" | ||
| //--- D/D2.h | ||
| //--- D/module.modulemap | ||
| module D { | ||
| module D1 { header "D1.h" } | ||
| module D2 { header "D2.h" } | ||
| } | ||
|
|
||
| //--- E/E1.h | ||
| #include "E2.h" | ||
| //--- E/E2.h | ||
| #include "Textual.h" | ||
| //--- E/module.modulemap | ||
| module E { | ||
| module E1 { header "E1.h" } | ||
| module E2 { header "E2.h" } | ||
| } | ||
|
|
||
| //--- Textual.h | ||
| #define MACRO_TEXTUAL 1 | ||
|
|
||
| //--- test_top.c | ||
| #import "Textual.h" | ||
| static int x = MACRO_TEXTUAL; | ||
|
|
||
| //--- test_sub.c | ||
| #import "D/D2.h" | ||
| #import "Textual.h" | ||
| static int x = MACRO_TEXTUAL; | ||
|
|
||
| //--- test_transitive.c | ||
| #import "E/E1.h" | ||
| #import "Textual.h" | ||
| static int x = MACRO_TEXTUAL; | ||
|
|
||
| // Simply loading a PCM file containing top-level module including a header does | ||
| // not prevent inclusion of that header in the TU. | ||
| // | ||
| // RUN: %clang_cc1 -fmodules -I %t -emit-module %t/C/module.modulemap -fmodule-name=C -o %t/C.pcm | ||
| // RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test_top.c -fmodule-file=%t/C.pcm | ||
|
|
||
| // Loading a PCM file and importing its empty submodule does not prevent | ||
| // inclusion of headers included by invisible sibling submodules. | ||
| // | ||
| // RUN: %clang_cc1 -fmodules -I %t -emit-module %t/D/module.modulemap -fmodule-name=D -o %t/D.pcm | ||
| // RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test_sub.c -fmodule-file=%t/D.pcm | ||
|
|
||
| // Loading a PCM file and importing a submodule does not prevent inclusion of | ||
| // headers included by some of its transitive un-exported dependencies. | ||
| // | ||
| // RUN: %clang_cc1 -fmodules -I %t -emit-module %t/E/module.modulemap -fmodule-name=E -o %t/E.pcm | ||
| // RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test_transitive.c -fmodule-file=%t/E.pcm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // RUN: rm -rf %t | ||
| // RUN: split-file %s %t | ||
|
|
||
| //--- frameworks/Textual.framework/Headers/Header.h | ||
| static int symbol; | ||
|
|
||
| //--- frameworks/FW.framework/Modules/module.modulemap | ||
| framework module FW { | ||
| umbrella header "FW.h" | ||
| export * | ||
| module * { export * } | ||
| } | ||
| //--- frameworks/FW.framework/Headers/FW.h | ||
| #import <FW/Sub1.h> | ||
| #import <FW/Sub2.h> | ||
| //--- frameworks/FW.framework/Headers/Sub1.h | ||
| //--- frameworks/FW.framework/Headers/Sub2.h | ||
| #import <Textual/Header.h> | ||
|
|
||
| //--- pch.modulemap | ||
| module __PCH { | ||
| header "pch.h" | ||
| export * | ||
| } | ||
| //--- pch.h | ||
| #import <FW/Sub1.h> | ||
|
|
||
| //--- tu.m | ||
| #import <Textual/Header.h> | ||
| int fn() { return symbol; } | ||
|
|
||
| // Compilation using the PCH regularly succeeds. The import of FW/Sub1.h in the | ||
| // PCH is treated textually due to -fmodule-name=FW. | ||
| // | ||
| // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fimplicit-module-maps -F %t/frameworks -fmodule-name=FW \ | ||
| // RUN: -emit-pch -x objective-c %t/pch.h -o %t/pch.h.gch | ||
| // | ||
| // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fimplicit-module-maps -F %t/frameworks -fmodule-name=FW \ | ||
| // RUN: -include-pch %t/pch.h.gch -fsyntax-only %t/tu.m | ||
|
|
||
| // Compilation using the PCH as precompiled module fails. The import of FW/Sub1.h | ||
| // in the PCH is translated to an import. Nothing is preventing that now that | ||
| // -fmodule-name=FW has been replaced with -fmodule-name=__PCH. | ||
| // | ||
| // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fimplicit-module-maps -F %t/frameworks \ | ||
| // RUN: -emit-module -fmodule-name=__PCH -x objective-c %t/pch.modulemap -o %t/pch.h.pcm | ||
| // | ||
| // Loading FW.pcm marks Textual/Header.h as imported (because it is imported in | ||
| // FW.Sub2), so the TU does not import it again. It's contents remain invisible, | ||
| // though. | ||
| // | ||
| // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/cache -fimplicit-module-maps -F %t/frameworks \ | ||
| // RUN: -include %t/pch.h -fmodule-map-file=%t/pch.modulemap -fsyntax-only %t/tu.m |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The TODO definitely needs to be resolved before landing this.