[clang] 9830c43 - [clang][bytecode] Fix a crash in Descriptor::getElemDataSize() (#196929)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 11 06:20:53 PDT 2026
Author: Timm Baeder
Date: 2026-05-11T15:20:48+02:00
New Revision: 9830c433751d9d998f739d74b12a9a5a22928542
URL: https://github.com/llvm/llvm-project/commit/9830c433751d9d998f739d74b12a9a5a22928542
DIFF: https://github.com/llvm/llvm-project/commit/9830c433751d9d998f739d74b12a9a5a22928542.diff
LOG: [clang][bytecode] Fix a crash in Descriptor::getElemDataSize() (#196929)
`FIXED_SIZE_INT_TYPE_SWITCH` does not handle `PT_Bool`, handle it
explicitly before.
Added:
Modified:
clang/lib/AST/ByteCode/Descriptor.cpp
clang/test/AST/ByteCode/literals.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp
index 729df4f200e30..2d7561480f645 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -493,6 +493,8 @@ bool Descriptor::isUnion() const { return isRecord() && ElemRecord->isUnion(); }
unsigned Descriptor::getElemDataSize() const {
if ((isPrimitive() || isPrimitiveArray()) &&
isIntegerOrBoolType(getPrimType())) {
+ if (getPrimType() == PT_Bool)
+ return 1;
FIXED_SIZE_INT_TYPE_SWITCH(getPrimType(), { return T::bitWidth() / 8; });
}
return ElemSize;
diff --git a/clang/test/AST/ByteCode/literals.cpp b/clang/test/AST/ByteCode/literals.cpp
index f7eae07c8060a..8d39d6772a923 100644
--- a/clang/test/AST/ByteCode/literals.cpp
+++ b/clang/test/AST/ByteCode/literals.cpp
@@ -1503,3 +1503,7 @@ namespace ExternRedecl {
constexpr int a = 10;
static_assert(*p == 10, "");
}
+
+namespace GetElemDataSizeBool {
+ int foo[(intptr_t)(bool *)0]; // both-warning {{variable length array folded to constant array as an extension}}
+}
More information about the cfe-commits
mailing list