https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/155381

>From a9b63626a9eccf36f632585866cd68a425fb30ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Tue, 26 Aug 2025 11:07:35 +0200
Subject: [PATCH] [clang][bytecode][NFC] Check hasTrivialDtor() in
 RunDestructors

We do this when calling Free() on dynamically allocated memory.
---
 clang/lib/AST/ByteCode/Interp.cpp | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index d4525c8288c68..06b2bdc98b428 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1207,17 +1207,15 @@ static bool runRecordDestructor(InterpState &S, CodePtr 
OpPC,
   }
 
   // Destructor of this record.
-  if (const CXXDestructorDecl *Dtor = R->getDestructor();
-      Dtor && !Dtor->isTrivial()) {
-    const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
-    if (!DtorFunc)
-      return false;
+  const CXXDestructorDecl *Dtor = R->getDestructor();
+  assert(Dtor);
+  assert(!Dtor->isTrivial());
+  const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
+  if (!DtorFunc)
+    return false;
 
-    S.Stk.push<Pointer>(BasePtr);
-    if (!Call(S, OpPC, DtorFunc, 0))
-      return false;
-  }
-  return true;
+  S.Stk.push<Pointer>(BasePtr);
+  return Call(S, OpPC, DtorFunc, 0);
 }
 
 static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
@@ -1229,6 +1227,9 @@ static bool RunDestructors(InterpState &S, CodePtr OpPC, 
const Block *B) {
 
   assert(Desc->isRecord() || Desc->isCompositeArray());
 
+  if (Desc->hasTrivialDtor())
+    return true;
+
   if (Desc->isCompositeArray()) {
     unsigned N = Desc->getNumElems();
     if (N == 0)

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to