[clang] [test] Add bit < 8 testcase for x86 __builtin_bswapg (PR #180124)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 5 21:54:57 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: woruyu (woruyu)
<details>
<summary>Changes</summary>
### Summary
the related PR: https://github.com/llvm/llvm-project/pull/179177, add bits < 8 testcase for __builtin_bswapg
---
Full diff: https://github.com/llvm/llvm-project/pull/180124.diff
3 Files Affected:
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+3)
- (modified) clang/test/Sema/constant-builtins-2.c (+2)
- (modified) clang/test/SemaCXX/builtin-bswapg.cpp (+2)
``````````diff
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 10f7ff294ae00..779bb450084b3 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -851,6 +851,9 @@ namespace bswap {
int h15 = __builtin_bswapg((_BitInt(24))0x1234) == (_BitInt(24))0x3412 ? 1 : f();
// expected-error at -1 {{_BitInt type '_BitInt(24)' (24 bits) must be a multiple of 16 bits for byte swapping}}
// ref-error at -2 {{_BitInt type '_BitInt(24)' (24 bits) must be a multiple of 16 bits for byte swapping}}
+ int h16 = __builtin_bswapg((_BitInt(5))0x1) == (_BitInt(5))0x1 ? 1 : f();
+ // expected-error at -1 {{_BitInt type '_BitInt(5)' (5 bits) must be a multiple of 16 bits for byte swapping}}
+ // ref-error at -2 {{_BitInt type '_BitInt(5)' (5 bits) must be a multiple of 16 bits for byte swapping}}
#endif
constexpr const int const_expr = 0x1234;
diff --git a/clang/test/Sema/constant-builtins-2.c b/clang/test/Sema/constant-builtins-2.c
index e875863e7fa91..3c437fcbe5e0d 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -502,6 +502,8 @@ int h21 = __builtin_bswapg((_BitInt(64))0x0000000000001234) == (_BitInt(64))0x34
int h22 = __builtin_bswapg(~(_BitInt(128))0) == (~(_BitInt(128))0) ? 1 : f();
int h23 = __builtin_bswapg((_BitInt(24))0x1234) == (_BitInt(24))0x3412 ? 1 : f();
// expected-error at -1 {{_BitInt type '_BitInt(24)' (24 bits) must be a multiple of 16 bits for byte swapping}}
+int h24 = __builtin_bswapg((_BitInt(3))0x3) == (_BitInt(3))0x3 ? 1 : f();
+// expected-error at -1 {{_BitInt type '_BitInt(3)' (3 bits) must be a multiple of 16 bits for byte swapping}}
extern long int bi0;
extern __typeof__(__builtin_expect(0, 0)) bi0;
diff --git a/clang/test/SemaCXX/builtin-bswapg.cpp b/clang/test/SemaCXX/builtin-bswapg.cpp
index 815cc0085f89e..88c387d5c4004 100644
--- a/clang/test/SemaCXX/builtin-bswapg.cpp
+++ b/clang/test/SemaCXX/builtin-bswapg.cpp
@@ -228,4 +228,6 @@ void test_bitint() {
static_assert(__builtin_bswapg(~(_BitInt(128))0) == (~(_BitInt(128))0), "");
static_assert(__builtin_bswapg((_BitInt(24))0x1234) == (_BitInt(24))0x3412, "");
// expected-error at -1 {{_BitInt type '_BitInt(24)' (24 bits) must be a multiple of 16 bits for byte swapping}}
+ static_assert(__builtin_bswapg((_BitInt(4))0x7) == (_BitInt(4))0x7, "");
+ // expected-error at -1 {{_BitInt type '_BitInt(4)' (4 bits) must be a multiple of 16 bits for byte swapping}}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/180124
More information about the cfe-commits
mailing list