ccl icon indicating copy to clipboard operation
ccl copied to clipboard

Incorrect value computed in integer code

Open pfdietz opened this issue 7 years ago • 1 comments

Compiling this function:

(defun f320 (b)
  (declare (type (integer -68847508698084903 448367229394151423) b))
  (declare (optimize (safety 1) (speed 3)))
  (setf b (min 448367229394151423 (max -68847508698084903 (+ b b 0 b)))))

gives incorrect code

(f320 390985184385489915) should be 448367229394151423, but it returns -68847508698084903

pfdietz avatar Oct 28 '18 02:10 pfdietz

Because b is type-constrained, maybe the compiler is assuming that all the subforms of (min ...) have to be of that same constrained type? It's doing the addition operations without overflow checking.

If we don't set b, but just return the value of the (min ...) form directly, then we get the right answer.

xrme avatar May 22 '24 04:05 xrme