HerrCai0907 created this revision.
HerrCai0907 added reviewers: aaron.ballman, cjdb.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed: https://github.com/llvm/llvm-project/issues/62122
This change pointer to add diagnose message for this code.

  struct S {
      static int F(int n = 0 ? 0) {
          return 0;
      }
  };

The old code only marks the Decl invalid without emiting diagnoise.
It will miss some error and crash CodeGen step.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148372

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseDecl.cpp
  clang/test/Parser/cxx-member-initializers.cpp


Index: clang/test/Parser/cxx-member-initializers.cpp
===================================================================
--- clang/test/Parser/cxx-member-initializers.cpp
+++ clang/test/Parser/cxx-member-initializers.cpp
@@ -108,4 +108,6 @@
   // expected-error@-2 {{type name requires a specifier or qualifier}}
   // expected-error@-3 {{expected '>'}}
   // expected-note@-4 {{to match this '<'}}
+
+  void n(int x = 1 ? 2) {} // expected-error {{expected initializer}}
 };
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -7383,6 +7383,7 @@
           SourceLocation ArgStartLoc = NextToken().getLocation();
           if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
             DefArgToks.reset();
+            Diag(ArgStartLoc, diag::err_expected) << "initializer";
             Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
           } else {
             Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 <https://github.com/llvm/llvm-project/issues/62105>`_)
+- Fix crash when member function contains invalid default argument.
+  (`#62122 <https://github.com/llvm/llvm-project/issues/62122>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Index: clang/test/Parser/cxx-member-initializers.cpp
===================================================================
--- clang/test/Parser/cxx-member-initializers.cpp
+++ clang/test/Parser/cxx-member-initializers.cpp
@@ -108,4 +108,6 @@
   // expected-error@-2 {{type name requires a specifier or qualifier}}
   // expected-error@-3 {{expected '>'}}
   // expected-note@-4 {{to match this '<'}}
+
+  void n(int x = 1 ? 2) {} // expected-error {{expected initializer}}
 };
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -7383,6 +7383,7 @@
           SourceLocation ArgStartLoc = NextToken().getLocation();
           if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
             DefArgToks.reset();
+            Diag(ArgStartLoc, diag::err_expected) << "initializer";
             Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
           } else {
             Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc,
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 <https://github.com/llvm/llvm-project/issues/62105>`_)
+- Fix crash when member function contains invalid default argument.
+  (`#62122 <https://github.com/llvm/llvm-project/issues/62122>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to