[libcxx-commits] [libcxx] 6f9ac38 - [libc++][test] Cover byteswap _BitInt padding on every ABI with width 72 (#206360)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 2 02:09:44 PDT 2026
Author: Xavier Roche
Date: 2026-07-02T17:09:39+08:00
New Revision: 6f9ac38b7c1934fbce49683e32c732c73e5e1ab4
URL: https://github.com/llvm/llvm-project/commit/6f9ac38b7c1934fbce49683e32c732c73e5e1ab4
DIFF: https://github.com/llvm/llvm-project/commit/6f9ac38b7c1934fbce49683e32c732c73e5e1ab4.diff
LOG: [libc++][test] Cover byteswap _BitInt padding on every ABI with width 72 (#206360)
`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)
---------
Co-authored-by: Claude Opus 4.6 <noreply at anthropic.com>
Co-authored-by: A. Jiang <de34 at live.cn>
Added:
Modified:
libcxx/test/std/numerics/bit/byteswap.verify.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/numerics/bit/byteswap.verify.cpp b/libcxx/test/std/numerics/bit/byteswap.verify.cpp
index f9b6954f525da..bbd3312a2457a 100644
--- a/libcxx/test/std/numerics/bit/byteswap.verify.cpp
+++ b/libcxx/test/std/numerics/bit/byteswap.verify.cpp
@@ -103,23 +103,20 @@ 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.
+# 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