CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
142 lines
4.8 KiB
C++
142 lines
4.8 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
|
|
|
// <bit>
|
|
|
|
// std::byteswap rejects integer types that have padding bits per
|
|
// [bit.byteswap]/Mandates. The implementation uses static_assert; the
|
|
// diagnostic comes from <__bit/byteswap.h>.
|
|
|
|
#include <bit>
|
|
|
|
#include "test_macros.h"
|
|
|
|
#if TEST_HAS_EXTENSION(bit_int)
|
|
|
|
// Sub-byte widths (sizeof == 1 but bit width below CHAR_BIT)
|
|
void test_unsigned_1() {
|
|
unsigned _BitInt(1) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_unsigned_7() {
|
|
unsigned _BitInt(7) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_signed_7() {
|
|
signed _BitInt(7) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
// Non-byte-aligned widths
|
|
void test_unsigned_13() {
|
|
unsigned _BitInt(13) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_unsigned_17() {
|
|
unsigned _BitInt(17) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_signed_33() {
|
|
signed _BitInt(33) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_unsigned_65() {
|
|
unsigned _BitInt(65) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
// Byte-aligned widths whose value bits don't fill the object representation.
|
|
// On platforms where sizeof(_BitInt(N)) rounds up to a power of two, these
|
|
// types have padding bits in the high-order storage positions even though
|
|
// their value width is a multiple of CHAR_BIT.
|
|
void test_unsigned_24() {
|
|
// sizeof(_BitInt(24)) == 4 on x86_64; 8 padding bits.
|
|
unsigned _BitInt(24) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_unsigned_40() {
|
|
// sizeof(_BitInt(40)) == 8 on x86_64; 24 padding bits.
|
|
unsigned _BitInt(40) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_unsigned_48() {
|
|
// sizeof(_BitInt(48)) == 8 on x86_64; 16 padding bits. Note that the value
|
|
// bit width (48) is a multiple of 16, so __builtin_bswapg accepts it -- the
|
|
// libc++ static_assert is what actually catches this case.
|
|
unsigned _BitInt(48) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
void test_unsigned_56() {
|
|
// sizeof(_BitInt(56)) == 8 on x86_64; 8 padding bits.
|
|
unsigned _BitInt(56) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
|
|
# 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@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
# endif
|
|
|
|
# if __BITINT_MAXWIDTH__ >= 96
|
|
void test_unsigned_96() {
|
|
// sizeof(_BitInt(96)) == 16 on x86_64; 32 padding bits.
|
|
unsigned _BitInt(96) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
# endif
|
|
|
|
# if __BITINT_MAXWIDTH__ >= 112
|
|
void test_unsigned_112() {
|
|
// sizeof(_BitInt(112)) == 16 on x86_64; 16 padding bits.
|
|
unsigned _BitInt(112) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
# endif
|
|
|
|
# if __BITINT_MAXWIDTH__ >= 256
|
|
void test_unsigned_192() {
|
|
// sizeof(_BitInt(192)) == 32 on x86_64; 64 padding bits. Multiple of 16
|
|
// but not of the storage size.
|
|
unsigned _BitInt(192) v = 0;
|
|
// expected-error@*:* {{static assertion failed{{.*}}std::byteswap requires T to have no padding bits}}
|
|
(void)std::byteswap(v);
|
|
}
|
|
# endif
|
|
|
|
#else
|
|
// expected-no-diagnostics
|
|
#endif
|