Skip to content

Commit 92e6a00

Browse files
committed
[Diags] Avoid infinite recursion on decl printing request cycle
The ASTPrinter may kick requests that may emit diagnostics, make sure we don't attempt to recursively print the decl since that would lead to infinite recursion when diagnosing the cycle.
1 parent 4a54598 commit 92e6a00

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,11 +1410,15 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic,
14101410
loc = decl->getLoc();
14111411

14121412
// If the location of the decl is invalid still, try to pretty-print the
1413-
// declaration into a buffer and capture the source location there.
1413+
// declaration into a buffer and capture the source location there. Make
1414+
// sure we don't have an active request running since printing AST can
1415+
// kick requests that may themselves emit diagnostics. This won't help the
1416+
// underlying cycle, but it at least stops us from overflowing the stack.
14141417
if (loc.isInvalid()) {
1415-
loc = evaluateOrDefault(
1416-
decl->getASTContext().evaluator, PrettyPrintDeclRequest{decl},
1417-
SourceLoc());
1418+
PrettyPrintDeclRequest req(decl);
1419+
auto &eval = decl->getASTContext().evaluator;
1420+
if (!eval.hasActiveRequest(req))
1421+
loc = evaluateOrDefault(eval, req, SourceLoc());
14181422
}
14191423
}
14201424

0 commit comments

Comments
 (0)