From f5907ea4f056a287022e4bce93c9b711b4133e5e Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Tue, 16 Aug 2011 00:21:54 +0300 Subject: [PATCH] use WEAKEN-INTEGER-TYPE in ARRAY-IN-BOUNDS-P 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 | 9 ++++++--- tests/compiler.pure.lisp | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/compiler/array-tran.lisp b/src/compiler/array-tran.lisp index 82b3bdb..0610986 100644 --- a/src/compiler/array-tran.lisp +++ b/src/compiler/array-tran.lisp @@ -174,9 +174,12 @@ ;; 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)))) diff --git a/tests/compiler.pure.lisp b/tests/compiler.pure.lisp index 5f24fbe..28b6b7f 100644 --- a/tests/compiler.pure.lisp +++ b/tests/compiler.pure.lisp @@ -3973,3 +3973,9 @@ (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)))) -- 1.7.10.4