Correct address computation in atomic-incf/aref for wide fixnums
authorPaul Khuong <pvk@pvk.ca>
Mon, 7 Nov 2011 19:18:38 +0000 (14:18 -0500)
committerPaul Khuong <pvk@pvk.ca>
Mon, 7 Nov 2011 19:18:38 +0000 (14:18 -0500)
 Reported by Martin Cracauer.

 Fixes lp#887220.

NEWS
src/compiler/x86-64/array.lisp
tests/compiler.pure.lisp

diff --git a/NEWS b/NEWS
index 99ca95c..f79f635 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,8 @@
 ;;;; -*- coding: utf-8; fill-column: 78 -*-
+changes relative to sbcl-1.0.53:
+  * bug fix: on 64-bit targets, atomic-incf/aref does index computation
+    correctly, even on wide-fixnum builds. (lp#887220)
+
 changes in sbcl-1.0.53 relative to sbcl-1.0.52:
   * enhancement: on 64-bit targets, in src/compiler/generic/early-vm.lisp,
     the parameter n-fixnum-tag-bits may now vary from 1 (fixnum =
index 26fd1a9..28060d9 100644 (file)
   (:result-types unsigned-num)
   (:generator 4
     (inst xadd (make-ea :qword :base array
-                        :scale 1 :index index
+                        :scale (ash 1 (- word-shift n-fixnum-tag-bits))
+                        :index index
                         :disp (- (* vector-data-offset n-word-bytes)
                                  other-pointer-lowtag))
           diff :lock)
index 73cc33d..1712620 100644 (file)
   (compile nil `(lambda (x)
                   (declare (type character x))
                   (eql x #\U0010FFFF))))
+
+;; Wide fixnum platforms had buggy address computation in atomic-incf/aref
+(with-test (:name :bug-887220)
+  (let ((incfer (compile
+                 nil
+                 `(lambda (vector index)
+                    (declare (type (simple-array sb-ext:word (4))
+                                   vector)
+                             (type (mod 4) index))
+                    (sb-ext:atomic-incf (aref vector index) 1)
+                    vector))))
+    (assert (equalp (funcall incfer
+                             (make-array 4 :element-type 'sb-ext:word
+                                           :initial-element 0)
+                             1)
+                    #(0 1 0 0)))))