[clang] 7866c40 - Fix crash with invalid member function param list (#139595)

via cfe-commits cfe-commits at lists.llvm.org
Tue May 13 03:31:13 PDT 2025


Author: Aaron Ballman
Date: 2025-05-13T06:31:10-04:00
New Revision: 7866c4091eb3badd8e0f145a200c8a3d11849ef5

URL: https://github.com/llvm/llvm-project/commit/7866c4091eb3badd8e0f145a200c8a3d11849ef5
DIFF: https://github.com/llvm/llvm-project/commit/7866c4091eb3badd8e0f145a200c8a3d11849ef5.diff

LOG: Fix crash with invalid member function param list (#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

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Parse/ParseCXXInlineMethods.cpp
    clang/test/Parser/cxx-invalid-function-decl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c3c75b88a9fe..bc13d02e2d20b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -582,6 +582,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)
 - Fixed assertion failures when generating name lookup table in modules. (#GH61065, #GH134739)
 
 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 ('}')}}


        


More information about the cfe-commits mailing list