[clang] 4a04568 - [clang][ExprConst] Add early exit in `evaluateDestruction()` (#205476)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 25 01:12:19 PDT 2026
Author: Timm Baeder
Date: 2026-06-25T10:12:14+02:00
New Revision: 4a04568bead31bd9edf8fd64210fbf2307d47199
URL: https://github.com/llvm/llvm-project/commit/4a04568bead31bd9edf8fd64210fbf2307d47199
DIFF: https://github.com/llvm/llvm-project/commit/4a04568bead31bd9edf8fd64210fbf2307d47199.diff
LOG: [clang][ExprConst] Add early exit in `evaluateDestruction()` (#205476)
There's nothing to do here for them. It's a little sad that we still
crated the vector holding the notes int he caller but setting
`HasConstantDestruction` is a side-effect of `evaluateDestruction()`
that some callers rely on.
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5ee27dd4e2ba2..28ac44edd800c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -21714,6 +21714,19 @@ bool Expr::EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD,
bool VarDecl::evaluateDestruction(
SmallVectorImpl<PartialDiagnosticAt> &Notes) const {
+ // 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;
+ }
+
Expr::EvalStatus EStatus;
EStatus.Diag = &Notes;
@@ -21728,7 +21741,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) {
@@ -21745,7 +21758,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;
More information about the cfe-commits
mailing list