[clang] [clang][bytecode] Fix a crash in Descriptor::getElemDataSize() (PR #196929)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon May 11 04:48:24 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/196929
`FIXED_SIZE_INT_TYPE_SWITCH` does not handle `PT_Bool`, handle it explicitly before.
>From f38355f52087c7f2681d2430320b23517b57556d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 11 May 2026 13:46:06 +0200
Subject: [PATCH] [clang][bytecode] Fix a crash in
Descriptor::getElemDataSize()
`FIXED_SIZE_INT_TYPE_SWITCH` does not handle `PT_Bool`, handle it
explicitly before.
---
clang/lib/AST/ByteCode/Descriptor.cpp | 2 ++
clang/test/AST/ByteCode/literals.cpp | 4 ++++
2 files changed, 6 insertions(+)
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