[PATCH] D112915: WIP: [clang][modules] Granular tracking of includes

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 1 02:23:27 PDT 2021


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

When building a module consisting of submodules, the preprocessor keeps a "global" state that for each header file (`HeaderFileInfo`) tracks (amongst other things) the number of times it was included/imported. This information is serialized into the PCM file.

When importing such module (either the top-level module or any of its submodules), this number is merged into the state of the importing preprocessor.

This can incorrectly prevent imports of headers. Consider that submodule `M.A` imports header `H`. If a TU imports submodule `M.B` (that didn't import header `H`), subsequent import of header `H` in the current TU will be skipped, since the preprocessor thinks it already imported that header. However, submodule `M.B` doesn't contain the AST of header `H`, which leads to compilation errors.

This patch fixes this bug by making the number of times a header was included more granular and tracks it on per-submodule basis.

(This patch is an alternative approach to the same issue addressed in https://reviews.llvm.org/D104344.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112915

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/import-submodule-visibility/A.framework/Headers/A.h
  clang/test/Modules/Inputs/import-submodule-visibility/A.framework/Modules/module.modulemap
  clang/test/Modules/Inputs/import-submodule-visibility/B.framework/Headers/B1.h
  clang/test/Modules/Inputs/import-submodule-visibility/B.framework/Headers/B2.h
  clang/test/Modules/Inputs/import-submodule-visibility/B.framework/Modules/module.modulemap
  clang/test/Modules/Inputs/import-submodule-visibility/C/C.h
  clang/test/Modules/Inputs/import-submodule-visibility/C/module.modulemap
  clang/test/Modules/Inputs/import-submodule-visibility/D/D1.h
  clang/test/Modules/Inputs/import-submodule-visibility/D/D2.h
  clang/test/Modules/Inputs/import-submodule-visibility/D/module.modulemap
  clang/test/Modules/Inputs/import-submodule-visibility/Textual.h
  clang/test/Modules/import-submodule-visibility.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112915.383750.patch
Type: text/x-patch
Size: 26353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211101/d65f4402/attachment-0001.bin>


More information about the cfe-commits mailing list