[clang] [clang][bytecode] Fix a crash with void declarations (PR #189334)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 30 00:57:12 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/189334
The `chk` decl is erroneous, but we shouldn't crash.
>From d112f5aadf6d5e918dd1a174fb90330cd71a5463 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 30 Mar 2026 09:51:38 +0200
Subject: [PATCH] [clang][bytecode] Fix a crash with void declarations
The `chk` decl is erroneous, but we shouldn't crash.
---
clang/lib/AST/ByteCode/Compiler.cpp | 2 +-
clang/test/AST/ByteCode/records.cpp | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index c7f074c9efc6a..75841c4378d21 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5293,7 +5293,7 @@ Compiler<Emitter>::visitVarDecl(const VarDecl *VD, const Expr *Init,
VD->getType().isVolatileQualified(), ScopeKind::Block,
IsConstexprUnknown);
- if (!Init)
+ if (!Init || Init->getType()->isVoidType())
return true;
// If this is a toplevel declaration, create a scope for the
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index a6aea0458e4ed..db02a7d23151e 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1910,3 +1910,22 @@ namespace VirtCallNoRecord {
int bar(int{((S *const)0)->foo()});
}
+namespace ErroneousVoidDecl {
+#if __cplusplus >= 201703L
+ struct S {};
+ template <auto V> struct M;
+ template <typename C, int N1, int N2> auto f(const C &, M<N1> *, M<N1> *) {} // both-note {{couldn't infer template argument}}
+
+ template <typename F, typename C, typename N1, typename N2>
+ constexpr bool check(const C &c, N1 *n1, N2 *n2) {
+ decltype(f(c, n1, n2)) *chk{}; // both-error {{no matching function}} \
+ // ref-note {{destroying object 'chk' whose lifetime has already ended}}
+ return true;
+ }
+
+ template <int N> constexpr M<N> *bar() { return nullptr; }
+ static_assert(check<S>([](int n) constexpr {}, bar<1u>(), bar<1u>())); // both-note {{in instantiation}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to}}
+#endif
+}
More information about the cfe-commits
mailing list