[clang] [CIR] Guard full-width shift in CIRGenFixedPointBuilder (PR #244504)

Jaeyong Lee via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 17:06:02 PST 2026


================
@@ -295,7 +295,12 @@ struct CIRGenFixedPointBuilder {
         mlir::Value rounded = builder.createAdd(loc, result, lowBits);
         result = builder.createSelect(loc, isNegative, rounded, result);
       }
-      result = builder.createShiftRight(loc, result, srcScale - dstScale);
+      unsigned shift = srcScale - dstScale;
+      assert(shift <= resultWidth && "Shift cannot exceed result width");
+      if (shift < resultWidth)
----------------
npmania wrote:

Since a full-width shift is poison/UB rather than zero, I believe it can't be folded to zero by a cir.shift folder. I followed classic codegen, which also guards this in FixedPointBuilder ([#239969 diff](https://github.com/llvm/llvm-project/pull/239969/changes#diff-323fa85756d9f35500306f6aef754ab6cb6672c40b3fb64ef52f43eb42e20213L63-R70)). Please let me know if things are structured differently on the CIR side.

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


More information about the cfe-commits mailing list