Author: Daniel Petrovic Date: 2026-11-20T10:15:30Z New Revision: 0f09df7e486373c7e347e723b1e15e6740b904f4
URL: https://github.com/llvm/llvm-project/commit/0f09df7e486373c7e347e723b1e15e6740b904f4 DIFF: https://github.com/llvm/llvm-project/commit/0f09df7e486373c7e347e723b1e15e6740b904f4.diff LOG: [clang] Prevent stack overflow on deeply nested template arguments (#224393) Limit template argument nesting and diagnose before exhausting the parser stack. Fixes #224114 Assisted by: Gemini Added: Modified: clang/docs/ReleaseNotes.md clang/lib/Parse/ParseTemplate.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index d6f8d2a30bd7df..fa416178474685 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1097,6 +1097,11 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and - Fixed a crash when a using-declaration naming an unresolvable member of a dependent base was shadowed by an invalid using-declaration. (#GH209427) +- Fixed a stack overflow when parsing deeply nested template arguments such + as ``S<S<S<...>>>``. Parsing now goes through the existing stack guard, which + continues on a fresh stack instead of crashing when the parser's stack is + nearly exhausted. (#GH224114) + - Fixed a CTAD bug when combining with concepts. (#GH124715) - Fixed a regression where an internal-linkage function (e.g. a `static` or diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index ff4945f014db16..56fde9dbe421fe 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -1400,7 +1400,9 @@ bool Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs, do { PreferredType.enterFunctionArgument(Tok.getLocation(), RunSignatureHelp); - ParsedTemplateArgument Arg = ParseTemplateArgument(); + ParsedTemplateArgument Arg; + StackHandler.runWithSufficientStackSpace( + OpenLoc, [&Arg, this] { Arg = ParseTemplateArgument(); }); SourceLocation EllipsisLoc; if (TryConsumeToken(tok::ellipsis, EllipsisLoc)) Arg = Actions.ActOnPackExpansion(Arg, EllipsisLoc); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
