[clang] [clang][bytecode] Fix a crash with an invalid Descriptor (PR #224231)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 02:07:35 PDT 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/224231
>From 5d1a57fc3e7487eb5d16cfd5c9b7e49a292a3bd3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 17 Sep 2026 09:56:40 +0200
Subject: [PATCH] [clang][bytecode] Fix a crash with an invalid Descriptor
It's neither a record nor an array.
---
clang/lib/AST/ByteCode/EvaluationResult.cpp | 3 +--
clang/test/AST/ByteCode/invalid.cpp | 15 +++++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index 5d232c5414e04..09b1eb822b13e 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -55,8 +55,7 @@ static bool CheckArrayInitialized(InterpState &S, SourceLocation Loc,
PtrView ElemPtr = BasePtr.atIndex(I).narrow();
Result &= CheckFieldsInitialized(S, Loc, ElemPtr, R);
}
- } else {
- assert(ElemDesc->isArray());
+ } else if (ElemDesc->isArray()) {
for (size_t I = 0; I != NumElems; ++I) {
PtrView ElemPtr = BasePtr.atIndex(I).narrow();
Result &= CheckArrayInitialized(S, Loc, ElemPtr);
diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp
index 2e822e0b56d91..3dd2dc91df9c1 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -267,3 +267,18 @@ namespace SubPtrResultIs1 {
struct C : A, B {};
unsigned char x = ((char **)(B *)(C *)0x1000) - (char *)0x1000; // both-error {{not pointers to compatible types}}
}
+
+namespace NonRecordNonArrayDesc {
+
+ struct S { // both-note {{definition of 'NonRecordNonArrayDesc::S' is not complete until the closing '}'}}
+ const S(foo[42]) : bar{}; // both-error {{use of undeclared identifier 'bar'}} \
+ // both-error {{field has incomplete type 'const S'}}
+ };
+
+ struct F {
+ _Atomic(S) a;
+ constexpr F(int i) {};
+ };
+
+ F foo(42);
+}
More information about the cfe-commits
mailing list