[clang] [clang][ExprConst] Don't pass invalid decls to ASTRecordLayout (PR #203817)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 14 21:05:29 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/203817
It will assert.
Fixes https://github.com/llvm/llvm-project/issues/203755
>From ba86203eee0338221e580b98422c4f8740300ebd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 15 Jun 2026 06:04:32 +0200
Subject: [PATCH] [clang][ExprConst] Don't pass invalid decls to
ASTRecordLayout
It will assert.
Fixes https://github.com/llvm/llvm-project/issues/203755
---
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 2 ++
clang/lib/AST/ExprConstant.cpp | 2 ++
clang/test/AST/ByteCode/builtin-bit-cast.cpp | 8 ++++++++
3 files changed, 12 insertions(+)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index c7379fda30f91..f136301c02912 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -131,6 +131,8 @@ static Result enumerateData(PtrView P, const Context &Ctx, Bits Offset,
// Records.
if (FieldDesc->isRecord()) {
const Record *R = FieldDesc->ElemRecord;
+ if (R->getDecl()->isInvalidDecl())
+ return Result::Failure;
const ASTRecordLayout &Layout =
Ctx.getASTContext().getASTRecordLayout(R->getDecl());
bool Ok = true;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 1642c41a99a2f..bc98c0d86bb65 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8060,6 +8060,8 @@ class BufferToAPValueConverter {
std::optional<APValue> visit(const RecordType *RTy, CharUnits Offset) {
const RecordDecl *RD = RTy->getAsRecordDecl();
+ if (RD->isInvalidDecl())
+ return std::nullopt;
const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD);
unsigned NumBases = 0;
diff --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
index aea5d9d712c80..368728d00a812 100644
--- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp
+++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
@@ -599,3 +599,11 @@ namespace NonNumbers {
static_assert(fn() == 1); // both-error {{not an integral constant expression}} \
// ref-note {{in call to}}
}
+
+namespace InvalidRecordDecl {
+ struct a :; // both-error {{expected class name}} \
+ // both-error {{expected '{' after base class list}}
+ constexpr struct {
+ } b;
+ a c = __builtin_bit_cast(a, b);
+}
More information about the cfe-commits
mailing list