Take bitwidth into account in BOOLEAN alien type
authorPaul Khuong <pvk@pvk.ca>
Mon, 20 May 2013 03:47:13 +0000 (23:47 -0400)
committerPaul Khuong <pvk@pvk.ca>
Mon, 20 May 2013 05:05:56 +0000 (01:05 -0400)
Some ABIs (x86/x86-64) allow garbage in unused upper bits of return
values; take that into account when converting BOOLEAN return types
to CL BOOLEANs.

NEWS
src/code/host-alieneval.lisp

diff --git a/NEWS b/NEWS
index 2b413ca..dd9b144 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,8 @@ changes relative to sbcl-1.1.7:
     modular arithemtic (mostly to exploit fixnum-width VOPs). (lp#1026634)
   * bug fix: a combination of inlined local function with &optional and
     recursion no longer causes undescriptive compiler errors. (lp#1180992)
+  * bug fix: sub-word BOOLEAN alien types now disregard higher order bits
+    when testing for non-zero-ness.
   * optimization: faster ISQRT on fixnums and small bignums
   * optimization: faster and smaller INTEGER-LENGTH on fixnums on x86-64.
   * optimization: On x86-64, the number of multi-byte NOP instructions used
index 8e61909..c78853f 100644 (file)
   `(member t nil))
 
 (define-alien-type-method (boolean :naturalize-gen) (type alien)
-  (declare (ignore type))
-  `(not (zerop ,alien)))
+  (let ((bits (alien-boolean-type-bits type)))
+    (if (= bits sb!vm:n-word-bits)
+        `(not (zerop ,alien))
+        `(logtest ,alien ,(ldb (byte bits 0) -1)))))
 
 (define-alien-type-method (boolean :deport-gen) (type value)
   (declare (ignore type))