[PATCH] D142550: Fix sizeof of boolean vector

Mariya Podchishchaeva via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 25 09:23:46 PST 2023


Fznamznon updated this revision to Diff 492151.
Fznamznon added a comment.

Add a case with vector of length 33


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142550/new/

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,15 @@
   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)));
+  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);
+}
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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142550.492151.patch
Type: text/x-patch
Size: 1551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230125/de3295a8/attachment.bin>


More information about the cfe-commits mailing list