diff options
| author | Manman Ren <manman.ren@gmail.com> | 2016-05-17 02:15:12 +0000 |
|---|---|---|
| committer | Manman Ren <manman.ren@gmail.com> | 2016-05-17 02:15:12 +0000 |
| commit | e4a5d37d6bed0fc503099c64ea6c65761cbb6518 (patch) | |
| tree | e1a8c22b50ab5f5afa5d3d3130e32d4a95de547c /clang/lib | |
| parent | 18254935c9d8f6fcf0e5f20c13d5b4ef5424bf94 (diff) | |
| download | bcm5719-llvm-e4a5d37d6bed0fc503099c64ea6c65761cbb6518.tar.gz bcm5719-llvm-e4a5d37d6bed0fc503099c64ea6c65761cbb6518.zip | |
Modules: set SystemHeader to true if we are building a system module.
If we are processing a #include from a module build, we should treat it
as a system header if we're building a system module. Passing an optional
flag to HeaderSearch::LookupFile.
Before this, the testing case will crash when accessing a freed FileEntry.
rdar://26214027
llvm-svn: 269730
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 9 |
2 files changed, 10 insertions, 6 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 3bb7f8e0428..e627c786407 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -565,7 +565,7 @@ const FileEntry *HeaderSearch::LookupFile( ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, - bool SkipCache) { + bool SkipCache, bool BuildSystemModule) { if (SuggestedModule) *SuggestedModule = ModuleMap::KnownHeader(); @@ -613,11 +613,12 @@ const FileEntry *HeaderSearch::LookupFile( // getFileAndSuggestModule, because it's a reference to an element of // a container that could be reallocated across this call. // - // FIXME: If we have no includer, that means we're processing a #include + // If we have no includer, that means we're processing a #include // from a module build. We should treat this as a system header if we're // building a [system] module. bool IncluderIsSystemHeader = - Includer && getFileInfo(Includer).DirInfo != SrcMgr::C_User; + (Includer && getFileInfo(Includer).DirInfo != SrcMgr::C_User) || + (!Includer && BuildSystemModule); if (const FileEntry *FE = getFileAndSuggestModule( TmpDir, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index c33f9aba267..34adf7fac29 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -671,6 +671,7 @@ const FileEntry *Preprocessor::LookupFile( // stack, record the parent #includes. SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 16> Includers; + bool BuildSystemModule = false; if (!FromDir && !FromFile) { FileID FID = getCurrentFileLexer()->getFileID(); const FileEntry *FileEnt = SourceMgr.getFileEntryForID(FID); @@ -688,9 +689,10 @@ const FileEntry *Preprocessor::LookupFile( // come from header declarations in the module map) relative to the module // map file. if (!FileEnt) { - if (FID == SourceMgr.getMainFileID() && MainFileDir) + if (FID == SourceMgr.getMainFileID() && MainFileDir) { Includers.push_back(std::make_pair(nullptr, MainFileDir)); - else if ((FileEnt = + BuildSystemModule = getCurrentModule()->IsSystem; + } else if ((FileEnt = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()))) Includers.push_back(std::make_pair(FileEnt, FileMgr.getDirectory("."))); } else { @@ -736,7 +738,8 @@ const FileEntry *Preprocessor::LookupFile( // Do a standard file entry lookup. const FileEntry *FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, FromDir, CurDir, Includers, SearchPath, - RelativePath, RequestingModule, SuggestedModule, SkipCache); + RelativePath, RequestingModule, SuggestedModule, SkipCache, + BuildSystemModule); if (FE) { if (SuggestedModule && !LangOpts.AsmPreprocessor) HeaderInfo.getModuleMap().diagnoseHeaderInclusion( |

