Skip to content

Commit 21d09a0

Browse files
committed
[Macros] Handle function body source range for body macro
Make sure it receives a SourceRange that covers the entire body, since that's what it replaces.
1 parent 60da121 commit 21d09a0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,12 @@ static CharSourceRange getExpansionInsertionRange(MacroRole role,
984984
closure->getEndLoc()));
985985
}
986986

987+
// If the function has a body, that's what's being replaced.
988+
auto *AFD = cast<AbstractFunctionDecl>(target.get<Decl *>());
989+
if (auto range = AFD->getBodySourceRange())
990+
return Lexer::getCharSourceRangeFromSourceRange(sourceMgr, range);
991+
992+
// Otherwise we have no body, just use the end of the decl.
987993
SourceLoc afterDeclLoc =
988994
Lexer::getLocForEndOfToken(sourceMgr, target.getEndLoc());
989995
return CharSourceRange(afterDeclLoc, 0);

0 commit comments

Comments
 (0)