[clang] [clang][bytecode] Don't call InterpFrame::getThis() on the bottom frame (PR #180682)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 22:01:58 PST 2026


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/180682

This happens when we're in checkingPotentialConstantExpression() and we try to evaluate a delete expression.

>From 952246bdde2ca5bb32c0fc14afe9e6ce39fe30f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 10 Feb 2026 07:00:20 +0100
Subject: [PATCH] [clang][bytecode] Don't call InterpFrame::getThis() on the
 bottom frame

This happens when we're in checkingPotentialConstantExpression() and we
try to evaluate a delete expression.
---
 clang/lib/AST/ByteCode/Interp.cpp      | 3 ++-
 clang/test/AST/ByteCode/new-delete.cpp | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index f6e2f149165ff..d6939c023f43b 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1260,7 +1260,8 @@ static bool runRecordDestructor(InterpState &S, CodePtr OpPC,
   const Record *R = Desc->ElemRecord;
   assert(R);
 
-  if (S.Current->hasThisPointer() && S.Current->getFunction()->isDestructor() &&
+  if (!S.Current->isBottomFrame() && S.Current->hasThisPointer() &&
+      S.Current->getFunction()->isDestructor() &&
       Pointer::pointToSameBlock(BasePtr, S.Current->getThis())) {
     const SourceInfo &Loc = S.Current->getSource(OpPC);
     S.FFDiag(Loc, diag::note_constexpr_double_destroy);
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index d77107856c30f..419547239fa77 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -117,6 +117,12 @@ constexpr int AutoArray() {
 
 static_assert(AutoArray() == 3);
 
+namespace ThisPtrInRunRecordDestructor {
+  struct S {
+    constexpr ~S() { delete new S; };
+  };
+}
+
 #if 0
 consteval int largeArray1(bool b) {
   if (b) {



More information about the cfe-commits mailing list