ccl
ccl copied to clipboard
Incorrect value computed in integer code
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
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.