[clang] 3a3bdd8 - [clang] Fix crash when destructor definition is preceded with '=' (#90220)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 1 01:43:15 PDT 2024
Author: Vlad Serebrennikov
Date: 2024-05-01T12:43:10+04:00
New Revision: 3a3bdd8fb63ffb49741a9c32b3a5a789ce4c3b91
URL: https://github.com/llvm/llvm-project/commit/3a3bdd8fb63ffb49741a9c32b3a5a789ce4c3b91
DIFF: https://github.com/llvm/llvm-project/commit/3a3bdd8fb63ffb49741a9c32b3a5a789ce4c3b91.diff
LOG: [clang] Fix crash when destructor definition is preceded with '=' (#90220)
Fixes #89544
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/Expr.cpp
clang/test/SemaCXX/destructor.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c11f117cd6e8b4..2c5308fbcb319a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -472,6 +472,9 @@ Bug Fixes in This Version
- Clang now correctly generates overloads for bit-precise integer types for
builtin operators in C++. Fixes #GH82998.
+- Fix crash when destructor definition is preceded with an equals sign.
+ Fixes (#GH89544).
+
- When performing mixed arithmetic between ``_Complex`` floating-point types and integers,
Clang now correctly promotes the integer to its corresponding real floating-point
type only rather than to the complex type (e.g. ``_Complex float / int`` is now evaluated
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index a915745d2d7322..ab3f810b45192b 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1482,6 +1482,8 @@ class CXXTemporary {
/// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr.
/// }
/// \endcode
+///
+/// Destructor might be null if destructor declaration is not valid.
class CXXBindTemporaryExpr : public Expr {
CXXTemporary *Temp = nullptr;
Stmt *SubExpr = nullptr;
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index d2e40be59d6f3b..ac0b1b38f0162f 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3893,9 +3893,14 @@ namespace {
}
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) {
- if (E->getTemporary()->getDestructor()->isTrivial()) {
- Inherited::VisitStmt(E);
- return;
+ // Destructor of the temporary might be null if destructor declaration
+ // is not valid.
+ if (const CXXDestructorDecl *DtorDecl =
+ E->getTemporary()->getDestructor()) {
+ if (DtorDecl->isTrivial()) {
+ Inherited::VisitStmt(E);
+ return;
+ }
}
NonTrivial = true;
diff --git a/clang/test/SemaCXX/destructor.cpp b/clang/test/SemaCXX/destructor.cpp
index beac50e449e96d..028bc7cc196989 100644
--- a/clang/test/SemaCXX/destructor.cpp
+++ b/clang/test/SemaCXX/destructor.cpp
@@ -565,4 +565,16 @@ struct Foo : public Baz { // expected-error {{cannot override a non-deleted func
};
}
+namespace GH89544 {
+class Foo {
+ ~Foo() = {}
+ // expected-error at -1 {{initializer on function does not look like a pure-specifier}}
+ // expected-error at -2 {{expected ';' at end of declaration list}}
+};
+
+static_assert(!__is_trivially_constructible(Foo), "");
+static_assert(!__is_trivially_constructible(Foo, const Foo &), "");
+static_assert(!__is_trivially_constructible(Foo, Foo &&), "");
+} // namespace GH89544
+
#endif // BE_THE_HEADER
More information about the cfe-commits
mailing list