aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-12-21 16:56:35 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-12-21 16:56:35 +0000
commite841c901de45c187f799c464331996d014c90fcd (patch)
treecf00015db117397127680d97715812efd9f432ec /clang/lib/Basic/SourceManager.cpp
parent2403797eecef43c4e3fb620684eba8d18ed8d087 (diff)
downloadllvm-e841c901de45c187f799c464331996d014c90fcd.zip
llvm-e841c901de45c187f799c464331996d014c90fcd.tar.gz
llvm-e841c901de45c187f799c464331996d014c90fcd.tar.bz2
Fix bugs in SourceManager::computeMacroArgsCache() and add a unit test for it.
llvm-svn: 147057
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index b278f3d..61f4e86 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/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<FileID, unsigned> 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