[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 21:57:48 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/202507
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.
>From 548dbe349630b4f2722c07931de8260c3331f029 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..ed435cb094a57 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 {
+ T t;
+ };
+ }
+ struct S {
+ ~S();
+ };
+ template void foo<S>();
+}
More information about the cfe-commits
mailing list