oontvoo updated this revision to Diff 249711. oontvoo added a comment. More typo correction
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75951/new/ https://reviews.llvm.org/D75951 Files: clang/include/clang/Lex/Preprocessor.h clang/lib/Lex/HeaderSearch.cpp
Index: clang/lib/Lex/HeaderSearch.cpp =================================================================== --- clang/lib/Lex/HeaderSearch.cpp +++ clang/lib/Lex/HeaderSearch.cpp @@ -1253,60 +1253,21 @@ // Get information about this file. HeaderFileInfo &FileInfo = getFileInfo(File); - // FIXME: this is a workaround for the lack of proper modules-aware support - // for #import / #pragma once - auto TryEnterImported = [&]() -> bool { - if (!ModulesEnabled) - return false; - // Ensure FileInfo bits are up to date. - ModMap.resolveHeaderDirectives(File); - // Modules with builtins are special; multiple modules use builtins as - // modular headers, example: - // - // module stddef { header "stddef.h" export * } - // - // After module map parsing, this expands to: - // - // module stddef { - // header "/path_to_builtin_dirs/stddef.h" - // textual "stddef.h" - // } - // - // It's common that libc++ and system modules will both define such - // submodules. Make sure cached results for a builtin header won't - // prevent other builtin modules to potentially enter the builtin header. - // Note that builtins are header guarded and the decision to actually - // enter them is postponed to the controlling macros logic below. - bool TryEnterHdr = false; - if (FileInfo.isCompilingModuleHeader && FileInfo.isModuleHeader) - TryEnterHdr = File->getDir() == ModMap.getBuiltinDir() && - ModuleMap::isBuiltinHeader( - llvm::sys::path::filename(File->getName())); - - // Textual headers can be #imported from different modules. Since ObjC - // headers find in the wild might rely only on #import and do not contain - // controlling macros, be conservative and only try to enter textual headers - // if such macro is present. - if (!FileInfo.isModuleHeader && - FileInfo.getControllingMacro(ExternalLookup)) - TryEnterHdr = true; - return TryEnterHdr; - }; - // If this is a #import directive, check that we have not already imported // this header. if (isImport) { // If this has already been imported, don't import it again. FileInfo.isImport = true; + } - // Has this already been #import'ed or #include'd? - if (FileInfo.NumIncludes && !TryEnterImported()) - return false; - } else { - // Otherwise, if this is a #include of a file that was previously #import'd - // or if this is the second #include of a #pragma once file, ignore it. - if (FileInfo.isImport && !TryEnterImported()) - return false; + if (FileInfo.isPragmaOnce || FileInfo.isImport){ + if (FileInfo.isModuleHeader && M != nullptr){ + if (PP.isIncludeVisibleInLocalModule(File, M)) return false; + else PP.setIncludeVisibleForHeader(File, M); + } else { + if(PP.isIncludeVisible(File)) return false; + else PP.setIncludeVisible(File); + } } // Next, check to see if the file is wrapped with #ifndef guards. If so, and Index: clang/include/clang/Lex/Preprocessor.h =================================================================== --- clang/include/clang/Lex/Preprocessor.h +++ clang/include/clang/Lex/Preprocessor.h @@ -51,6 +51,7 @@ #include <cstdint> #include <map> #include <memory> +#include <set> #include <string> #include <utility> #include <vector> @@ -743,6 +744,9 @@ /// The set of modules that are visible within the submodule. VisibleModuleSet VisibleModules; + /// The included header for the submodule. + std::set<const FileEntry*> IncludedFiles; + // FIXME: CounterValue? // FIXME: PragmaPushMacroInfo? }; @@ -1038,6 +1042,32 @@ OnToken = std::move(F); } + void setIncludeVisible(const FileEntry *File) { + CurSubmoduleState.IncludedFiles.insert(File); + } + + bool isIncludeVisible(const FileEntry *File) { + return CurSubmoduleState->IncludedFiles.find(File) + != CurSubmoduleState->IncludedFiles.end(); + } + + void setIncludeVisibleForModule(const FileEntry *File, Module *M) { + auto SubmoduleIter = Submodules.find(M); + // Can't find the module. Maybe something is wrong. + if (SubmoduleIter == Submodules.end()) return; + + SubmoduleIter->second.IncludedFiles.insert(File); + } + + bool isIncludeVisibleInLocalModule(const FileEntry *File, Module *M) { + auto SubmoduleIter = Submodules.find(M); + if (SubmoduleIter == Submodules.end()) return false; + + return SubmoduleIter->second.IncludedFiles.find(File) + != SubmoduleIter->second.IncludedFiles.end(); + } + + bool isMacroDefined(StringRef Id) { return isMacroDefined(&Identifiers.get(Id)); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits