[AST] Avoid walking macro expanded bodies in non-expanded mode

Make sure we don't walk into the expansion of a body macro if the AST
walker is configured not to walk macro expansions.
This commit is contained in:
Hamish Knight
2025-12-10 14:58:44 +00:00
parent f0d4572a92
commit a9ad4e2cae
2 changed files with 11 additions and 1 deletions

View File

@@ -558,7 +558,12 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
if (WalkGenerics && visitTrailingRequirements(AFD))
return true;
if (AFD->getBody(/*canSynthesize=*/false)) {
// If we're not walking macro expansions, avoid walking into a body if it
// was expanded from a macro.
auto SkipBody = !Walker.shouldWalkMacroArgumentsAndExpansion().second &&
AFD->isBodyMacroExpanded();
if (!SkipBody && AFD->getBody(/*canSynthesize=*/false)) {
AbstractFunctionDecl::BodyKind PreservedKind = AFD->getBodyKind();
if (BraceStmt *S = cast_or_null<BraceStmt>(doIt(AFD->getBody())))
AFD->setBody(S, PreservedKind);