diff options
| author | Ted Kremenek <kremenek@apple.com> | 2012-12-18 23:07:30 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2012-12-18 23:07:30 +0000 |
| commit | e3713d3025e1f76f6c40e0c6553a6fab6d427e0a (patch) | |
| tree | 9b57f420a3b57f9a172867bcefdf06dfec5ef773 /clang/tools | |
| parent | 9b7ab87738a6e4225005cff36e7aa1e735df5236 (diff) | |
| download | bcm5719-llvm-e3713d3025e1f76f6c40e0c6553a6fab6d427e0a.tar.gz bcm5719-llvm-e3713d3025e1f76f6c40e0c6553a6fab6d427e0a.zip | |
Have clang_getSpellingLocation() use the same logic as DiagnosticRenderer for plowing through macros.
This fixes a subtle bug reported in <rdar://problem/12584554> where a double-nested
macro could lead to an incorrect fixit location with live issues.
This fix also uncovers a bunch of subtle bugs in our indexer test cases which
are now fixed (mostly around source ranges for attributes).
llvm-svn: 170468
Diffstat (limited to 'clang/tools')
| -rw-r--r-- | clang/tools/libclang/CXSourceLocation.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/clang/tools/libclang/CXSourceLocation.cpp b/clang/tools/libclang/CXSourceLocation.cpp index 53b8a333f05..c715eecdecf 100644 --- a/clang/tools/libclang/CXSourceLocation.cpp +++ b/clang/tools/libclang/CXSourceLocation.cpp @@ -295,15 +295,13 @@ void clang_getSpellingLocation(CXSourceLocation location, const SourceManager &SM = *static_cast<const SourceManager*>(location.ptr_data[0]); SourceLocation SpellLoc = Loc; - if (SpellLoc.isMacroID()) { - SourceLocation SimpleSpellingLoc = SM.getImmediateSpellingLoc(SpellLoc); - if (SimpleSpellingLoc.isFileID() && - SM.getFileEntryForID(SM.getDecomposedLoc(SimpleSpellingLoc).first)) - SpellLoc = SimpleSpellingLoc; - else - SpellLoc = SM.getExpansionLoc(SpellLoc); + + // Unravel the macro instantiation stack. This logic mirrors that + // in DiagnosticRenderer. + while (SpellLoc.isMacroID()) { + SpellLoc = SM.getImmediateMacroCallerLoc(SpellLoc); } - + std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SpellLoc); FileID FID = LocInfo.first; unsigned FileOffset = LocInfo.second; |

