[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Younan Zhang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG76d72a715038: [clang] Fix a crash on invalid destructor 
(authored by zyounan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153724/new/

https://reviews.llvm.org/D153724

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/virtuals.cpp


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,18 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  virtual ~Derived() = defaul; // #default
+} do_not_crash;
+// expected-error@#default {{initializer on function does not look like a 
pure-specifier}}
+// expected-error@#default {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a 
friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15807,7 +15807,11 @@
 return;
 
   CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
-
+  // The result of `LookupDestructor` might be nullptr if the destructor is
+  // invalid, in which case it is marked as `IneligibleOrNotSelected` and
+  // will not be selected by `CXXRecordDecl::getDestructor()`.
+  if (!Destructor)
+return;
   // If this is an array, we'll require the destructor during initialization, 
so
   // we can skip over this. We still want to emit exit-time destructor warnings
   // though.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -471,7 +471,7 @@
 - Fix crash when redefining a variable with an invalid type again with an
   invalid type. (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
-  (`#60082` `_)
+  (`#60082 `_)
 - Fix the assertion hit when generating code for global variable initializer of
   _BitInt(1) type.
   (`#62207 `_)
@@ -523,21 +523,23 @@
   (`#50534 `_).
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
-  (`#50244 _`).
+  (`#50244 `_).
 - Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
   (`#63219 `_).
 - Clang now properly diagnoses format string mismatches involving scoped
   enumeration types. A scoped enumeration type is not promoted to an integer
   type by the default argument promotions, and thus this is UB. Clang's
   behavior now matches GCC's behavior in C++.
-  (`#38717 _`).
+  (`#38717 `_).
 - Fixed a failing assertion when implicitly defining a function within a GNU
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
-  (`#48579 _`).
+  (`#48579 `_).
 - Fixed a failing assertion when applying an attribute to an anonymous union.
   The assertion was benign outside of asserts builds and would only fire in 
C++.
-  (`#48512 _`).
+  (`#48512 `_).
+- Fixed a failing assertion when parsing incomplete destructor.
+  (`#63503 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,18 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  virtual ~Derived() = defaul; // #default
+} do_not_crash;
+// expected-error@#default {{initializer on function does not look like a pure-specifier}}
+// expected-error@#default {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no num

[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.
This revision is now accepted and ready to land.

Make sense to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153724/new/

https://reviews.llvm.org/D153724

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 534387.
zyounan added a comment.

.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153724/new/

https://reviews.llvm.org/D153724

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/virtuals.cpp


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,18 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  virtual ~Derived() = defaul; // #default
+} do_not_crash;
+// expected-error@#default {{initializer on function does not look like a 
pure-specifier}}
+// expected-error@#default {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a 
friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15807,7 +15807,11 @@
 return;
 
   CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
-
+  // The result of `LookupDestructor` might be nullptr if the destructor is
+  // invalid, in which case it is marked as `IneligibleOrNotSelected` and
+  // will not be selected by `CXXRecordDecl::getDestructor()`.
+  if (!Destructor)
+return;
   // If this is an array, we'll require the destructor during initialization, 
so
   // we can skip over this. We still want to emit exit-time destructor warnings
   // though.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -469,7 +469,7 @@
 - Fix crash when redefining a variable with an invalid type again with an
   invalid type. (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
-  (`#60082` `_)
+  (`#60082 `_)
 - Fix the assertion hit when generating code for global variable initializer of
   _BitInt(1) type.
   (`#62207 `_)
@@ -521,21 +521,23 @@
   (`#50534 `_).
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
-  (`#50244 _`).
+  (`#50244 `_).
 - Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
   (`#63219 `_).
 - Clang now properly diagnoses format string mismatches involving scoped
   enumeration types. A scoped enumeration type is not promoted to an integer
   type by the default argument promotions, and thus this is UB. Clang's
   behavior now matches GCC's behavior in C++.
-  (`#38717 _`).
+  (`#38717 `_).
 - Fixed a failing assertion when implicitly defining a function within a GNU
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
-  (`#48579 _`).
+  (`#48579 `_).
 - Fixed a failing assertion when applying an attribute to an anonymous union.
   The assertion was benign outside of asserts builds and would only fire in 
C++.
-  (`#48512 _`).
+  (`#48512 `_).
+- Fixed a failing assertion when parsing incomplete destructor.
+  (`#63503 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,18 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  virtual ~Derived() = defaul; // #default
+} do_not_crash;
+// expected-error@#default {{initializer on function does not look like a pure-specifier}}
+// expected-error@#default {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
=

[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 534386.
zyounan added a comment.

Simplify test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153724/new/

https://reviews.llvm.org/D153724

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/virtuals.cpp


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,18 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a 
pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a 
friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15807,7 +15807,11 @@
 return;
 
   CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
-
+  // The result of `LookupDestructor` might be nullptr if the destructor is
+  // invalid, in which case it is marked as `IneligibleOrNotSelected` and
+  // will not be selected by `CXXRecordDecl::getDestructor()`.
+  if (!Destructor)
+return;
   // If this is an array, we'll require the destructor during initialization, 
so
   // we can skip over this. We still want to emit exit-time destructor warnings
   // though.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -469,7 +469,7 @@
 - Fix crash when redefining a variable with an invalid type again with an
   invalid type. (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
-  (`#60082` `_)
+  (`#60082 `_)
 - Fix the assertion hit when generating code for global variable initializer of
   _BitInt(1) type.
   (`#62207 `_)
@@ -521,21 +521,23 @@
   (`#50534 `_).
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
-  (`#50244 _`).
+  (`#50244 `_).
 - Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
   (`#63219 `_).
 - Clang now properly diagnoses format string mismatches involving scoped
   enumeration types. A scoped enumeration type is not promoted to an integer
   type by the default argument promotions, and thus this is UB. Clang's
   behavior now matches GCC's behavior in C++.
-  (`#38717 _`).
+  (`#38717 `_).
 - Fixed a failing assertion when implicitly defining a function within a GNU
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
-  (`#48579 _`).
+  (`#48579 `_).
 - Fixed a failing assertion when applying an attribute to an anonymous union.
   The assertion was benign outside of asserts builds and would only fire in 
C++.
-  (`#48512 _`).
+  (`#48512 `_).
+- Fixed a failing assertion when parsing incomplete destructor.
+  (`#63503 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,18 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
==

[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 534362.
zyounan added a comment.

Typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153724/new/

https://reviews.llvm.org/D153724

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/virtuals.cpp


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,19 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  using Base::Base;
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a 
pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a 
friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15807,7 +15807,11 @@
 return;
 
   CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
-
+  // The result of `LookupDestructor` might be nullptr if the destructor is
+  // invalid, in which case it is marked as `IneligibleOrNotSelected` and
+  // will not be selected by `CXXRecordDecl::getDestructor()`.
+  if (!Destructor)
+return;
   // If this is an array, we'll require the destructor during initialization, 
so
   // we can skip over this. We still want to emit exit-time destructor warnings
   // though.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -469,7 +469,7 @@
 - Fix crash when redefining a variable with an invalid type again with an
   invalid type. (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
-  (`#60082` `_)
+  (`#60082 `_)
 - Fix the assertion hit when generating code for global variable initializer of
   _BitInt(1) type.
   (`#62207 `_)
@@ -521,21 +521,23 @@
   (`#50534 `_).
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
-  (`#50244 _`).
+  (`#50244 `_).
 - Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
   (`#63219 `_).
 - Clang now properly diagnoses format string mismatches involving scoped
   enumeration types. A scoped enumeration type is not promoted to an integer
   type by the default argument promotions, and thus this is UB. Clang's
   behavior now matches GCC's behavior in C++.
-  (`#38717 _`).
+  (`#38717 `_).
 - Fixed a failing assertion when implicitly defining a function within a GNU
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
-  (`#48579 _`).
+  (`#48579 `_).
 - Fixed a failing assertion when applying an attribute to an anonymous union.
   The assertion was benign outside of asserts builds and would only fire in 
C++.
-  (`#48512 _`).
+  (`#48512 `_).
+- Fixed a failing assertion when parsing incomplete destructor.
+  (`#63503 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,19 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  using Base::Base;
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cp

[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 534359.
zyounan added a comment.

And this


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153724/new/

https://reviews.llvm.org/D153724

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/virtuals.cpp


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,19 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  using Base::Base;
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a 
pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a 
friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15807,7 +15807,11 @@
 return;
 
   CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
-
+  // The result of `LookupDestructor` might be nullptr if the destructor is
+  // invalid, in which case it is not marked as `IsEligibleOrSelected` and
+  // will not be selected by `CXXRecordDecl::getDestructor()`.
+  if (!Destructor)
+return;
   // If this is an array, we'll require the destructor during initialization, 
so
   // we can skip over this. We still want to emit exit-time destructor warnings
   // though.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -469,7 +469,7 @@
 - Fix crash when redefining a variable with an invalid type again with an
   invalid type. (`#62447 `_)
 - Fix a stack overflow issue when evaluating ``consteval`` default arguments.
-  (`#60082` `_)
+  (`#60082 `_)
 - Fix the assertion hit when generating code for global variable initializer of
   _BitInt(1) type.
   (`#62207 `_)
@@ -521,21 +521,23 @@
   (`#50534 `_).
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
-  (`#50244 _`).
+  (`#50244 `_).
 - Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
   (`#63219 `_).
 - Clang now properly diagnoses format string mismatches involving scoped
   enumeration types. A scoped enumeration type is not promoted to an integer
   type by the default argument promotions, and thus this is UB. Clang's
   behavior now matches GCC's behavior in C++.
-  (`#38717 _`).
+  (`#38717 `_).
 - Fixed a failing assertion when implicitly defining a function within a GNU
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
-  (`#48579 _`).
+  (`#48579 `_).
 - Fixed a failing assertion when applying an attribute to an anonymous union.
   The assertion was benign outside of asserts builds and would only fire in 
C++.
-  (`#48512 _`).
+  (`#48512 `_).
+- Fixed a failing assertion when parsing incomplete destructor.
+  (`#63503 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,19 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  using Base::Base;
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclC

[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:524
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
-  (`#50244 _`).
+  (`#50244 `_).
 - Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments

These underscores are not placed correctly so I revised them as well. Hope you 
don't mind. :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153724/new/

https://reviews.llvm.org/D153724

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153724: [clang] Fix a crash on invalid destructor

2023-06-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan created this revision.
zyounan added reviewers: royjacobson, aaron.ballman, erichkeane, shafik.
Herald added a project: All.
zyounan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a follow-up patch to D126194  in 
order to
fix https://github.com/llvm/llvm-project/issues/63503.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153724

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/virtuals.cpp


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,19 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  using Base::Base;
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a 
pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a 
friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15807,7 +15807,11 @@
 return;
 
   CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
-
+  // The result of `LookupDestructor` might be nullptr if the destructor is
+  // invalid, in which case it is not marked as `IsEligibleOrSelected` and
+  // will not be selected by `CXXRecordDecl::getDestructor()`.
+  if (!Destructor)
+return;
   // If this is an array, we'll require the destructor during initialization, 
so
   // we can skip over this. We still want to emit exit-time destructor warnings
   // though.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -521,21 +521,23 @@
   (`#50534 `_).
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
-  (`#50244 _`).
+  (`#50244 `_).
 - Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
   (`#63219 `_).
 - Clang now properly diagnoses format string mismatches involving scoped
   enumeration types. A scoped enumeration type is not promoted to an integer
   type by the default argument promotions, and thus this is UB. Clang's
   behavior now matches GCC's behavior in C++.
-  (`#38717 _`).
+  (`#38717 `_).
 - Fixed a failing assertion when implicitly defining a function within a GNU
   statement expression that appears outside of a function block scope. The
   assertion was benign outside of asserts builds and would only fire in C.
-  (`#48579 _`).
+  (`#48579 `_).
 - Fixed a failing assertion when applying an attribute to an anonymous union.
   The assertion was benign outside of asserts builds and would only fire in 
C++.
-  (`#48512 _`).
+  (`#48512 `_).
+- Fixed a failing assertion when parsing incomplete destructor.
+  (`#63503 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/virtuals.cpp
===
--- clang/test/SemaCXX/virtuals.cpp
+++ clang/test/SemaCXX/virtuals.cpp
@@ -52,6 +52,19 @@
   };
 }
 
+namespace issue63503 {
+struct Base {
+  virtual ~Base() = default;
+};
+
+struct Derived final : Base {
+  using Base::Base;
+  virtual ~Derived() = defaul; // #62
+} do_not_crash;
+// expected-error@#62 {{initializer on function does not look like a pure-specifier}}
+// expected-error@#62 {{use of undeclared identifier 'defaul'}}
+}
+
 namespace VirtualFriend {
   // DR (filed but no number yet): reject meaningless pure-specifier on a friend declaration.
   struct A { virtual int f(); };
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15807,7 +15807,11 @@
 return;
 
   CXXDestructorDecl *Destructor = LookupDestructor(ClassDecl);
-
+  // The result of `LookupDestructor` might be nullptr if the dest