================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to