[PATCH] D114173: [clang][modules] Apply local submodule visibility to includes

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 18 10:27:08 PST 2021


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

With this patch, the preprocessor tracks the set of included files on per-submodule basis with `-fmodules-local-submodule-visibility`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114173

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Modules/import-textual-noguard.mm


Index: clang/test/Modules/import-textual-noguard.mm
===================================================================
--- clang/test/Modules/import-textual-noguard.mm
+++ clang/test/Modules/import-textual-noguard.mm
@@ -1,7 +1,9 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -fmodules -fimplicit-module-maps -I%S/Inputs/import-textual/M2 -fmodules-cache-path=%t -x objective-c++ -fmodules-local-submodule-visibility %s -verify
 
-#include "A/A.h" // expected-error {{could not build module 'M'}}
+// expected-no-diagnostics
+
+#include "A/A.h"
 #include "B/B.h"
 
 typedef aint xxx;
Index: clang/lib/Lex/Preprocessor.cpp
===================================================================
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -1482,16 +1482,16 @@
     CurrentSubmodule = BuildingSubmoduleStack.back().M;
   IncludedFilesPerSubmodule[CurrentSubmodule].insert(File);
 
-  return IncludedFiles.insert(File).second;
+  return CurSubmoduleState->IncludedFiles.insert(File).second;
 }
 
 void Preprocessor::markTransitivelyIncluded(const FileEntry *File) {
-  IncludedFiles.insert(File);
+  CurSubmoduleState->IncludedFiles.insert(File);
 }
 
 /// Return true if this header has already been included.
 bool Preprocessor::alreadyIncluded(const FileEntry *File) const {
-  return IncludedFiles.count(File);
+  return CurSubmoduleState->IncludedFiles.count(File);
 }
 
 const Preprocessor::IncludedFilesSet *
Index: clang/include/clang/Lex/Preprocessor.h
===================================================================
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -752,6 +752,9 @@
     /// The macros for the submodule.
     MacroMap Macros;
 
+    /// The set of files that have been included in the submodule.
+    IncludedFilesSet IncludedFiles;
+
     /// The set of modules that are visible within the submodule.
     VisibleModuleSet VisibleModules;
 
@@ -771,10 +774,6 @@
   /// Files included outside of any module (e.g. in PCH) have nullptr key.
   llvm::DenseMap<Module *, IncludedFilesSet> IncludedFilesPerSubmodule;
 
-  /// The global set of files that have been included.
-  // TODO: Move this into SubmoduleState.
-  IncludedFilesSet IncludedFiles;
-
   /// The set of known macros exported from modules.
   llvm::FoldingSet<ModuleMacro> ModuleMacros;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114173.388256.patch
Type: text/x-patch
Size: 2368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211118/9609dbcd/attachment.bin>


More information about the cfe-commits mailing list