[libcxx-commits] [libcxx] [libc++][test] Cover byteswap _BitInt padding on every ABI with width 72 (PR #206360)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 29 02:03:46 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Xavier Roche (xroche)
<details>
<summary>Changes</summary>
`std::byteswap` is required to reject integer types that have padding bits, and one test case checks that it does. The case used `unsigned _BitInt(96)`, but #<!-- -->205295 had to skip it on 32-bit x86. On the i386 System V ABI, `_BitInt(96)` is exactly 12 bytes with no padding, so `std::byteswap` accepts it and the expected error never fires. The skip used `!defined(__i386__)`, a target name that stands in for an object layout the preprocessor cannot see.
This change uses `unsigned _BitInt(72)` instead. Its 9 value bytes round up to 12 bytes on 32-bit x86 and 16 bytes everywhere else, so the type always has padding and `std::byteswap` always rejects it. The case now runs on every target, 32-bit x86 included, with no target guard.
Follows up on #<!-- -->205295.
Assisted-by: Claude (Anthropic)
---
Full diff: https://github.com/llvm/llvm-project/pull/206360.diff
1 Files Affected:
- (modified) libcxx/test/std/numerics/bit/byteswap.verify.cpp (+10-12)
``````````diff
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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/206360
More information about the libcxx-commits
mailing list