[clang] d4f4b2f - [clang] Fix sizeof of boolean vector
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 26 07:58:40 PST 2023
Author: Mariya Podchishchaeva
Date: 2023-01-26T10:44:15-05:00
New Revision: d4f4b2fe21dddff023aeab775dd63b321e23f918
URL: https://github.com/llvm/llvm-project/commit/d4f4b2fe21dddff023aeab775dd63b321e23f918
DIFF: https://github.com/llvm/llvm-project/commit/d4f4b2fe21dddff023aeab775dd63b321e23f918.diff
LOG: [clang] Fix sizeof of boolean vector
Ensure it is at least 8 bits.
Fixes #59801
Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D142550
Added:
Modified:
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/vector-bool.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 18a041d7a72ab..bdbf1891190e4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2076,7 +2076,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
TypeInfo EltInfo = getTypeInfo(VT->getElementType());
Width = VT->isExtVectorBoolType() ? VT->getNumElements()
: EltInfo.Width * VT->getNumElements();
- // Enforce at least byte alignment.
+ // Enforce at least byte size and alignment.
+ Width = std::max<unsigned>(8, Width);
Align = std::max<unsigned>(8, Width);
// If the alignment is not a power of 2, round up to the next power of 2.
diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp
index 1b83a20999cb2..e99d420e73fab 100644
--- a/clang/test/SemaCXX/vector-bool.cpp
+++ b/clang/test/SemaCXX/vector-bool.cpp
@@ -90,3 +90,25 @@ bool* ElementRefs() {
foo(eight_bools.w); // expected-error at 90 {{illegal vector component name ''w''}}
foo(eight_bools.wyx); // expected-error at 91 {{illegal vector component name ''wyx''}}
}
+
+void Sizeof() {
+ using FourBools = bool __attribute__((ext_vector_type(4)));
+ using NineBools = bool __attribute__((ext_vector_type(9)));
+ using TwentyEightBools = bool __attribute__((ext_vector_type(28)));
+ using ThirtyThreeBools = bool __attribute__((ext_vector_type(33)));
+ using SixtyFiveBools = bool __attribute__((ext_vector_type(65)));
+ using Bool129 = bool __attribute__((ext_vector_type(129)));
+ using Bool150 = bool __attribute__((ext_vector_type(150)));
+ using Bool195 = bool __attribute__((ext_vector_type(195)));
+ using Bool257 = bool __attribute__((ext_vector_type(257)));
+ static_assert(sizeof(FourBools) == 1);
+ static_assert(sizeof(EightBools) == 1);
+ static_assert(sizeof(NineBools) == 2);
+ static_assert(sizeof(TwentyEightBools) == 4);
+ static_assert(sizeof(ThirtyThreeBools) == 8);
+ static_assert(sizeof(SixtyFiveBools) == 16);
+ static_assert(sizeof(Bool129) == 32);
+ static_assert(sizeof(Bool150) == 32);
+ static_assert(sizeof(Bool195) == 32);
+ static_assert(sizeof(Bool257) == 64);
+}
More information about the cfe-commits
mailing list