[clang] [clang][bytecode] Fix emitDestruction() for dummy descriptors (PR #134665)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 7 07:50:07 PDT 2025


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/134665

This might happen if the referenced declaration is invalid and thus gets a dummy descriptor. We ran into an assertion later on.

>From 9143c1118815f3b4a232a8d8029215ecbd2a3955 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 7 Apr 2025 16:49:00 +0200
Subject: [PATCH] [clang][bytecode] Fix emitDestruction() for dummy descriptors

This might happen if the referenced declaration is invalid and thus
gets a dummy descriptor. We ran into an assertion later on.
---
 clang/lib/AST/ByteCode/Compiler.cpp |  4 ++++
 clang/test/AST/ByteCode/cxx17.cpp   | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 021acbd798646..207cddf44f54d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6800,6 +6800,10 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc,
   assert(!Desc->isPrimitive());
   assert(!Desc->isPrimitiveArray());
 
+  // Can happen if the decl is invalid.
+  if (Desc->isDummy())
+    return true;
+
   // Arrays.
   if (Desc->isArray()) {
     const Descriptor *ElemDesc = Desc->ElemDesc;
diff --git a/clang/test/AST/ByteCode/cxx17.cpp b/clang/test/AST/ByteCode/cxx17.cpp
index ecb8a395520a0..9453906579f04 100644
--- a/clang/test/AST/ByteCode/cxx17.cpp
+++ b/clang/test/AST/ByteCode/cxx17.cpp
@@ -125,3 +125,14 @@ namespace constant {
   }
   static_assert(f());
 }
+
+
+template <int a> struct i; // both-note {{template is declared here}}
+template <> struct i<0> {};
+
+template <int x> constexpr auto c() {
+  i<x> g; // both-error {{implicit instantiation of undefined template 'i<1>'}}
+  return 0;
+}
+
+auto y = c<1>(); // both-note {{in instantiation of function template specialization 'c<1>' requested here}}



More information about the cfe-commits mailing list