[clang] [Clang] Add __builtin_bswapg (PR #162433)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 12:18:37 PDT 2025


================
@@ -130,7 +130,7 @@ int main(void) {
   P(object_size, (s0, 3));
 
   // Whatever
-
+  P(bswapg, (N));
   P(bswap16, (N));
   P(bswap32, (N));
   P(bswap64, (N));
----------------
ojhunt wrote:

Ok, I don't know why the existing ones don't have output tests, I think you should probably add expectation results for these as well, when adding tests for bswapg.

Because bswapg does operate generically you should add tests for `P(bswapg, ((char)N)`, `P(bswapg, ((short)N)`, etc which I believe you should be able to test for with something like `// CHECK: @llvm.bswap...`

In the C++ tests you should also add type checks, something like:

```cpp
template <class A, class B> static constexpr bool is_same_type = false;
template <class A> static constexpr bool is_same_type<A, A> = true;
// ...
static_assert(is_same_type<some_type, decltype(__builtin_bswapg((some_type)0)); // for the various correct types
```

https://github.com/llvm/llvm-project/pull/162433


More information about the cfe-commits mailing list