[clang] [clang][bytecode] Fix an assertion failure in visitDtorCall() (PR #202507)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 8 23:14:28 PDT 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/202507
>From b07fd3a8a51d6a1859ef21f6cac8ad1c6b42cfd3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 9 Jun 2026 06:54:47 +0200
Subject: [PATCH] [clang][bytecode] Fix an assertion failure in visitDtorCall()
In `emitDestructionPop()`, we assert that the Descriptor has a
non-trivial dtor. Check this first here so we don't do all this work for
nothing.
---
clang/lib/AST/ByteCode/Compiler.cpp | 5 +++++
clang/test/AST/ByteCode/unions.cpp | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 76688e30a0acd..b89849b6983d8 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5418,6 +5418,11 @@ bool Compiler<Emitter>::visitDtorCall(const VarDecl *VD, const APValue &Value) {
if (!D)
return false;
+ // FIXME: Would be nice if we didn't allocate the descriptor at all in this
+ // case.
+ if (D->hasTrivialDtor())
+ return true;
+
Scope::Local Local = this->createLocal(D);
Locals.insert({VD, Local});
VarScope->addForScopeKind(Local, ScopeKind::Block);
diff --git a/clang/test/AST/ByteCode/unions.cpp b/clang/test/AST/ByteCode/unions.cpp
index 5f3676785fde6..4c72af986c333 100644
--- a/clang/test/AST/ByteCode/unions.cpp
+++ b/clang/test/AST/ByteCode/unions.cpp
@@ -1084,3 +1084,15 @@ namespace Revive {
// both-note {{in call to}}
}
#endif
+
+namespace TrivialDtorInEvaluateDtor{
+ template <class T> void foo() {
+ union { // both-error {{attempt to use a deleted function}}
+ T t; // both-note {{implicitly deleted}}
+ };
+ }
+ struct S {
+ ~S();
+ };
+ template void foo<S>(); // both-note {{in instantiation of function template specialization}}
+}
More information about the cfe-commits
mailing list