From 201cbad62dca645abcee1fd01df3e29bf5fe0deb Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Thu, 13 Mar 2014 16:46:36 +0000 Subject: Prevent outputting HeaderFileInfos for files not used as headers When building an AST file, we don't want to output HeaderFileInfo structures for files that are not actually used as headers in the current context. This can lead to assuming that unrelated files have include counts of 0, defeating multiple-include prevention. This is accomplished by adding an IsValid bit to the HFI. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203813 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/HeaderSearch.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/Lex/HeaderSearch.cpp') diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 97bff4f277..46d4d41b9a 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -988,9 +988,21 @@ HeaderFileInfo &HeaderSearch::getFileInfo(const FileEntry *FE) { HeaderFileInfo &HFI = FileInfo[FE->getUID()]; if (ExternalSource && !HFI.Resolved) mergeHeaderFileInfo(HFI, ExternalSource->GetHeaderFileInfo(FE)); + HFI.IsValid = 1; return HFI; } +bool HeaderSearch::tryGetFileInfo(const FileEntry *FE, HeaderFileInfo &Result) const { + if (FE->getUID() >= FileInfo.size()) + return false; + const HeaderFileInfo &HFI = FileInfo[FE->getUID()]; + if (HFI.IsValid) { + Result = HFI; + return true; + } + return false; +} + bool HeaderSearch::isFileMultipleIncludeGuarded(const FileEntry *File) { // Check if we've ever seen this file as a header. if (File->getUID() >= FileInfo.size()) -- cgit v1.2.3