[libcxx-commits] [libcxx] [libc++][test] Cover byteswap _BitInt padding on every ABI with width 72 (PR #206360)
Xavier Roche via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jun 28 12:26:52 PDT 2026
https://github.com/xroche updated https://github.com/llvm/llvm-project/pull/206360
>From 9416d0d71902f65c93271943d01eddd09be707ac Mon Sep 17 00:00:00 2001
From: Xavier Roche <xavier.roche at algolia.com>
Date: Sun, 28 Jun 2026 21:10:43 +0200
Subject: [PATCH] [libc++][test] Cover byteswap _BitInt padding on every ABI
with width 72
The byteswap padding-bit test added in #196512 used unsigned _BitInt(96),
which #205295 had to skip on 32-bit x86: the i386 System V ABI aligns
_BitInt to 4 bytes and packs _BitInt(96) into exactly 12 bytes with no
padding, so std::byteswap accepts it and the expected diagnostic never
fires. The skip used !defined(__i386__) as a stand-in because the object
layout that drives the result is not visible to the preprocessor.
Use unsigned _BitInt(72) instead. Its 9 value bytes round up to 12 on
32-bit x86 and 16 everywhere else, so the type always carries padding and
std::byteswap always rejects it. The case now runs on every target,
including 32-bit x86, with no target check.
Assisted-by: Claude (Anthropic)
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
---
.../test/std/numerics/bit/byteswap.verify.cpp | 22 +++++++++----------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/libcxx/test/std/numerics/bit/byteswap.verify.cpp b/libcxx/test/std/numerics/bit/byteswap.verify.cpp
index f9b6954f525da..a8026b41c0f18 100644
--- a/libcxx/test/std/numerics/bit/byteswap.verify.cpp
+++ b/libcxx/test/std/numerics/bit/byteswap.verify.cpp
@@ -103,23 +103,21 @@ void test_unsigned_56() {
// Same dispatch-availability guard as test_unsigned_65 above.
# if TEST_HAS_BUILTIN(__builtin_bswapg) || !defined(TEST_HAS_NO_INT128)
-# if __BITINT_MAXWIDTH__ >= 80
-void test_unsigned_80() {
- // sizeof(_BitInt(80)) == 16 on x86_64; 48 padding bits. Width 80 is also
- // a multiple of 16, so bswapg would accept it without the static_assert.
- unsigned _BitInt(80) v = 0;
+// 72 value bits leave padding on every ABI, unlike _BitInt(96), which is
+// exactly 12 bytes with no padding on 32-bit x86 (#205295).
+# if __BITINT_MAXWIDTH__ >= 72
+void test_unsigned_72() {
+ unsigned _BitInt(72) v = 0;
// expected-error-re@*:* {{{{(std::byteswap requires T to have no padding bits|byteswap is unimplemented for integral types of this size)}}}}
(void)std::byteswap(v);
}
# endif
-// 32-bit x86 packs _BitInt(96) into 12 bytes (no padding), so std::byteswap
-// accepts it there; gate the case out. sizeof isn't available to the
-// preprocessor, so this is a target check rather than a has-padding predicate.
-# if __BITINT_MAXWIDTH__ >= 96 && !defined(__i386__)
-void test_unsigned_96() {
- // sizeof(_BitInt(96)) == 16 here; 32 padding bits.
- unsigned _BitInt(96) v = 0;
+# if __BITINT_MAXWIDTH__ >= 80
+void test_unsigned_80() {
+ // sizeof(_BitInt(80)) == 16 on x86_64; 48 padding bits. Width 80 is also
+ // a multiple of 16, so bswapg would accept it without the static_assert.
+ unsigned _BitInt(80) v = 0;
// expected-error-re@*:* {{{{(std::byteswap requires T to have no padding bits|byteswap is unimplemented for integral types of this size)}}}}
(void)std::byteswap(v);
}
More information about the libcxx-commits
mailing list