[clang] [clang] Implement __builtin_stdc_rotate_left, __builtin_stdc_rotate_right (PR #160259)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 3 13:26:11 PDT 2025
================
@@ -14166,7 +14160,37 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), Amt, Info))
return false;
- return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
+ // Normalize shift amount to [0, BitWidth) range to match runtime behavior
+ unsigned BitWidth = Val.getBitWidth();
+ unsigned AmtBitWidth = Amt.getBitWidth();
+ APSInt Divisor;
+ if (AmtBitWidth > BitWidth) {
+ Divisor = APSInt(llvm::APInt(AmtBitWidth, BitWidth), Amt.isUnsigned());
+ } else {
+ Divisor = APSInt(llvm::APInt(BitWidth, BitWidth), Amt.isUnsigned());
----------------
efriedma-quic wrote:
Bitwidth fits into BitWidth bits, yes... unless you have `(_BitInt(1))-1`, in which case I think this is flipping the sign.
https://github.com/llvm/llvm-project/pull/160259
More information about the cfe-commits
mailing list