diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-09-17 05:35:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-09-17 05:35:18 +0000 |
commit | 5d1bee253c045dcb6cf914d4b56fabe31e1e5f28 (patch) | |
tree | 453efb0bf85e754407eaca98267b219cf146f233 /clang | |
parent | 1b4f1637fbcc9c72cf1c8e3836957f29c17b7b33 (diff) | |
download | bcm5719-llvm-5d1bee253c045dcb6cf914d4b56fabe31e1e5f28.tar.gz bcm5719-llvm-5d1bee253c045dcb6cf914d4b56fabe31e1e5f28.zip |
When we load header file information from the external source (i.e.,
the AST reader), merge that header file information with whatever
header file information we already have. Otherwise, we might forget
something we already knew (e.g., that the header was #import'd already).
llvm-svn: 139979
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 36 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/point.h | 2 | ||||
-rw-r--r-- | clang/test/Modules/header-import.m | 7 |
3 files changed, 37 insertions, 8 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index ca641d4c0dc..931145a8d65 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -580,7 +580,31 @@ LookupSubframeworkHeader(StringRef Filename, // File Info Management. //===----------------------------------------------------------------------===// +/// \brief Merge the header file info provided by \p OtherHFI into the current +/// header file info (\p HFI) +static void mergeHeaderFileInfo(HeaderFileInfo &HFI, + const HeaderFileInfo &OtherHFI) { + HFI.isImport |= OtherHFI.isImport; + HFI.isPragmaOnce |= OtherHFI.isPragmaOnce; + HFI.NumIncludes += OtherHFI.NumIncludes; + + if (!HFI.ControllingMacro && !HFI.ControllingMacroID) { + HFI.ControllingMacro = OtherHFI.ControllingMacro; + HFI.ControllingMacroID = OtherHFI.ControllingMacroID; + } + + if (OtherHFI.External) { + HFI.DirInfo = OtherHFI.DirInfo; + HFI.External = OtherHFI.External; + HFI.IndexHeaderMapHeader = OtherHFI.IndexHeaderMapHeader; + } + if (HFI.Framework.empty()) + HFI.Framework = OtherHFI.Framework; + + HFI.Resolved = true; +} + /// getFileInfo - Return the HeaderFileInfo structure for the specified /// FileEntry. HeaderFileInfo &HeaderSearch::getFileInfo(const FileEntry *FE) { @@ -588,10 +612,8 @@ HeaderFileInfo &HeaderSearch::getFileInfo(const FileEntry *FE) { FileInfo.resize(FE->getUID()+1); HeaderFileInfo &HFI = FileInfo[FE->getUID()]; - if (ExternalSource && !HFI.Resolved) { - HFI = ExternalSource->GetHeaderFileInfo(FE); - HFI.Resolved = true; - } + if (ExternalSource && !HFI.Resolved) + mergeHeaderFileInfo(HFI, ExternalSource->GetHeaderFileInfo(FE)); return HFI; } @@ -602,10 +624,8 @@ bool HeaderSearch::isFileMultipleIncludeGuarded(const FileEntry *File) { // Resolve header file info from the external source, if needed. HeaderFileInfo &HFI = FileInfo[File->getUID()]; - if (ExternalSource && !HFI.Resolved) { - HFI = ExternalSource->GetHeaderFileInfo(File); - HFI.Resolved = true; - } + if (ExternalSource && !HFI.Resolved) + mergeHeaderFileInfo(HFI, ExternalSource->GetHeaderFileInfo(File)); return HFI.isPragmaOnce || HFI.ControllingMacro || HFI.ControllingMacroID; } diff --git a/clang/test/Modules/Inputs/point.h b/clang/test/Modules/Inputs/point.h new file mode 100644 index 00000000000..eab23d5867a --- /dev/null +++ b/clang/test/Modules/Inputs/point.h @@ -0,0 +1,2 @@ +struct Point { int x, y; }; + diff --git a/clang/test/Modules/header-import.m b/clang/test/Modules/header-import.m new file mode 100644 index 00000000000..9996dc75c8b --- /dev/null +++ b/clang/test/Modules/header-import.m @@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodule-cache-path %t -F %S/Inputs -I %S/Inputs -verify %s + +#import "point.h" +__import_module__ Module; +#import "point.h" + |