use WEAKEN-INTEGER-TYPE in ARRAY-IN-BOUNDS-P
authorNikodemus Siivola <nikodemus@random-state.net>
Mon, 15 Aug 2011 21:21:54 +0000 (00:21 +0300)
committerNikodemus Siivola <nikodemus@random-state.net>
Mon, 22 Aug 2011 11:17:18 +0000 (14:17 +0300)
  The type of the bound might be a union-type. WEAKEN-INTEGER-TYPE
  gives us the ends of a range.

  lp#826970

src/compiler/array-tran.lisp
tests/compiler.pure.lisp

index 82b3bdb..0610986 100644 (file)
         ;; we can already decide on the result of the optimization without
         ;; even taking a look at the dimensions.
         (flet ((subscript-bounds (subscript)
-                 (let* ((type (lvar-type subscript))
-                        (low (numeric-type-low type))
-                        (high (numeric-type-high type)))
+                 (let* ((type1 (lvar-type subscript))
+                        (type2 (if (csubtypep type1 (specifier-type 'integer))
+                                   (weaken-integer-type type1)
+                                   (give-up)))
+                        (low (numeric-type-low type2))
+                        (high (numeric-type-high type2)))
                    (cond
                      ((and (or (not (bound-known-p low)) (minusp low))
                            (or (not (bound-known-p high)) (not (minusp high))))
index 5f24fbe..28b6b7f 100644 (file)
                              (declare (optimize (safety 0)))
                              (apply #'cons rest)))))
     (assert (equal '(car . cdr) (funcall fun 'car 'cdr)))))
+
+(with-test (:name :bug-826970)
+  (let ((fun (compile nil `(lambda (a b c)
+                             (declare (type (member -2 1) b))
+                             (array-in-bounds-p a 4 b c)))))
+    (assert (funcall fun (make-array '(5 2 2)) 1 1))))