Fznamznon created this revision. Herald added a project: All. Fznamznon requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Ensure it is at least 8 bits. Fixes #59801 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D142550 Files: clang/lib/AST/ASTContext.cpp clang/test/SemaCXX/vector-bool.cpp Index: clang/test/SemaCXX/vector-bool.cpp =================================================================== --- clang/test/SemaCXX/vector-bool.cpp +++ clang/test/SemaCXX/vector-bool.cpp @@ -90,3 +90,9 @@ foo(eight_bools.w); // expected-error@90 {{illegal vector component name ''w''}} foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}} } + +void Sizeof() { + using FourBools = bool __attribute__((ext_vector_type(8))); + static_assert(sizeof(FourBools) == 1); + static_assert(sizeof(EightBools) == 1); +} Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -2002,7 +2002,8 @@ 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.
Index: clang/test/SemaCXX/vector-bool.cpp =================================================================== --- clang/test/SemaCXX/vector-bool.cpp +++ clang/test/SemaCXX/vector-bool.cpp @@ -90,3 +90,9 @@ foo(eight_bools.w); // expected-error@90 {{illegal vector component name ''w''}} foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}} } + +void Sizeof() { + using FourBools = bool __attribute__((ext_vector_type(8))); + static_assert(sizeof(FourBools) == 1); + static_assert(sizeof(EightBools) == 1); +} Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -2002,7 +2002,8 @@ 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits