+
+;;; reported by Lutz Euler: we shouldn't signal a compiler note for
+;;; simple-bit-vector functions.
+(handler-bind ((sb-ext:compiler-note #'error))
+ (compile nil '(lambda (x)
+ (declare (type simple-bit-vector x))
+ (count 1 x))))
+(handler-bind ((sb-ext:compiler-note #'error))
+ (compile nil '(lambda (x y)
+ (declare (type simple-bit-vector x y))
+ (equal x y))))
+
+;;; MISC.550: CAST merging in IR1 finalization caused unexpected
+;;; code transformations.
+(assert (eql (funcall
+ (compile
+ nil
+ '(lambda (p1 p2)
+ (declare (optimize (speed 3) (safety 2) (debug 3) (space 3))
+ (type atom p1)
+ (type symbol p2))
+ (or p1 (the (eql t) p2))))
+ nil t)
+ t))
+
+;;; MISC.548: type check weakening converts required type into
+;;; optional
+(assert (eql t
+ (funcall
+ (compile
+ nil
+ '(lambda (p1)
+ (declare (optimize (speed 2) (safety 1) (debug 3) (space 2)))
+ (atom (the (member f assoc-if write-line t w) p1))))
+ t)))
+
+;;; Free special bindings only apply to the body of the binding form, not
+;;; the initialization forms.
+(assert (eq :good
+ (funcall (compile 'nil
+ (lambda ()
+ (let ((x :bad))
+ (declare (special x))
+ (let ((x :good))
+ ((lambda (&optional (y x))
+ (declare (special x)) y)))))))))
+
+;;; Bug from pfdietz's random tester: the compiler knew that IMAGPART of
+;;; a rational was zero, but didn't do the substitution, leading to a
+;;; crash in the ASH vop (since a shift of 57 wouldn't fit in the
+;;; machine's ASH instruction's immediate field) that the compiler
+;;; thought was legitimate.
+;;;
+;;; FIXME: this has been recorded as bug 383. The attempted fix (sbcl
+;;; 0.9.2.6) led to lots of spurious optimization notes. So the bug stil
+;;; exist and this test case serves as a reminder of the problem.
+;;; --njf, 2005-07-05
+#+nil
+(compile 'nil
+ (LAMBDA (B)
+ (DECLARE (TYPE (INTEGER -2 14) B))
+ (DECLARE (IGNORABLE B))
+ (ASH (IMAGPART B) 57)))
+
+;;; bug reported by Eduardo Mu\~noz
+(multiple-value-bind (fun warnings failure)
+ (compile nil '(lambda (struct first)
+ (declare (optimize speed))
+ (let* ((nodes (nodes struct))
+ (bars (bars struct))
+ (length (length nodes))
+ (new (make-array length :fill-pointer 0)))
+ (vector-push first new)
+ (loop with i fixnum = 0
+ for newl fixnum = (length new)
+ while (< newl length) do
+ (let ((oldl (length new)))
+ (loop for j fixnum from i below newl do
+ (dolist (n (node-neighbours (aref new j) bars))
+ (unless (find n new)
+ (vector-push n new))))
+ (setq i oldl)))
+ new)))
+ (declare (ignore fun warnings failure))
+ (assert (not failure)))
+
+;;; bug #389: "0.0 can't be converted to type NIL." (Brian Rowe
+;;; sbcl-devel)
+(compile nil '(lambda (x y a b c)
+ (- y (* (signum x) (sqrt (abs (- (* b x) c)))))))
+
+;;; Type inference from CHECK-TYPE
+(let ((count0 0) (count1 0))
+ (handler-bind ((sb-ext:compiler-note (lambda (c) (incf count0))))
+ (compile nil '(lambda (x)
+ (declare (optimize (speed 3)))
+ (1+ x))))
+ ;; forced-to-do GENERIC-+, etc
+ (assert (> count0 0))
+ (handler-bind ((sb-ext:compiler-note (lambda (c) (incf count1))))
+ (compile nil '(lambda (x)
+ (declare (optimize (speed 3)))
+ (check-type x fixnum)
+ (1+ x))))
+ (assert (= count1 0)))
+
+;;; Up to 0.9.8.22 x86-64 had broken return value handling in the
+;;; %SET-SAP-REF-DOUBLE/SINGLE VOPs.
+(with-test (:name :sap-ref-float)
+ (compile nil '(lambda (sap)
+ (let ((x (setf (sb-vm::sap-ref-double sap 0) 1d0)))
+ (1+ x))))
+ (compile nil '(lambda (sap)
+ (let ((x (setf (sb-vm::sap-ref-single sap 0) 1d0)))
+ (1+ x)))))
+
+;;; bug #399
+(with-test (:name :string-union-types)
+ (compile nil '(lambda (x)
+ (declare (type (or (simple-array character (6))
+ (simple-array character (5))) x))
+ (aref x 0))))
+
+;;; MISC.623: missing functions for constant-folding
+(assert (eql 0
+ (funcall
+ (compile
+ nil
+ '(lambda ()
+ (declare (optimize (space 2) (speed 0) (debug 2)
+ (compilation-speed 3) (safety 0)))
+ (loop for lv3 below 1
+ count (minusp
+ (loop for lv2 below 2
+ count (logbitp 0
+ (bit #*1001101001001
+ (min 12 (max 0 lv3))))))))))))
+
+;;; MISC.624: erronous AVER in x86's %LOGBITP VOPs
+(assert (eql 0
+ (funcall
+ (compile
+ nil
+ '(lambda (a)
+ (declare (type (integer 21 28) a))
+ (declare (optimize (compilation-speed 1) (safety 2)
+ (speed 0) (debug 0) (space 1)))
+ (let* ((v7 (flet ((%f3 (f3-1 f3-2)
+ (loop for lv2 below 1
+ count
+ (logbitp 29
+ (sbit #*10101111
+ (min 7 (max 0 (eval '0))))))))
+ (%f3 0 a))))
+ 0)))
+ 22)))
+
+;;; MISC.626: bandaged AVER was still wrong
+(assert (eql -829253
+ (funcall
+ (compile
+ nil
+ '(lambda (a)
+ (declare (type (integer -902970 2) a))
+ (declare (optimize (space 2) (debug 0) (compilation-speed 1)
+ (speed 0) (safety 3)))
+ (prog2 (if (logbitp 30 a) 0 (block b3 0)) a)))
+ -829253)))
+
+;; MISC.628: constant-folding %LOGBITP was buggy
+(assert (eql t
+ (funcall
+ (compile
+ nil
+ '(lambda ()
+ (declare (optimize (safety 3) (space 3) (compilation-speed 3)
+ (speed 0) (debug 1)))
+ (not (not (logbitp 0 (floor 2147483651 (min -23 0))))))))))
+
+;; mistyping found by random-tester
+(assert (zerop
+ (funcall
+ (compile
+ nil
+ '(lambda ()
+ (declare (optimize (speed 1) (debug 0)
+ (space 2) (safety 0) (compilation-speed 0)))
+ (unwind-protect 0
+ (* (/ (multiple-value-prog1 -29457482 -5602513511) 1))))))))
+
+;; aggressive constant folding (bug #400)
+(assert
+ (eq t (funcall (compile nil '(lambda () (or t (the integer (/ 1 0))))))))