Skip to content

Commit 64ebf31

Browse files
committed
[HeaderSearch] Use isImport only for imported headers and not for #pragma once.
There is a separate field `isPragmaOnce` and when `isImport` combines both, it complicates HeaderFileInfo serialization as `#pragma once` is the inherent property of the header while `isImport` reflects how other headers use it. The usage of the header can be different in different contexts, that's why `isImport` requires tracking separate from `#pragma once`. Differential Revision: https://reviews.llvm.org/D104351
1 parent bb0fa3e commit 64ebf31

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TargetInfo;
5151
/// The preprocessor keeps track of this information for each
5252
/// file that is \#included.
5353
struct HeaderFileInfo {
54-
/// True if this is a \#import'd or \#pragma once file.
54+
/// True if this is a \#import'd file.
5555
unsigned isImport : 1;
5656

5757
/// True if this is a \#pragma once file.
@@ -450,11 +450,10 @@ class HeaderSearch {
450450
return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo;
451451
}
452452

453-
/// Mark the specified file as a "once only" file, e.g. due to
453+
/// Mark the specified file as a "once only" file due to
454454
/// \#pragma once.
455455
void MarkFileIncludeOnce(const FileEntry *File) {
456456
HeaderFileInfo &FI = getFileInfo(File);
457-
FI.isImport = true;
458457
FI.isPragmaOnce = true;
459458
}
460459

@@ -500,8 +499,7 @@ class HeaderSearch {
500499
/// This routine does not consider the effect of \#import
501500
bool isFileMultipleIncludeGuarded(const FileEntry *File);
502501

503-
/// Determine whether the given file is known to have ever been \#imported
504-
/// (or if it has been \#included and we've encountered a \#pragma once).
502+
/// Determine whether the given file is known to have ever been \#imported.
505503
bool hasFileBeenImported(const FileEntry *File) {
506504
const HeaderFileInfo *FI = getExistingFileInfo(File);
507505
return FI && FI->isImport;

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void HeaderSearch::PrintStats() {
9191
<< FileInfo.size() << " files tracked.\n";
9292
unsigned NumOnceOnlyFiles = 0, MaxNumIncludes = 0, NumSingleIncludedFiles = 0;
9393
for (unsigned i = 0, e = FileInfo.size(); i != e; ++i) {
94-
NumOnceOnlyFiles += FileInfo[i].isImport;
94+
NumOnceOnlyFiles += (FileInfo[i].isPragmaOnce || FileInfo[i].isImport);
9595
if (MaxNumIncludes < FileInfo[i].NumIncludes)
9696
MaxNumIncludes = FileInfo[i].NumIncludes;
9797
NumSingleIncludedFiles += FileInfo[i].NumIncludes == 1;
@@ -1325,7 +1325,7 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
13251325
} else {
13261326
// Otherwise, if this is a #include of a file that was previously #import'd
13271327
// or if this is the second #include of a #pragma once file, ignore it.
1328-
if (FileInfo.isImport && !TryEnterImported())
1328+
if ((FileInfo.isPragmaOnce || FileInfo.isImport) && !TryEnterImported())
13291329
return false;
13301330
}
13311331

0 commit comments

Comments
 (0)