[PATCH] D75951: draft
Vy Nguyen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 10 12:00:45 PDT 2020
oontvoo created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
oontvoo retitled this revision from "Make a distinction between import and pragma-once, and keep tracked of already-included pragma-once files." to "draft ".
oontvoo edited the summary of this revision.
oontvoo added a reviewer: jyknight.
Make a distinction between import and pragma-once, and keep tracked of already-included pragma-once files.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75951
Files:
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Lex/HeaderSearch.cpp
Index: clang/lib/Lex/HeaderSearch.cpp
===================================================================
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -1253,8 +1253,6 @@
// 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;
@@ -1300,13 +1298,24 @@
FileInfo.isImport = true;
// Has this already been #import'ed or #include'd?
+ bool try_enter = TryEnterImported();
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())
+ // If the file has #pragma once guard and if it's been included
+ // then skip it.
+ if (FileInfo.isPragmaOnce) {
+ auto &it = included_pragma_files.find(FileEntry);
+ if (it != included_pragma_files.end() && it->second) {
+ return false;
+ } else {
+ it->second = true;
+ }
+ } else if (FileInfo.isImport && !TryEnterImported) {
+ // Otherwise, if this is a #include of a file that was previously
+ // #import'd ignore it.
return false;
+ }
}
// Next, check to see if the file is wrapped with #ifndef guards. If so, and
Index: clang/include/clang/Lex/HeaderSearch.h
===================================================================
--- clang/include/clang/Lex/HeaderSearch.h
+++ clang/include/clang/Lex/HeaderSearch.h
@@ -250,6 +250,9 @@
/// Entity used to look up stored header file information.
ExternalHeaderFileInfoSource *ExternalSource = nullptr;
+ // Set of #pragma_once file already seen.
+ llvm::DenseMap<const FileEntry *, bool> included_pragma_files;
+
public:
HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
SourceManager &SourceMgr, DiagnosticsEngine &Diags,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75951.249463.patch
Type: text/x-patch
Size: 2133 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200310/76a9f6d5/attachment.bin>
More information about the cfe-commits
mailing list