[clang] 745a8e0 - [clang][ExprConst] Don't pass invalid decls to ASTRecordLayout (#203817)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 15 03:34:12 PDT 2026
Author: Timm Baeder
Date: 2026-06-15T12:34:08+02:00
New Revision: 745a8e0f1cd2b783b2039617a3880b40f6405ec1
URL: https://github.com/llvm/llvm-project/commit/745a8e0f1cd2b783b2039617a3880b40f6405ec1
DIFF: https://github.com/llvm/llvm-project/commit/745a8e0f1cd2b783b2039617a3880b40f6405ec1.diff
LOG: [clang][ExprConst] Don't pass invalid decls to ASTRecordLayout (#203817)
It will assert.
Fixes https://github.com/llvm/llvm-project/issues/203755
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/lib/AST/ExprConstant.cpp
clang/test/AST/ByteCode/builtin-bit-cast.cpp
Removed:
################################################################################
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