[clang] [clang] Implement __builtin_stdc_rotate_left, __builtin_stdc_rotate_right (PR #160259)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 26 15:11:07 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,c -- clang/test/Sema/builtin-stdc-rotate.c clang/test/SemaCXX/constexpr-builtin-stdc-rotate.cpp clang/lib/AST/ExprConstant.cpp clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaChecking.cpp clang/test/CodeGen/builtin-rotate.c
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 71c5ae8d5..8f38420da 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14171,27 +14171,28 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
     // Determine rotation direction
     bool IsRotateRight;
     switch (BuiltinOp) {
-      case Builtin::BI__builtin_rotateright8:
-      case Builtin::BI__builtin_rotateright16:
-      case Builtin::BI__builtin_rotateright32:
-      case Builtin::BI__builtin_rotateright64:
-      case Builtin::BI__builtin_stdc_rotate_right:
-      case Builtin::BI_rotr8:
-      case Builtin::BI_rotr16:
-      case Builtin::BI_rotr:
-      case Builtin::BI_lrotr:
-      case Builtin::BI_rotr64:
-        IsRotateRight = true;
-        break;
-      default:
-        IsRotateRight = false;
-        break;
+    case Builtin::BI__builtin_rotateright8:
+    case Builtin::BI__builtin_rotateright16:
+    case Builtin::BI__builtin_rotateright32:
+    case Builtin::BI__builtin_rotateright64:
+    case Builtin::BI__builtin_stdc_rotate_right:
+    case Builtin::BI_rotr8:
+    case Builtin::BI_rotr16:
+    case Builtin::BI_rotr:
+    case Builtin::BI_lrotr:
+    case Builtin::BI_rotr64:
+      IsRotateRight = true;
+      break;
+    default:
+      IsRotateRight = false;
+      break;
     }
 
     // Perform the rotation
-    APSInt Result = IsRotateRight ?
-      APSInt(Val.rotr(NormalizedAmt.getZExtValue()), Val.isUnsigned()) :
-      APSInt(Val.rotl(NormalizedAmt.getZExtValue()), Val.isUnsigned());
+    APSInt Result =
+        IsRotateRight
+            ? APSInt(Val.rotr(NormalizedAmt.getZExtValue()), Val.isUnsigned())
+            : APSInt(Val.rotl(NormalizedAmt.getZExtValue()), Val.isUnsigned());
 
     return Success(Result, E);
   }

``````````

</details>


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


More information about the cfe-commits mailing list