https://github.com/boomanaiden154 updated 
https://github.com/llvm/llvm-project/pull/190017

>From b11860c413c031dfe46ad5241ce16836e855dd7c Mon Sep 17 00:00:00 2001
From: Aiden Grossman <[email protected]>
Date: Wed, 1 Apr 2026 18:23:04 +0000
Subject: [PATCH 1/2] [Clang] Fix miscompile with custom operator delete

See discussion in #183347.

Added a separate test case rather than reusing
destructor-dead-on-return.cpp as we need to test functionality of the
deleting destructor which update_cc_test_checks.py does not add check
lines for.
---
 clang/lib/CodeGen/CGCall.cpp                         |  8 +++++++-
 .../dead-on-return-deleting-destructor.cpp           | 12 ++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/dead-on-return-deleting-destructor.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7d5dc53091c2b..b0b9a1f397aaf 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2878,10 +2878,16 @@ void CodeGenModule::ConstructAttributeList(StringRef 
Name,
         CalleeInfo.getCalleeDecl().getDecl());
     // Do not annotate vector deleting destructors with dead_on_return as the
     // this pointer in that case points to an array which we cannot
-    // statically know the size of.
+    // statically know the size of. Also do not mark deleting destructors
+    // dead_on_return as then we might delete stores inside of a user-defined
+    // operator delete implementation if it gets inlined, which would be
+    // incorrect as the object's lifetime has already ended and the operator
+    // delete implementation is allowed to manipulate the underlying storage.
     if (DD &&
         CalleeInfo.getCalleeDecl().getDtorType() !=
             CXXDtorType::Dtor_VectorDeleting &&
+        CalleeInfo.getCalleeDecl().getDtorType() !=
+            CXXDtorType::Dtor_Deleting &&
         CodeGenOpts.StrictLifetimes) {
       const CXXRecordDecl *ClassDecl =
           dyn_cast<CXXRecordDecl>(DD->getDeclContext());
diff --git a/clang/test/CodeGenCXX/dead-on-return-deleting-destructor.cpp 
b/clang/test/CodeGenCXX/dead-on-return-deleting-destructor.cpp
new file mode 100644
index 0000000000000..0ae57f1e21b08
--- /dev/null
+++ b/clang/test/CodeGenCXX/dead-on-return-deleting-destructor.cpp
@@ -0,0 +1,12 @@
+// Check that we do not annotate deleting destructors with dead_on_return.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | 
FileCheck %s
+
+class Foo {
+public:
+  virtual ~Foo();
+};
+
+// CHECK-LABEL: define dso_local void @_ZN3FooD0Ev
+// CHECK-SAME: ptr noundef nonnull align 8 dereferenceable(8) [[THIS:%.*]]) 
unnamed_addr #[[ATTR0:[0-9]+]] align 2 {
+Foo::~Foo() {};

>From 9c86cbca1fc415d161bea61ba46575a9782b1ff1 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <[email protected]>
Date: Wed, 1 Apr 2026 19:02:13 +0000
Subject: [PATCH 2/2] test updates

---
 clang/test/CodeGenCXX/microsoft-vector-deleting-dtors2.cpp    | 4 ++--
 .../ptrauth-apple-kext-indirect-virtual-dtor-call.cpp         | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors2.cpp 
b/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors2.cpp
index 65e2853b82e4d..c6089bb5ecbba 100644
--- a/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors2.cpp
+++ b/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors2.cpp
@@ -94,6 +94,6 @@ void TesttheTest() {
 // X64: define linkonce_odr dso_local void 
@"??_V?$RefCounted@UDrawingBuffer@@@@SAXPEAX@Z"(ptr noundef %p)
 // X86: define linkonce_odr dso_local void 
@"??_V?$RefCounted@UDrawingBuffer@@@@SAXPAX@Z"(ptr noundef %p)
 
-// X86: define linkonce_odr dso_local x86_thiscallcc noundef ptr 
@"??_GNoExport@@UAEPAXI@Z"(ptr noundef nonnull align 4 dead_on_return(4) 
dereferenceable(4) %this, i32 noundef %should_call_delete)
-// X64: define linkonce_odr dso_local noundef ptr 
@"??_GNoExport@@UEAAPEAXI@Z"(ptr noundef nonnull align 8 dead_on_return(8) 
dereferenceable(8) %this, i32 noundef %should_call_delete)
+// X86: define linkonce_odr dso_local x86_thiscallcc noundef ptr 
@"??_GNoExport@@UAEPAXI@Z"(ptr noundef nonnull align 4 dereferenceable(4) 
%this, i32 noundef %should_call_delete)
+// X64: define linkonce_odr dso_local noundef ptr 
@"??_GNoExport@@UEAAPEAXI@Z"(ptr noundef nonnull align 8 dereferenceable(8) 
%this, i32 noundef %should_call_delete)
 // CHECK-NOT: define {{.*}}_V{{.*}}NoExport
diff --git 
a/clang/test/CodeGenCXX/ptrauth-apple-kext-indirect-virtual-dtor-call.cpp 
b/clang/test/CodeGenCXX/ptrauth-apple-kext-indirect-virtual-dtor-call.cpp
index d40691f95c33f..eaef4edf2dd10 100644
--- a/clang/test/CodeGenCXX/ptrauth-apple-kext-indirect-virtual-dtor-call.cpp
+++ b/clang/test/CodeGenCXX/ptrauth-apple-kext-indirect-virtual-dtor-call.cpp
@@ -45,6 +45,6 @@ void f(SubTempl<int>* t) {
 }
 
 // CHECK: getelementptr inbounds nuw (i8, ptr @_ZTV5TemplIiE, i64 16)
-// CHECK: declare void @_ZN5TemplIiED0Ev(ptr noundef nonnull align 8 
dead_on_return(8) dereferenceable(8))
+// CHECK: declare void @_ZN5TemplIiED0Ev(ptr noundef nonnull align 8 
dereferenceable(8))
 // CHECK: define internal void @_ZN5TemplIiE1fEv(ptr noundef nonnull align 8 
dereferenceable(8) %this)
 // CHECK: define internal void @_ZN5TemplIiE1gEv(ptr noundef nonnull align 8 
dereferenceable(8) %this)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to