Author: Timm Baeder
Date: 2025-08-26T13:03:17+02:00
New Revision: 0eebb8bbe545eb0a045ed07091b3e4eda3e68a53

URL: 
https://github.com/llvm/llvm-project/commit/0eebb8bbe545eb0a045ed07091b3e4eda3e68a53
DIFF: 
https://github.com/llvm/llvm-project/commit/0eebb8bbe545eb0a045ed07091b3e4eda3e68a53.diff

LOG: [clang][bytecode][NFC] Check hasTrivialDtor() in RunDestructors (#155381)

We do this when calling Free() on dynamically allocated memory.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp

Removed: 
    


################################################################################
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