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

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 9 22:02:29 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/180682.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.cpp (+2-1) 
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+6) 


``````````diff
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) {

``````````

</details>


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


More information about the cfe-commits mailing list