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

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 10 03:01:26 PDT 2025


================
@@ -755,6 +755,12 @@ def BSwap : Builtin, Template<["unsigned short", "uint32_t", "uint64_t"],
   let Prototype = "T(T)";
 }
 
+def BSwapg : Builtin {
+  let Spellings = ["__builtin_bswapg"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "int(...)";
----------------
clingfei wrote:

> IIRC `T(T)` assumes an explicit set of type mappings. In _principle_ I think this could be labeled as `T(T)` with the customtypechecking flag. That would be more correct than `int(..)`, and the Sema work is already doing the custom checking.

In fact, at first I attempted to use T(T) with an explicit set of type mappings, but the automatically generated builtin functions are bswapg16, bswapg32, etc., rather than a single generic bswapg. I'm not sure if I can use T(T) without making more modifications to clang. It would be nice if that worked.

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


More information about the cfe-commits mailing list