diff options
author | Manuel Klimek <klimek@google.com> | 2014-08-12 08:25:57 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2014-08-12 08:25:57 +0000 |
commit | 9af34aeac196631c4743f872dfd8eeaf211e0086 (patch) | |
tree | 0c24728e1eaf5074a04653bd3fefc2df6cafb3f4 /clang/lib/Lex/PPDirectives.cpp | |
parent | ce40dbcbaa3871671d0bb6d4131e9bbd99061ba7 (diff) | |
download | bcm5719-llvm-9af34aeac196631c4743f872dfd8eeaf211e0086.tar.gz bcm5719-llvm-9af34aeac196631c4743f872dfd8eeaf211e0086.zip |
Correctly implement -include search logic.
According to the gcc docs, -include uses the current working directory
for the lookup instead of the main source file.
This patch gets rid of NormalizeIncludePath (which relied on an
implementation detail of FileManager / FileEntry for the include path
logic to work), and instead hands the correct lookup information down to
LookupFile.
This will allow us to change the FileEntry's behavior regarding its Name
caching.
llvm-svn: 215433
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 4c80bb2ada3..4250619d084 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -541,7 +541,8 @@ const FileEntry *Preprocessor::LookupFile( bool SkipCache) { // If the header lookup mechanism may be relative to the current inclusion // stack, record the parent #includes. - SmallVector<const FileEntry *, 16> Includers; + SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 16> + Includers; if (!FromDir) { FileID FID = getCurrentFileLexer()->getFileID(); const FileEntry *FileEnt = SourceMgr.getFileEntryForID(FID); @@ -550,13 +551,15 @@ const FileEntry *Preprocessor::LookupFile( // predefines buffer. Any other file is not lexed with a normal lexer, so // it won't be scanned for preprocessor directives. If we have the // predefines buffer, resolve #include references (which come from the - // -include command line argument) as if they came from the main file, this - // affects file lookup etc. - if (!FileEnt) + // -include command line argument) from the current working directory + // instead of relative to the main file. + if (!FileEnt) { FileEnt = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()); - - if (FileEnt) - Includers.push_back(FileEnt); + if (FileEnt) + Includers.push_back(std::make_pair(FileEnt, FileMgr.getDirectory("."))); + } else { + Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir())); + } // MSVC searches the current include stack from top to bottom for // headers included by quoted include directives. @@ -567,7 +570,7 @@ const FileEntry *Preprocessor::LookupFile( if (IsFileLexer(ISEntry)) if ((FileEnt = SourceMgr.getFileEntryForID( ISEntry.ThePPLexer->getFileID()))) - Includers.push_back(FileEnt); + Includers.push_back(std::make_pair(FileEnt, FileEnt->getDir())); } } } |