(assert (not (eval `(locally (declare (optimize (safety 3)))
(ignore-errors (progn ,form t)))))))
+;;; feature: we shall complain if functions which are only useful for
+;;; their result are called and their result ignored.
+(loop for (form expected-des) in
+ '(((progn (nreverse (list 1 2)) t)
+ "The return value of NREVERSE should not be discarded.")
+ ((progn (nreconc (list 1 2) (list 3 4)) t)
+ "The return value of NRECONC should not be discarded.")
+ ((locally
+ (declare (inline sort))
+ (sort (list 1 2) #'<) t)
+ ;; FIXME: it would be nice if this warned on non-inlined sort
+ ;; but the current simple boolean function attribute
+ ;; can't express the condition that would be required.
+ "The return value of STABLE-SORT-LIST should not be discarded.")
+ ((progn (sort (vector 1 2) #'<) t)
+ ;; Apparently, SBCL (but not CL) guarantees in-place vector
+ ;; sort, so no warning.
+ nil)
+ ((progn (delete 2 (list 1 2)) t)
+ "The return value of DELETE should not be discarded.")
+ ((progn (delete-if #'evenp (list 1 2)) t)
+ ("The return value of DELETE-IF should not be discarded."))
+ ((progn (delete-if #'evenp (vector 1 2)) t)
+ ("The return value of DELETE-IF should not be discarded."))
+ ((progn (delete-if-not #'evenp (list 1 2)) t)
+ "The return value of DELETE-IF-NOT should not be discarded.")
+ ((progn (delete-duplicates (list 1 2)) t)
+ "The return value of DELETE-DUPLICATES should not be discarded.")
+ ((progn (merge 'list (list 1 3) (list 2 4) #'<) t)
+ "The return value of MERGE should not be discarded.")
+ ((progn (nreconc (list 1 3) (list 2 4)) t)
+ "The return value of NRECONC should not be discarded.")
+ ((progn (nunion (list 1 3) (list 2 4)) t)
+ "The return value of NUNION should not be discarded.")
+ ((progn (nintersection (list 1 3) (list 2 4)) t)
+ "The return value of NINTERSECTION should not be discarded.")
+ ((progn (nset-difference (list 1 3) (list 2 4)) t)
+ "The return value of NSET-DIFFERENCE should not be discarded.")
+ ((progn (nset-exclusive-or (list 1 3) (list 2 4)) t)
+ "The return value of NSET-EXCLUSIVE-OR should not be discarded."))
+ for expected = (if (listp expected-des)
+ expected-des
+ (list expected-des))
+ do
+ (multiple-value-bind (fun warnings-p failure-p)
+ (handler-bind ((style-warning (lambda (c)
+ (if expected
+ (let ((expect-one (pop expected)))
+ (assert (search expect-one
+ (with-standard-io-syntax
+ (let ((*print-right-margin* nil))
+ (princ-to-string c))))
+ ()
+ "~S should have warned ~S, but instead warned: ~A"
+ form expect-one c))
+ (error "~S shouldn't give a(nother) warning, but did: ~A" form c)))))
+ (compile nil `(lambda () ,form)))
+ (declare (ignore warnings-p))
+ (assert (functionp fun))
+ (assert (null expected)
+ ()
+ "~S should have warned ~S, but didn't."
+ form expected)
+ (assert (not failure-p))))
+
;;; a bug in the MAP deftransform caused non-VECTOR array specifiers
;;; to cause errors in the compiler. Fixed by CSR in 0.7.8.10
(assert (list (compile nil '(lambda (x) (map 'simple-array 'identity x)))))
(error "bad RANDOM event"))))
;;; 0.8.17.28-sma.1 lost derived type information.
-(handler-bind ((sb-ext:compiler-note #'error))
- (compile nil
- '(lambda (x y v)
- (declare (optimize (speed 3) (safety 0)))
- (declare (type (integer 0 80) x)
- (type (integer 0 11) y)
- (type (simple-array (unsigned-byte 32) (*)) v))
- (setf (aref v 0) (* (* x #.(floor (ash 1 32) (* 11 80))) y))
- nil)))
+(with-test (:name "0.8.17.28-sma.1" :fails-on :sparc)
+ (handler-bind ((sb-ext:compiler-note (lambda (c) (error "~A" c))))
+ (compile nil
+ '(lambda (x y v)
+ (declare (optimize (speed 3) (safety 0)))
+ (declare (type (integer 0 80) x)
+ (type (integer 0 11) y)
+ (type (simple-array (unsigned-byte 32) (*)) v))
+ (setf (aref v 0) (* (* x #.(floor (ash 1 32) (* 11 80))) y))
+ nil))))
;;; Bug reported by Robert J. Macomber: instrumenting of more-entry
;;; prevented open coding of %LISTIFY-REST-ARGS.
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))))))))
+
+(with-test (:name (:compiler :constraint-propagation :var-eql-to-non-var-1))
+ (assert
+ (handler-case
+ (compile nil '(lambda (x y)
+ (when (eql x (length y))
+ (locally
+ (declare (optimize (speed 3)))
+ (1+ x)))))
+ (compiler-note () (error "The code is not optimized.")))))
+
+(with-test (:name (:compiler :constraint-propagation :var-eql-to-non-var-2))
+ (assert
+ (handler-case
+ (compile nil '(lambda (x y)
+ (when (eql (length y) x)
+ (locally
+ (declare (optimize (speed 3)))
+ (1+ x)))))
+ (compiler-note () (error "The code is not optimized.")))))