https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/139595
We cannot consume annotation tokens with ConsumeToken(), so any pragmas present in an invalid initializer would previously crash. Now we handle annotation tokens more generally and avoid the crash. Fixes #113722 >From 8e43846179c9d89f03bcc5a1cc2f8a61d5fbf2b4 Mon Sep 17 00:00:00 2001 From: Aaron Ballman <aa...@aaronballman.com> Date: Mon, 12 May 2025 13:50:36 -0400 Subject: [PATCH] Fix crash with invalid member function param list We cannot consume annotation tokens with ConsumeToken(), so any pragmas present in an invalid initializer would previously crash. Now we handle annotation tokens more generally and avoid the crash. Fixes #113722 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Parse/ParseCXXInlineMethods.cpp | 9 +++++---- clang/test/Parser/cxx-invalid-function-decl.cpp | 10 ++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 257c4696de403..37cc037be0026 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -579,6 +579,8 @@ Bug Fixes in This Version ``#include`` directive. (#GH138094) - Fixed a crash during constant evaluation involving invalid lambda captures (#GH138832) +- Fixed a crash with an invalid member function parameter list with a default + argument which contains a pragma. (#GH113722) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp index e76435d0e9de7..342d46770c656 100644 --- a/clang/lib/Parse/ParseCXXInlineMethods.cpp +++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp @@ -1272,10 +1272,6 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, goto consume_token; case tok::eof: - case tok::annot_module_begin: - case tok::annot_module_end: - case tok::annot_module_include: - case tok::annot_repl_input_end: // Ran out of tokens. return false; @@ -1411,6 +1407,11 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, [[fallthrough]]; default: consume_token: + // If it's an annotation token, then we've run out of tokens and should + // bail out. Otherwise, cache the token and consume it. + if (Tok.isAnnotation()) + return false; + Toks.push_back(Tok); ConsumeToken(); break; diff --git a/clang/test/Parser/cxx-invalid-function-decl.cpp b/clang/test/Parser/cxx-invalid-function-decl.cpp index 2db27516eefab..39d3221d3d279 100644 --- a/clang/test/Parser/cxx-invalid-function-decl.cpp +++ b/clang/test/Parser/cxx-invalid-function-decl.cpp @@ -40,3 +40,13 @@ struct S : public Base1<int>, public Base2<float> { // All initializers are correct, nothing to skip, diagnose 2 missing commas. S(const S &) : Base1<int>(0) ::Base2<float>(1.0) x(2) {} // expected-error2{{missing ',' between base or member initializers}} }; + +namespace GH113722 { +struct S { + void m(int x = 0; // expected-error {{unexpected end of default argument expression}} \ + expected-note {{to match this '('}} + #pragma unused(x) // expected-error {{expected ')'}} \ + expected-error {{expected ';' at end of declaration list}} + } // expected-error {{expected ';' after struct}} +}; +} // expected-error {{extraneous closing brace ('}')}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits