[clang] [clang] Implement __builtin_stdc_rotate_left, __builtin_stdc_rotate_right (PR #160259)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 25 14:48:15 PST 2025
================
@@ -15774,7 +15768,53 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
!EvaluateInteger(E->getArg(1), Amt, Info))
return false;
- return Success(Val.rotr(Amt), E);
+ // Normalize shift amount to [0, BitWidth) range to match runtime behavior
+ unsigned BitWidth = Val.getBitWidth();
+ unsigned AmtBitWidth = Amt.getBitWidth();
+ if (BitWidth == 1) {
+ // Rotating a 1-bit value is always a no-op
+ Amt = APSInt(APInt(AmtBitWidth, 0), Amt.isUnsigned());
+ } else {
+ // Divisor is always unsigned to avoid misinterpreting BitWidth as
+ // negative in small bit widths (e.g., BitWidth=2 would be -2 if signed).
+ APSInt Divisor;
----------------
efriedma-quic wrote:
You can declare Divisor as an APInt; every use coerces from APSInt to APInt anyway.
https://github.com/llvm/llvm-project/pull/160259
More information about the cfe-commits
mailing list