diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 86b42c499b23be..aa1411d67799b6 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -842,6 +842,10 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, unsigned AddLevels, unsigned InitialLevel = Line->Level; nextToken(/*LevelDifference=*/AddLevels); + // Bail out if there are too many levels. Otherwise, the stack might overflow. + if (Line->Level > 300) + return; + if (MacroBlock && FormatTok->is(tok::l_paren)) parseParens();