Incorrect value in integer expression in 1.1.9

Bug #1199428 reported by Paul F. Dietz on 2013-07-09
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

(defun test-2013-0709-1 ()
  (let ((a 530436387)
 (c -4890629672277))
    (list (f1 a c) (f2 a c))))

(defun f1 (a c)
  (declare (type (integer -2 1217810089) a))
  (declare (type (integer -6895591104928 -561736648588) c))
  (declare (optimize (speed 2) (space 0) (safety 2) (debug 0)
       (compilation-speed 3)))
  (logandc1 (gcd c)
     (+ (- a c)
        (loop for lv2 below 1 count t)

(defun f2 (a c)
  (declare (notinline - + gcd logandc1))
  (declare (optimize (speed 1) (space 1) (safety 0) (debug 1)
       (compilation-speed 3)))
  (logandc1 (gcd c)
     (+ (- a c)
        (loop for lv2 below 1 count t))))

;; In SBCL 1.1.9 (x86-64 Linux):
;; (test-2013-0709-1) ==> (9223372038192779816 1338004008)
;; (the first value is incorrect)
;; This was found by the usual random testing.

Paul F. Dietz (paul-dietz) wrote :

;; Perhaps related:

(defun test-2013-0709-2 ()
  (let ((a -1491588365)
 (b -3745511761))
    (list (g1 a b) (g2 a b))))

(defun g1 (a b)
  (declare (type (integer -1869232508 -6939151) a))
  (declare (type (integer -11466348357 -2645644006) b))
  (declare (optimize (speed 1) (space 0) (safety 2) (debug 2)
       (compilation-speed 2)))
  (logand (lognand a -6) (* b -502823994)))

(defun g2 (a b)
  (logand (lognand a -6) (* b -502823994)))

;; In SBCL 1.1.9 (x86 64 Linux),
;; (test-2013-0709-2) ==> (9223372037939105800 1084329992)

Paul Khuong (pvk) wrote :

This patch fixes both issues. I'm pretty sure the problem is when we perform non-trivial replacement (e.g. lognot -> lognot-mod64), the result isn't necessarily cut to the right width: it's actually widened to the VOP's width. So, we "only" need to track when we perform such replacements, and insert actually cutting operations (logand/mask-signed-field) after the final result.

Hopefully, we can have a second opinion and I'll commit the conclusion around the end of the week.

Changed in sbcl:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → Paul Khuong (pvk)
Paul Khuong (pvk) wrote :

Should be fixed in df2d632 (Insert explicit cut to width when needed). Thank you for the test case!

Changed in sbcl:
status: In Progress → Fix Committed
assignee: Paul Khuong (pvk) → nobody
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers