Timm =?utf-8?q?Bäder?= <[email protected]> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/205476 >From 9fc9d46216271476b9ec20057e1f3b911ef96140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Wed, 24 Jun 2026 06:05:40 +0200 Subject: [PATCH 1/2] [clang][ExprConst] Add early exit in `evaluateDestruction()` --- clang/lib/AST/ExprConstant.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index dde3b8bab43ec..a0558f2ac9d99 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -21707,6 +21707,12 @@ bool Expr::EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD, bool VarDecl::evaluateDestruction( SmallVectorImpl<PartialDiagnosticAt> &Notes) const { + + if (getType()->isPointerOrReferenceType()) { + ensureEvaluatedStmt()->HasConstantDestruction = true; + return true; + } + Expr::EvalStatus EStatus; EStatus.Diag = &Notes; >From dcdc64b9b20bd677d73a9047e80c330c9dae1ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Wed, 24 Jun 2026 17:40:40 +0200 Subject: [PATCH 2/2] try to short circuit for all non-record types --- clang/lib/AST/ExprConstant.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index a0558f2ac9d99..eb7393292adb8 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -21707,8 +21707,15 @@ bool Expr::EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD, bool VarDecl::evaluateDestruction( SmallVectorImpl<PartialDiagnosticAt> &Notes) const { - - if (getType()->isPointerOrReferenceType()) { + // This function is only meaningful for records and arrays of records. + QualType VarTy = getType(); + if (VarTy->isArrayType()) { + QualType ElemTy = getASTContext().getBaseElementType(VarTy); + if (!ElemTy->isRecordType()) { + ensureEvaluatedStmt()->HasConstantDestruction = true; + return true; + } + } else if (!VarTy->isRecordType()) { ensureEvaluatedStmt()->HasConstantDestruction = true; return true; } @@ -21727,7 +21734,7 @@ bool VarDecl::evaluateDestruction( APValue DestroyedValue; if (getEvaluatedValue()) DestroyedValue = *getEvaluatedValue(); - else if (!handleDefaultInitValue(getType(), DestroyedValue)) + else if (!handleDefaultInitValue(VarTy, DestroyedValue)) return false; if (Ctx.getLangOpts().EnableNewConstInterp) { @@ -21744,7 +21751,7 @@ bool VarDecl::evaluateDestruction( return true; } - if (!EvaluateDestruction(Ctx, this, std::move(DestroyedValue), getType(), + if (!EvaluateDestruction(Ctx, this, std::move(DestroyedValue), VarTy, getLocation(), EStatus, IsConstantDestruction) || EStatus.HasSideEffects) return false; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
