diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -842,6 +842,10 @@ 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();