summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Basic/SourceManager.cpp6
-rw-r--r--clang/lib/Edit/Commit.cpp6
-rw-r--r--clang/lib/Sema/SemaChecking.cpp7
3 files changed, 10 insertions, 9 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 0a51985614c..3bf70b66693 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -955,6 +955,12 @@ SourceManager::getImmediateExpansionRange(SourceLocation Loc) const {
return Expansion.getExpansionLocRange();
}
+SourceLocation SourceManager::getTopMacroCallerLoc(SourceLocation Loc) const {
+ while (isMacroArgExpansion(Loc))
+ Loc = getImmediateSpellingLoc(Loc);
+ return Loc;
+}
+
/// getExpansionRange - Given a SourceLocation object, return the range of
/// tokens covered by the expansion in the ultimate file.
std::pair<SourceLocation,SourceLocation>
diff --git a/clang/lib/Edit/Commit.cpp b/clang/lib/Edit/Commit.cpp
index cb7a784a41a..0cc152bf1e7 100644
--- a/clang/lib/Edit/Commit.cpp
+++ b/clang/lib/Edit/Commit.cpp
@@ -225,8 +225,7 @@ bool Commit::canInsert(SourceLocation loc, FileOffset &offs) {
isAtStartOfMacroExpansion(loc, &loc);
const SourceManager &SM = SourceMgr;
- while (SM.isMacroArgExpansion(loc))
- loc = SM.getImmediateSpellingLoc(loc);
+ loc = SM.getTopMacroCallerLoc(loc);
if (loc.isMacroID())
if (!isAtStartOfMacroExpansion(loc, &loc))
@@ -256,8 +255,7 @@ bool Commit::canInsertAfterToken(SourceLocation loc, FileOffset &offs,
isAtEndOfMacroExpansion(loc, &loc);
const SourceManager &SM = SourceMgr;
- while (SM.isMacroArgExpansion(loc))
- loc = SM.getImmediateSpellingLoc(loc);
+ loc = SM.getTopMacroCallerLoc(loc);
if (loc.isMacroID())
if (!isAtEndOfMacroExpansion(loc, &loc))
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 8f6eef59843..8f6fa10dd8f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9357,11 +9357,8 @@ static void DiagnoseNullConversion(Sema &S, Expr *E, QualType T,
// Venture through the macro stacks to get to the source of macro arguments.
// The new location is a better location than the complete location that was
// passed in.
- while (S.SourceMgr.isMacroArgExpansion(Loc))
- Loc = S.SourceMgr.getImmediateMacroCallerLoc(Loc);
-
- while (S.SourceMgr.isMacroArgExpansion(CC))
- CC = S.SourceMgr.getImmediateMacroCallerLoc(CC);
+ Loc = S.SourceMgr.getTopMacroCallerLoc(Loc);
+ CC = S.SourceMgr.getTopMacroCallerLoc(CC);
// __null is usually wrapped in a macro. Go up a macro if that is the case.
if (NullKind == Expr::NPCK_GNUNull && Loc.isMacroID()) {
OpenPOWER on IntegriCloud