[clang] [clang][ExprConst] Don't pass invalid decls to ASTRecordLayout (PR #203817)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 14 21:06:15 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
It will assert.
Fixes https://github.com/llvm/llvm-project/issues/203755
---
Full diff: https://github.com/llvm/llvm-project/pull/203817.diff
3 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+2)
- (modified) clang/lib/AST/ExprConstant.cpp (+2)
- (modified) clang/test/AST/ByteCode/builtin-bit-cast.cpp (+8)
``````````diff
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);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/203817
More information about the cfe-commits
mailing list