https://github.com/vishruth-thimmaiah created https://github.com/llvm/llvm-project/pull/182857
Upstreams support for emitting traps for abstract destructors. >From 59ed53edb032cc6247f8a51176bda56c6304a7cd Mon Sep 17 00:00:00 2001 From: vishruth-thimmaiah <[email protected]> Date: Mon, 23 Feb 2026 19:54:10 +0530 Subject: [PATCH] [CIR] Upstream support for pure virtual destructors Signed-off-by: vishruth-thimmaiah <[email protected]> --- clang/lib/CIR/CodeGen/CIRGenFunction.cpp | 4 +- .../CIR/CodeGen/virtual-destructor-calls.cpp | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp index 71f3368cca3bb..efe4d762f7c22 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp @@ -840,7 +840,9 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &args) { // in fact emit references to them from other compilations, so emit them // as functions containing a trap instruction. if (dtorType != Dtor_Base && dtor->getParent()->isAbstract()) { - cgm.errorNYI(dtor->getSourceRange(), "abstract base class destructors"); + SourceLocation loc = + dtor->hasBody() ? dtor->getBody()->getBeginLoc() : dtor->getLocation(); + emitTrap(getLoc(loc), true); return; } diff --git a/clang/test/CIR/CodeGen/virtual-destructor-calls.cpp b/clang/test/CIR/CodeGen/virtual-destructor-calls.cpp index 08a6b21ca91d3..3f1b2e307d4db 100644 --- a/clang/test/CIR/CodeGen/virtual-destructor-calls.cpp +++ b/clang/test/CIR/CodeGen/virtual-destructor-calls.cpp @@ -127,3 +127,49 @@ namespace PR12798 { template void f(A*); } + +class D { + virtual ~D() = 0; +}; + +D::~D() = default; + +// CIR: cir.func{{.*}} @_ZN1DD2Ev +// CIR: %[[THIS:.*]] = cir.alloca !cir.ptr<!rec_D>, !cir.ptr<!cir.ptr<!rec_D>>, ["this", init] {alignment = 8 : i64} +// CIR: cir.store %[[ARG0:.*]], %[[THIS]] : !cir.ptr<!rec_D>, !cir.ptr<!cir.ptr<!rec_D>> +// CIR: %[[THIS1:.*]] = cir.load %[[THIS]] : !cir.ptr<!cir.ptr<!rec_D>>, !cir.ptr<!rec_D> +// CIR: cir.return + +// LLVM: define {{.*}} @_ZN1DD2Ev +// LLVM: %[[THIS_ADDR:.*]] = alloca ptr, i64 1, align 8 +// LLVM: store ptr %[[THIS:.*]], ptr %[[THIS_ADDR]], align 8 +// LLVM: %[[THIS1:.*]] = load ptr, ptr %[[THIS_ADDR]], align 8 +// LLVM: ret void + +// OGCG: define {{.*}} @_ZN1DD2Ev +// OGCG: %[[THIS_ADDR:.*]] = alloca ptr, align 8 +// OGCG: store ptr %[[THIS:.*]], ptr %[[THIS_ADDR]], align 8 +// OGCG: %[[THIS1:.*]] = load ptr, ptr %[[THIS_ADDR]], align 8 +// OGCG: ret void + +// CIR: cir.func {{.*}} @_ZN1DD1Ev(!cir.ptr<!rec_D>) alias(@_ZN1DD2Ev) + +// CIR: cir.func{{.*}} @_ZN1DD0Ev +// CIR: %[[THIS:.*]] = cir.alloca !cir.ptr<!rec_D>, !cir.ptr<!cir.ptr<!rec_D>>, ["this", init] {alignment = 8 : i64} +// CIR: cir.store %[[ARG0:.*]], %[[THIS]] : !cir.ptr<!rec_D>, !cir.ptr<!cir.ptr<!rec_D>> +// CIR: %[[THIS1:.*]] = cir.load %[[THIS]] : !cir.ptr<!cir.ptr<!rec_D>>, !cir.ptr<!rec_D> +// CIR: cir.trap + +// LLVM: define {{.*}} @_ZN1DD0Ev +// LLVM: %[[THIS_ADDR:.*]] = alloca ptr, i64 1, align 8 +// LLVM: store ptr %[[THIS:.*]], ptr %[[THIS_ADDR]], align 8 +// LLVM: %[[THIS1:.*]] = load ptr, ptr %[[THIS_ADDR]], align 8 +// LLVM: call void @llvm.trap() +// LLVM: unreachable + +// OGCG: define {{.*}} @_ZN1DD0Ev +// OGCG: %[[THIS_ADDR:.*]] = alloca ptr, align 8 +// OGCG: store ptr %[[THIS:.*]], ptr %[[THIS_ADDR]], align 8 +// OGCG: %[[THIS1:.*]] = load ptr, ptr %[[THIS_ADDR]], align 8 +// OGCG: call void @llvm.trap() +// OGCG: unreachable _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
