From cee5ec9df479994e4ba27fb65b7ded5bb5a980eb Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 21 Dec 2011 16:56:35 +0000 Subject: Fix bugs in SourceManager::computeMacroArgsCache() and add a unit test for it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147057 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/SourceManager.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'lib/Basic') diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index b278f3d963..61f4e86652 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -1585,14 +1585,31 @@ void SourceManager::computeMacroArgsCache(MacroArgsMap *&CachePtr, continue; } - if (!Entry.getExpansion().isMacroArgExpansion()) + const ExpansionInfo &ExpInfo = Entry.getExpansion(); + + if (ExpInfo.getExpansionLocStart().isFileID()) { + if (!isInFileID(ExpInfo.getExpansionLocStart(), FID)) + return; // No more files/macros that may be "contained" in this file. + } + + if (!ExpInfo.isMacroArgExpansion()) continue; - - SourceLocation SpellLoc = - getSpellingLoc(Entry.getExpansion().getSpellingLoc()); + + SourceLocation SpellLoc = ExpInfo.getSpellingLoc(); + while (!SpellLoc.isFileID()) { + std::pair LocInfo = getDecomposedLoc(SpellLoc); + const ExpansionInfo &Info = getSLocEntry(LocInfo.first).getExpansion(); + if (!Info.isMacroArgExpansion()) + break; + SpellLoc = Info.getSpellingLoc().getLocWithOffset(LocInfo.second); + } + if (!SpellLoc.isFileID()) + continue; + unsigned BeginOffs; if (!isInFileID(SpellLoc, FID, &BeginOffs)) - return; // No more files/macros that may be "contained" in this file. + continue; + unsigned EndOffs = BeginOffs + getFileIDSize(FileID::get(ID)); // Add a new chunk for this macro argument. A previous macro argument chunk -- cgit v1.2.3-18-g5258