From 372735f3423bbaacccda99e61805d6d8644487cc Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 19 Dec 2012 01:16:49 +0000 Subject: [PATCH] Simplify logic to use SourceManager::getFileLoc(), per Argyrios's feedback. llvm-svn: 170487 --- clang/lib/Frontend/DiagnosticRenderer.cpp | 6 ++---- clang/tools/libclang/CXSourceLocation.cpp | 9 +-------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/clang/lib/Frontend/DiagnosticRenderer.cpp b/clang/lib/Frontend/DiagnosticRenderer.cpp index 88a8706..d540964 100644 --- a/clang/lib/Frontend/DiagnosticRenderer.cpp +++ b/clang/lib/Frontend/DiagnosticRenderer.cpp @@ -153,10 +153,8 @@ void DiagnosticRenderer::emitDiagnostic(SourceLocation Loc, SourceLocation UnexpandedLoc = Loc; - // Perform the same walk as emitMacroExpansions, to find the ultimate - // expansion location for the diagnostic. - while (Loc.isMacroID()) - Loc = SM->getImmediateMacroCallerLoc(Loc); + // Find the ultimate expansion location for the diagnostic. + Loc = SM->getFileLoc(Loc); PresumedLoc PLoc = SM->getPresumedLoc(Loc, DiagOpts->ShowPresumedLoc); diff --git a/clang/tools/libclang/CXSourceLocation.cpp b/clang/tools/libclang/CXSourceLocation.cpp index c715eec..5d49f42 100644 --- a/clang/tools/libclang/CXSourceLocation.cpp +++ b/clang/tools/libclang/CXSourceLocation.cpp @@ -294,14 +294,7 @@ void clang_getSpellingLocation(CXSourceLocation location, const SourceManager &SM = *static_cast(location.ptr_data[0]); - SourceLocation SpellLoc = Loc; - - // Unravel the macro instantiation stack. This logic mirrors that - // in DiagnosticRenderer. - while (SpellLoc.isMacroID()) { - SpellLoc = SM.getImmediateMacroCallerLoc(SpellLoc); - } - + SourceLocation SpellLoc = SM.getFileLoc(Loc); std::pair LocInfo = SM.getDecomposedLoc(SpellLoc); FileID FID = LocInfo.first; unsigned FileOffset = LocInfo.second; -- 2.7.4