https://github.com/daniel-petrovic updated https://github.com/llvm/llvm-project/pull/238088
>From ca0c1ba614fdbd8a53ae51e5dd34830218c09eb3 Mon Sep 17 00:00:00 2001 From: Daniel Petrovic <[email protected]> Date: Mon, 2 Nov 2026 20:11:54 +0100 Subject: [PATCH] [Clang] Fix crash during constexpr virtual destructor evaluation Pass the designated object's type to findCompleteObject in checkDynamicType instead of null QualType. This prevents assertions when contant evaluation attempts to destroy objects without ordinary storage, such as type_info objects produced by typeid expressions. Use the designator's type, which also correctly identifies the currently designated object. Fixes: #237168 --- clang/lib/AST/ExprConstant.cpp | 3 ++- .../SemaCXX/constexpr-typeid-destruction.cpp | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/constexpr-typeid-destruction.cpp diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 57d5bb475d0f9b..dcee61ce87d22e 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -6675,7 +6675,8 @@ static bool checkDynamicType(EvalInfo &Info, const Expr *E, const LValue &This, if (This.Designator.Invalid) return false; - CompleteObject Obj = findCompleteObject(Info, E, AK, This, QualType()); + CompleteObject Obj = + findCompleteObject(Info, E, AK, This, This.Designator.getType(Info.Ctx)); if (!Obj) return false; diff --git a/clang/test/SemaCXX/constexpr-typeid-destruction.cpp b/clang/test/SemaCXX/constexpr-typeid-destruction.cpp new file mode 100644 index 00000000000000..04c2409b1526af --- /dev/null +++ b/clang/test/SemaCXX/constexpr-typeid-destruction.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -std=c++14 -verify=expected,ref,cxx20 %s +// RUN: %clang_cc1 -std=c++20 -verify=expected,ref,cxx20 %s +// RUN: %clang_cc1 -std=c++23 -verify=expected,ref %s +// RUN: %clang_cc1 -std=c++23 -fexperimental-new-constant-interpreter -verify=expected %s + +namespace std { +struct type_info { + virtual ~type_info(); +}; +} + +// Ensure that diagnosing virtual dispatch on type_info object does not crash (GH237168). +constexpr void destroy_type_info() { // cxx20-error {{constexpr function never produces a constant expression}} + typeid(int).~type_info(); // ref-note {{destruction of object 'typeid(int)' whose value is not known}} +} + +#if __cplusplus > 202002L +static_assert((destroy_type_info(), true)); // expected-error {{static assertion expression is not an integral constant expression}} \ + // ref-note {{in call to 'destroy_type_info()'}} +#endif _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
