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

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 10 00:49:33 PDT 2025


================
@@ -2200,6 +2200,32 @@ static bool BuiltinCpu(Sema &S, const TargetInfo &TI, CallExpr *TheCall,
   return false;
 }
 
+/// Checks that __builtin_bswapg was called with a single argument, which is an
+/// unsigned integer, and overrides the return value type to the integer type.
+static bool BuiltinBswapg(Sema &S, CallExpr *TheCall) {
+  if (S.checkArgCount(TheCall, 1))
+    return true;
+  ExprResult ArgRes = S.DefaultLvalueConversion(TheCall->getArg(0));
+  if (ArgRes.isInvalid())
+    return true;
+
+  Expr *Arg = ArgRes.get();
+  TheCall->setArg(0, Arg);
+  if (Arg->isTypeDependent())
+    return false;
+
+  QualType ArgTy = Arg->getType();
+
+  if (!ArgTy->isIntegerType()) {
+    S.Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+        << 1 << /* scalar */ 1 << /* unsigned integer ty */ 1 << /* no fp */ 0
----------------
cor3ntin wrote:

Indeed !

```suggestion
        << 1 << /*scalar=*/ 1 << /*unsigned integer=*/ 1 << /*floating point=*/ 0
```

However we are super inconsistent if you search for uses of `err_builtin_invalid_arg_type` elsewhere, so i could go either way.

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


More information about the cfe-commits mailing list