1 ;;;; various compiler tests without side effects
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (cl:in-package
:cl-user
)
16 (load "compiler-test-util.lisp")
18 ;; The tests in this file assume that EVAL will use the compiler
19 (when (eq sb-ext
:*evaluator-mode
* :interpret
)
20 (invoke-restart 'run-tests
::skip-file
))
22 ;;; Exercise a compiler bug (by crashing the compiler).
24 ;;; This test code is from Douglas Crosher's simplified TICKLE-BUG
25 ;;; (2000-09-06 on cmucl-imp).
27 ;;; The bug was fixed by Douglas Crosher's patch, massaged for SBCL by
28 ;;; Martin Atzmueller (2000-09-13 on sbcl-devel).
48 ;;; Exercise a compiler bug (by crashing the compiler).
50 ;;; Tim Moore gave a patch for this bug in CMU CL 2000-05-24 on
51 ;;; cmucl-imp, and Martin Atzmueller applied it to SBCL.
55 (block used-by-some-y?
59 (return-from used-by-some-y? t
)))))
60 (declare (inline frob
))
66 ;;; bug 112, reported by Martin Atzmueller 2001-06-25 (originally
67 ;;; from Bruno Haible in CMU CL bugs collection), fixed by
68 ;;; Alexey Dejneka 2002-01-27
69 (assert (= 1 ; (used to give 0 under bug 112)
74 (declare (special x
)) y
)))))
75 (assert (= 1 ; (used to give 1 even under bug 112, still works after fix)
80 (declare (special x
)) y
)))))
82 ;;; another LET-related bug fixed by Alexey Dejneka at the same
84 (multiple-value-bind (fun warnings-p failure-p
)
85 ;; should complain about duplicate variable names in LET binding
91 (declare (ignore warnings-p
))
92 (assert (functionp fun
))
95 ;;; bug 169 (reported by Alexey Dejneka 2002-05-12, fixed by David
96 ;;; Lichteblau 2002-05-21)
98 (multiple-value-bind (fun warnings-p failure-p
)
100 ;; Compiling this code should cause a STYLE-WARNING
101 ;; about *X* looking like a special variable but not
105 (funcall (symbol-function 'x-getter
))
107 (assert (functionp fun
))
109 (assert (not failure-p
)))
110 (multiple-value-bind (fun warnings-p failure-p
)
112 ;; Compiling this code should not cause a warning
113 ;; (because the DECLARE turns *X* into a special
114 ;; variable as its name suggests it should be).
117 (declare (special *x
*))
118 (funcall (symbol-function 'x-getter
))
120 (assert (functionp fun
))
121 (assert (not warnings-p
))
122 (assert (not failure-p
))))
124 ;;; a bug in 0.7.4.11
125 (dolist (i '(a b
1 2 "x" "y"))
126 ;; In sbcl-0.7.4.11, the compiler tried to source-transform the
127 ;; TYPEP here but got confused and died, doing
128 ;; (ASSOC '(AND INTEGERP (SATISFIES PLUSP)))
129 ;; *BACKEND-TYPE-PREDICATES*
131 ;; and blowing up because TYPE= tried to call PLUSP on the
132 ;; characters of the MEMBER-TYPE representing STANDARD-CHAR.
133 (when (typep i
'(and integer
(satisfies oddp
)))
136 (when (typep i
'(and integer
(satisfies oddp
)))
139 ;;; bug 156 (reported by APD sbcl-devel 2002-04-12, fixed by CSR patch
140 ;;; sbcl-devel 2002-07-02): FUNCTION-LAMBDA-EXPRESSION of
141 ;;; interactively-compiled functions was broken by sleaziness and
142 ;;; confusion in the assault on 0.7.0, so this expression used to
143 ;;; signal TYPE-ERROR when it found NIL instead of a DEBUG-SOURCE.
144 (eval '(function-lambda-expression #'(lambda (x) x
)))
146 ;;; bug caught and fixed by Raymond Toy cmucl-imp 2002-07-10: &REST
147 ;;; variable is not optional.
148 (assert (null (ignore-errors (eval '(funcall (lambda (&rest
) 12))))))
150 ;;; on the PPC, we got the magic numbers in undefined_tramp wrong for
151 ;;; a while; fixed by CSR 2002-07-18
152 (with-test (:name
:undefined-function-error
)
153 (multiple-value-bind (value error
)
154 (ignore-errors (some-undefined-function))
155 (assert (null value
))
156 (assert (eq (cell-error-name error
) 'some-undefined-function
))))
158 (with-test (:name
:unbound-variable-error
)
159 (let ((foo (gensym)))
160 (assert (eq (handler-case (symbol-value foo
)
161 (unbound-variable (c) (cell-error-name c
)))
163 ;; on x86-64 the code for a literal symbol uses a slightly different path,
165 (assert (eq (handler-case xyzzy
*%state
166 (unbound-variable (c) (cell-error-name c
)))
168 ;; And finally, also on x86-64, there was massive confusion about
169 ;; variable names that looked like names of thread slots.
170 (assert (eq (handler-case *state
*
171 (unbound-variable (c) (cell-error-name c
)))
174 ;;; Non-symbols shouldn't be allowed as VARs in lambda lists. (Where VAR
175 ;;; is a variable name, as in section 3.4.1 of the ANSI spec.)
176 (assert (null (ignore-errors (eval '(lambda ("foo") 12)))))
177 (assert (ignore-errors (eval '(lambda (foo) 12))))
178 (assert (null (ignore-errors (eval '(lambda (&optional
12) "foo")))))
179 (assert (ignore-errors (eval '(lambda (&optional twelve
) "foo"))))
180 (assert (null (ignore-errors (eval '(lambda (&optional
(12 12)) "foo")))))
181 (assert (ignore-errors (eval '(lambda (&optional
(twelve 12)) "foo"))))
182 (assert (null (ignore-errors (eval '(lambda (&key
#\c
) "foo")))))
183 (assert (ignore-errors (eval '(lambda (&key c
) "foo"))))
184 (assert (null (ignore-errors (eval '(lambda (&key
(#\c
#\c
)) "foo")))))
185 (assert (ignore-errors (eval '(lambda (&key
(c #\c
)) "foo"))))
186 (assert (null (ignore-errors (eval '(lambda (&key
((#\c
#\c
) #\c
)) "foo")))))
187 (assert (ignore-errors (eval '(lambda (&key
((:c cbyanyothername
) #\c
)) "foo"))))
189 ;;; As reported and fixed by Antonio Martinez-Shotton sbcl-devel
190 ;;; 2002-09-12, this failed in sbcl-0.7.7.23. (with failed AVER
191 ;;; "(LEAF-HAS-SOURCE-NAME-P LEAF)")
192 (assert (= (funcall (eval `(lambda (x) (funcall ,(lambda (y) (+ y
3)) x
))) 14)
195 ;;; bug 181: bad type specifier dropped compiler into debugger
196 (assert (list (compile nil
'(lambda (x)
197 (declare (type (0) x
))
200 (let ((f (compile nil
'(lambda (x)
201 (make-array 1 :element-type
'(0))))))
202 (assert (null (ignore-errors (funcall f
)))))
204 ;;; the following functions must not be flushable
205 (dolist (form '((make-sequence 'fixnum
10)
206 (concatenate 'fixnum nil
)
207 (map 'fixnum
#'identity nil
)
208 (merge 'fixnum nil nil
#'<)))
209 (assert (not (eval `(locally (declare (optimize (safety 0)))
210 (ignore-errors (progn ,form t
)))))))
212 (dolist (form '((values-list (car (list '(1 .
2))))
214 (atan #c
(1 1) (car (list #c
(2 2))))
215 (nthcdr (car (list (floor (cos 3)))) '(1 2 3 4 5))
216 (nthcdr (car (list 5)) '(1 2 .
3))))
217 (assert (not (eval `(locally (declare (optimize (safety 3)))
218 (ignore-errors (progn ,form t
)))))))
220 ;;; feature: we shall complain if functions which are only useful for
221 ;;; their result are called and their result ignored.
222 (loop for
(form expected-des
) in
223 '(((progn (nreverse (list 1 2)) t
)
224 "The return value of NREVERSE should not be discarded.")
225 ((progn (nreconc (list 1 2) (list 3 4)) t
)
226 "The return value of NRECONC should not be discarded.")
228 (declare (inline sort
))
229 (sort (list 1 2) #'<) t
)
230 ;; FIXME: it would be nice if this warned on non-inlined sort
231 ;; but the current simple boolean function attribute
232 ;; can't express the condition that would be required.
233 "The return value of STABLE-SORT-LIST should not be discarded.")
234 ((progn (sort (vector 1 2) #'<) t
)
235 ;; Apparently, SBCL (but not CL) guarantees in-place vector
236 ;; sort, so no warning.
238 ((progn (delete 2 (list 1 2)) t
)
239 "The return value of DELETE should not be discarded.")
240 ((progn (delete-if #'evenp
(list 1 2)) t
)
241 ("The return value of DELETE-IF should not be discarded."))
242 ((progn (delete-if #'evenp
(vector 1 2)) t
)
243 ("The return value of DELETE-IF should not be discarded."))
244 ((progn (delete-if-not #'evenp
(list 1 2)) t
)
245 "The return value of DELETE-IF-NOT should not be discarded.")
246 ((progn (delete-duplicates (list 1 2)) t
)
247 "The return value of DELETE-DUPLICATES should not be discarded.")
248 ((progn (merge 'list
(list 1 3) (list 2 4) #'<) t
)
249 "The return value of MERGE should not be discarded.")
250 ((progn (nreconc (list 1 3) (list 2 4)) t
)
251 "The return value of NRECONC should not be discarded.")
252 ((progn (nunion (list 1 3) (list 2 4)) t
)
253 "The return value of NUNION should not be discarded.")
254 ((progn (nintersection (list 1 3) (list 2 4)) t
)
255 "The return value of NINTERSECTION should not be discarded.")
256 ((progn (nset-difference (list 1 3) (list 2 4)) t
)
257 "The return value of NSET-DIFFERENCE should not be discarded.")
258 ((progn (nset-exclusive-or (list 1 3) (list 2 4)) t
)
259 "The return value of NSET-EXCLUSIVE-OR should not be discarded."))
260 for expected
= (if (listp expected-des
)
264 (multiple-value-bind (fun warnings-p failure-p
)
265 (handler-bind ((style-warning (lambda (c)
267 (let ((expect-one (pop expected
)))
268 (assert (search expect-one
269 (with-standard-io-syntax
270 (let ((*print-right-margin
* nil
))
271 (princ-to-string c
))))
273 "~S should have warned ~S, but instead warned: ~A"
275 (error "~S shouldn't give a(nother) warning, but did: ~A" form c
)))))
276 (compile nil
`(lambda () ,form
)))
277 (declare (ignore warnings-p
))
278 (assert (functionp fun
))
279 (assert (null expected
)
281 "~S should have warned ~S, but didn't."
283 (assert (not failure-p
))))
285 ;;; a bug in the MAP deftransform caused non-VECTOR array specifiers
286 ;;; to cause errors in the compiler. Fixed by CSR in 0.7.8.10
287 (assert (list (compile nil
'(lambda (x) (map 'simple-array
'identity x
)))))
289 ;;; bug 129: insufficient syntax checking in MACROLET
290 (multiple-value-bind (result error
)
291 (ignore-errors (eval '(macrolet ((foo x
`',x
)) (foo 1 2 3))))
292 (assert (null result
))
293 (assert (typep error
'error
)))
295 ;;; bug 124: environment of MACROLET-introduced macro expanders
297 (macrolet ((mext (x) `(cons :mext
,x
)))
298 (macrolet ((mint (y) `'(:mint
,(mext y
))))
301 '((:MEXT
1 2) (:MINT
(:MEXT
1 2)))))
303 ;;; bug 48c: SYMBOL-MACROLET should signal PROGRAM-ERROR if introduced
304 ;;; symbol is declared to be SPECIAL
305 (multiple-value-bind (result error
)
306 (ignore-errors (funcall (lambda ()
307 (symbol-macrolet ((s '(1 2)))
308 (declare (special s
))
310 (assert (null result
))
311 (assert (typep error
'program-error
)))
313 ;;; ECASE should treat a bare T as a literal key
314 (multiple-value-bind (result error
)
315 (ignore-errors (ecase 1 (t 0)))
316 (assert (null result
))
317 (assert (typep error
'type-error
)))
319 (multiple-value-bind (result error
)
320 (ignore-errors (ecase 1 (t 0) (1 2)))
321 (assert (eql result
2))
322 (assert (null error
)))
324 ;;; FTYPE should accept any functional type specifier
325 (compile nil
'(lambda (x) (declare (ftype function f
)) (f x
)))
327 ;;; FUNCALL of special operators and macros should signal an
328 ;;; UNDEFINED-FUNCTION error
329 (multiple-value-bind (result error
)
330 (ignore-errors (funcall 'quote
1))
331 (assert (null result
))
332 (assert (typep error
'undefined-function
))
333 (assert (eq (cell-error-name error
) 'quote
)))
334 (multiple-value-bind (result error
)
335 (ignore-errors (funcall 'and
1))
336 (assert (null result
))
337 (assert (typep error
'undefined-function
))
338 (assert (eq (cell-error-name error
) 'and
)))
340 ;;; PSETQ should behave when given complex symbol-macro arguments
341 (multiple-value-bind (sequence index
)
342 (symbol-macrolet ((x (aref a
(incf i
)))
343 (y (aref a
(incf i
))))
344 (let ((a (copy-seq #(0 1 2 3 4 5 6 7 8 9)))
346 (psetq x
(aref a
(incf i
))
349 (assert (equalp sequence
#(0 2 2 4 4 5 6 7 8 9)))
350 (assert (= index
4)))
352 (multiple-value-bind (result error
)
354 (let ((x (list 1 2)))
357 (assert (null result
))
358 (assert (typep error
'program-error
)))
360 ;;; COPY-SEQ should work on known-complex vectors:
362 (let ((v (make-array 0 :fill-pointer
0)))
363 (vector-push-extend 1 v
)
366 ;;; to support INLINE functions inside MACROLET, it is necessary for
367 ;;; FUNCTION-LAMBDA-EXPRESSION to return a proper lambda expression in
368 ;;; certain circumstances, one of which is when compile is called from
371 (function-lambda-expression
372 (compile nil
'(lambda (x) (block nil
(print x
)))))
373 '(lambda (x) (block nil
(print x
)))))
375 ;;; bug 62: too cautious type inference in a loop
380 (declare (optimize speed
(safety 0)))
382 (array (loop (print (car a
)))))))))
384 ;;; Bug reported by Robert E. Brown sbcl-devel 2003-02-02: compiler
387 '(lambda (key tree collect-path-p
)
388 (let ((lessp (key-lessp tree
))
389 (equalp (key-equalp tree
)))
390 (declare (type (function (t t
) boolean
) lessp equalp
))
392 (loop for node
= (root-node tree
)
393 then
(if (funcall lessp key
(node-key node
))
397 do
(return (values nil nil nil
))
398 do
(when collect-path-p
400 (when (funcall equalp key
(node-key node
))
401 (return (values node path t
))))))))
403 ;;; CONSTANTLY should return a side-effect-free function (bug caught
404 ;;; by Paul Dietz' test suite)
406 (let ((fn (constantly (progn (incf i
) 1))))
408 (assert (= (funcall fn
) 1))
410 (assert (= (funcall fn
) 1))
413 ;;; Bug 240 reported by tonyms on #lisp IRC 2003-02-25 (modified version)
414 (loop for
(fun warns-p
) in
415 '(((lambda (&optional
*x
*) *x
*) t
)
416 ((lambda (&optional
*x
* &rest y
) (values *x
* y
)) t
)
417 ((lambda (&optional
*print-length
*) (values *print-length
*)) nil
)
418 ((lambda (&optional
*print-length
* &rest y
) (values *print-length
* y
)) nil
)
419 ((lambda (&optional
*x
*) (declare (special *x
*)) (values *x
*)) nil
)
420 ((lambda (&optional
*x
* &rest y
) (declare (special *x
*)) (values *x
* y
)) nil
))
421 for real-warns-p
= (nth-value 1 (compile nil fun
))
422 do
(assert (eq warns-p real-warns-p
)))
424 ;;; Bug reported by Gilbert Baumann on #lisp IRC 2003-03-26
425 (assert (equal (funcall (eval '(lambda (x &optional
(y (pop x
))) (list x y
)))
429 ;;; Bug reported by Paul Dietz on cmucl-imp and fixed by Gerd
430 ;;; Moellmann: CONVERT-MORE-CALL failed on the following call
431 (assert (eq (eval '((lambda (&key
) 'u
) :allow-other-keys nil
)) 'u
))
433 (assert-error (multiple-value-bind (a b c
)
434 (eval '(truncate 3 4))
435 (declare (integer c
))
439 (assert (equal (multiple-value-list (the (values &rest integer
)
443 ;;; Bug relating to confused representation for the wild function
445 (assert (null (funcall (eval '(lambda () (multiple-value-list (values)))))))
447 ;;; &ENVIRONMENT parameter should be bound first (from Paul Dietz'
449 (assert (eql (macrolet ((foo () 1))
450 (macrolet ((%f
(&optional
(x (macroexpand '(foo) env
)) &environment env
)
455 ;;; MACROLET should check for duplicated names
456 (dolist (ll '((x (z x
))
457 (x y
&optional z x w
)
461 (x &optional
(y nil x
))
462 (x &optional
(y nil y
))
465 (&key
(y nil z
) (z nil w
))
466 (&whole x
&optional x
)
467 (&environment x
&whole x
)))
472 (macrolet ((foo ,ll nil
)
473 (bar (&environment env
)
474 `',(macro-function 'foo env
)))
477 (values nil t t
))))))
479 (assert (typep (eval `(the arithmetic-error
480 ',(make-condition 'arithmetic-error
)))
483 (assert (not (nth-value
484 2 (compile nil
'(lambda ()
485 (make-array nil
:initial-element
11))))))
487 (assert-error (funcall (eval #'open
) "assertoid.lisp"
488 :external-format
'#:nonsense
))
489 (assert-error (funcall (eval #'load
) "assertoid.lisp"
490 :external-format
'#:nonsense
))
492 (assert (= (the (values integer symbol
) (values 1 'foo
13)) 1))
494 (let ((f (compile nil
496 (declare (optimize (safety 3)))
497 (list (the fixnum
(the (real 0) (eval v
))))))))
498 (assert-error (funcall f
0.1) type-error
)
499 (assert-error (funcall f -
1) type-error
))
501 ;;; the implicit block does not enclose lambda list
502 (let ((forms '((defmacro #1=#:foo
(&optional
(x (return-from #1#))))
503 #+nil
(macrolet ((#2=#:foo
(&optional
(x (return-from #2#))))))
504 (define-compiler-macro #3=#:foo
(&optional
(x (return-from #3#))))
505 (deftype #4=#:foo
(&optional
(x (return-from #4#))))
506 (define-setf-expander #5=#:foo
(&optional
(x (return-from #5#))))
507 (defsetf #6=#:foo
(&optional
(x (return-from #6#))) ()))))
509 (assert (nth-value 2 (compile nil
`(lambda () ,form
))))))
511 (assert (nth-value 2 (compile nil
513 (svref (make-array '(8 9) :adjustable t
) 1)))))
515 ;;; CHAR= did not check types of its arguments (reported by Adam Warner)
516 (assert-error (funcall (compile nil
'(lambda (x y z
) (char= x y z
)))
519 (assert-error (funcall (compile nil
521 (declare (optimize (speed 3) (safety 3)))
526 ;;; Compiler lost return type of MAPCAR and friends
527 (dolist (fun '(mapcar mapc maplist mapl
))
528 (assert (nth-value 2 (compile nil
530 (1+ (,fun
#'print x
)))))))
532 (assert (nth-value 2 (compile nil
534 (declare (notinline mapcar
))
535 (1+ (mapcar #'print
'(1 2 3)))))))
537 ;;; bug found by Paul Dietz: (SETF AREF) for bit vectors with constant
538 ;;; index was effectless
539 (let ((f (compile nil
'(lambda (a v
)
540 (declare (type simple-bit-vector a
) (type bit v
))
541 (declare (optimize (speed 3) (safety 0)))
544 (let ((y (make-array 2 :element-type
'bit
:initial-element
0)))
545 (assert (equal y
#*00))
547 (assert (equal y
#*10))))
549 ;;; use of declared array types
550 (handler-bind ((sb-ext:compiler-note
#'error
))
551 (compile nil
'(lambda (x)
552 (declare (type (simple-array (simple-string 3) (5)) x
)
554 (aref (aref x
0) 0))))
556 (handler-bind ((sb-ext:compiler-note
#'error
))
557 (compile nil
'(lambda (x)
558 (declare (type (simple-array (simple-array bit
(10)) (10)) x
)
560 (1+ (aref (aref x
0) 0)))))
563 (let ((f (compile nil
'(lambda (x) (typep x
'(not (member 0d0
)))))))
564 (assert (funcall f
1d0
)))
566 (compile nil
'(lambda (x)
567 (declare (double-float x
))
571 ;;; bogus optimization of BIT-NOT
572 (multiple-value-bind (result x
)
573 (eval '(let ((x (eval #*1001)))
574 (declare (optimize (speed 2) (space 3))
575 (type (bit-vector) x
))
576 (values (bit-not x nil
) x
)))
577 (assert (equal x
#*1001))
578 (assert (equal result
#*0110)))
580 ;;; the VECTOR type in CONCATENATE/MERGE/MAKE-SEQUENCE means (VECTOR T).
581 (handler-bind ((sb-ext:compiler-note
#'error
))
582 (assert (equalp (funcall
586 (let ((x (make-sequence 'vector
10 :initial-element
'a
)))
589 #(a a a a b a a a a a
))))
591 ;;; this is not a check for a bug, but rather a test of compiler
593 (dolist (type '((integer 0 *) ; upper bound
596 (real * (-10)) ; lower bound
601 (declare (optimize (speed 3) (compilation-speed 0)))
602 (loop for i from
1 to
(the (integer -
17 10) n
) by
2
603 collect
(when (> (random 10) 5)
604 (the ,type
(- i
11)))))))))
608 ;;; We suppose that INTEGER arithmetic cannot be efficient, and the
609 ;;; compiler has an optimized VOP for +; so this code should cause an
611 (assert (eq (block nil
613 (compile nil
'(lambda (i)
614 (declare (optimize speed
))
615 (declare (type integer i
))
617 (sb-ext:compiler-note
(c) (return :good
))))
620 ;;; bug 277: IGNORE/IGNORABLE declarations should be acceptable for
622 (assert (not (nth-value 1 (compile nil
'(lambda (u v
)
623 (symbol-macrolet ((x u
)
629 ;;; bug reported by Paul Dietz: wrong optimizer for (EXPT ... 0)
630 (loop for
(x type
) in
633 (-14/3 (rational -
8 11))
642 (#c
(-3 4) (complex fixnum
))
643 (#c
(-3 4) (complex rational
))
644 (#c
(-3/7 4) (complex rational
))
645 (#c
(2s0 3s0
) (complex short-float
))
646 (#c
(2f0 3f0
) (complex single-float
))
647 (#c
(2d0 3d0
) (complex double-float
))
648 (#c
(2l0 3l0) (complex long-float
))
649 (#c
(2d0 3s0
) (complex float
))
650 (#c
(2 3f0
) (complex real
))
651 (#c
(2 3d0
) (complex real
))
652 (#c
(-3/7 4) (complex real
))
655 do
(dolist (zero '(0 0s0
0f0
0d0
0l0))
656 (dolist (real-zero (list zero
(- zero
)))
657 (let* ((src `(lambda (x) (expt (the ,type x
) ,real-zero
)))
658 (fun (compile nil src
))
659 (result (1+ (funcall (eval #'*) x real-zero
))))
660 (assert (eql result
(funcall fun x
)))))))
662 ;;; (SIGNED-BYTE 1) [ returned from the logxor derive-type optimizer ]
663 ;;; wasn't recognized as a good type specifier.
664 (let ((fun (lambda (x y
)
665 (declare (type (integer -
1 0) x y
) (optimize speed
))
667 (assert (= (funcall fun
0 0) 0))
668 (assert (= (funcall fun
0 -
1) -
1))
669 (assert (= (funcall fun -
1 -
1) 0)))
671 ;;; from PFD's torture test, triggering a bug in our effective address
676 (declare (type (integer 8 22337) b
))
679 (* (logandc1 (max -
29303 b
) 4) b
)
680 (abs (logorc1 (+ (logandc1 -
11 b
) 2607688420) -
31153924)))
681 (logeqv (max a
0) b
))))
683 ;;; Alpha floating point modes weren't being reset after an exception,
684 ;;; leading to an exception on the second compile, below.
685 (compile nil
'(lambda (x y
) (declare (type (double-float 0.0d0
) x y
)) (/ x y
)))
686 (handler-case (/ 1.0 0.0)
687 ;; provoke an exception
688 (arithmetic-error ()))
689 (compile nil
'(lambda (x y
) (declare (type (double-float 0.0d0
) x y
)) (/ x y
)))
691 ;;; bug reported by Paul Dietz: component last block does not have
695 (declare (notinline + logand
)
696 (optimize (speed 0)))
700 (RETURN-FROM B5 -
220)))
702 (+ 359749 35728422))))
705 (with-test (:name
:ansi-misc
.293a
)
710 (declare (optimize (speed 2) (space 3) (safety 1)
711 (debug 2) (compilation-speed 2)))
713 (multiple-value-prog1
718 (complex (cl::handler-bind nil -
254932942) 0))))))))
722 (with-test (:name
:ansi-misc
.293d
)
727 (declare (optimize (debug 3) (safety 0) (space 2)
728 (compilation-speed 2) (speed 2)))
730 (multiple-value-prog1
733 (return-from b4
(catch 'ct2
(progn (tagbody) 0)))))))))
736 (with-test (:name
:ansi-misc
.618)
741 (declare (optimize (space 0) (compilation-speed 2) (debug 0)
742 (speed 3) (safety 0)))
745 (multiple-value-prog1 0
746 (apply (constantly 0)
748 (catch 'ct2
(return-from b1
0))
753 ;;; bug 294 reported by Paul Dietz: miscompilation of REM and MOD
754 (assert (= (funcall (compile nil
`(lambda (b)
755 (declare (optimize (speed 3))
756 (type (integer 2 152044363) b
))
757 (rem b
(min -
16 0))))
761 (assert (= (funcall (compile nil
`(lambda (c)
762 (declare (optimize (speed 3))
763 (type (integer 23062188 149459656) c
))
768 ;;; bug reported by Paul Dietz: block splitting inside FLUSH-DEAD-CODE
772 (LOGEQV (REM C -
6758)
773 (REM B
(MAX 44 (RETURN-FROM B6 A
)))))))
775 (compile nil
'(lambda ()
777 (flet ((foo (x y
) (if (> x y
) (print x
) (print y
))))
780 (foo (return 14) 2)))))
782 ;;; bug in Alpha backend: not enough sanity checking of arguments to
784 (assert (= (funcall (compile nil
791 ;;; bug found by WHN and pfdietz: compiler failure while referencing
792 ;;; an entry point inside a deleted lambda
793 (compile nil
'(lambda ()
798 (flet ((truly (fn bbd
)
802 (multiple-value-prog1
819 (wum #'bbfn
"hc3" (list)))
821 (compile nil
'(lambda () (flet ((%f
() (unwind-protect nil
))) nil
)))
823 ;;; the strength reduction of constant multiplication used (before
824 ;;; sbcl-0.8.4.x) to lie to the compiler. This meant that, under
825 ;;; certain circumstances, the compiler would derive that a perfectly
826 ;;; reasonable multiplication never returned, causing chaos. Fixed by
827 ;;; explicitly doing modular arithmetic, and relying on the backends
832 (declare (type (integer 178956970 178956970) x
)
838 ;;; bug in modular arithmetic and type specifiers
839 (assert (= (funcall (compile nil
'(lambda (x) (logand x x
0)))
843 ;;; MISC.99 from Paul Dietz' random tester: FAST-ASH-MOD32-C VOP
844 ;;; produced wrong result for shift >=32 on X86
845 (assert (= 0 (funcall
848 (declare (type (integer 4303063 101130078) a
))
849 (mask-field (byte 18 2) (ash a
77))))
851 ;;; rewrite the test case to get the unsigned-byte 32/64
852 ;;; implementation even after implementing some modular arithmetic
853 ;;; with signed-byte 30:
854 (assert (= 0 (funcall
857 (declare (type (integer 4303063 101130078) a
))
858 (mask-field (byte 30 2) (ash a
77))))
860 (assert (= 0 (funcall
863 (declare (type (integer 4303063 101130078) a
))
864 (mask-field (byte 64 2) (ash a
77))))
866 ;;; and a similar test case for the signed masking extension (not the
867 ;;; final interface, so change the call when necessary):
868 (assert (= 0 (funcall
871 (declare (type (integer 4303063 101130078) a
))
872 (sb-c::mask-signed-field
30 (ash a
77))))
874 (assert (= 0 (funcall
877 (declare (type (integer 4303063 101130078) a
))
878 (sb-c::mask-signed-field
61 (ash a
77))))
881 ;;; MISC.101 and MISC.103: FLUSH-DEST did not mark the USE's block for
882 ;;; type check regeneration
883 (assert (eql (funcall
884 (compile nil
'(lambda (a c
)
885 (declare (type (integer 185501219873 303014665162) a
))
886 (declare (type (integer -
160758 255724) c
))
887 (declare (optimize (speed 3)))
889 (- -
554046873252388011622614991634432
891 (unwind-protect 2791485))))
892 (max (ignore-errors a
)
893 (let ((v6 (- v8
(restart-case 980))))
897 (assert (eql (funcall
898 (compile nil
'(lambda (a b
)
906 (load-time-value -
6876935))))
907 (if (logbitp 1 a
) b
(setq a -
1522022182249))))))))
908 -
1802767029877 -
12374959963)
911 ;;; various MISC.*, related to NODEs/LVARs with derived type NIL
912 (assert (eql (funcall (compile nil
'(lambda (c)
913 (declare (type (integer -
3924 1001809828) c
))
914 (declare (optimize (speed 3)))
915 (min 47 (if (ldb-test (byte 2 14) c
)
917 (ignore-errors -
732893970)))))
920 (assert (eql (funcall
921 (compile nil
'(lambda (b)
922 (declare (type (integer -
1598566306 2941) b
))
923 (declare (optimize (speed 3)))
924 (max -
148949 (ignore-errors b
))))
927 (assert (eql (funcall
928 (compile nil
'(lambda (b c
)
929 (declare (type (integer -
4 -
3) c
))
931 (flet ((%f1
(f1-1 f1-2 f1-3
)
932 (if (logbitp 0 (return-from b7
933 (- -
815145138 f1-2
)))
934 (return-from b7 -
2611670)
936 (let ((v2 (%f1 -
2464 (%f1 -
1146 c c
) -
2)))
940 (assert (eql (funcall
943 (declare (type (integer -
29742055786 23602182204) b
))
944 (declare (type (integer -
7409 -
2075) c
))
945 (declare (optimize (speed 3)))
949 (ignore-errors (return-from b6
950 (if (= c
8) b
82674))))))
954 (assert (equal (multiple-value-list
956 (compile nil
'(lambda (a)
957 (declare (type (integer -
944 -
472) a
))
958 (declare (optimize (speed 3)))
962 (if (= 55957 a
) -
117 (ignore-errors
963 (return-from b3 a
))))))))
968 (assert (zerop (funcall
971 (declare (type (integer 79828 2625480458) a
))
972 (declare (type (integer -
4363283 8171697) b
))
973 (declare (type (integer -
301 0) c
))
974 (if (equal 6392154 (logxor a b
))
978 (logior (logandc2 c v5
)
979 (common-lisp:handler-case
980 (ash a
(min 36 22477)))))))))
983 ;;; MISC.152, 153: deleted code and iteration var type inference
984 (assert (eql (funcall
988 (let ((v1 (let ((v8 (unwind-protect 9365)))
992 (labels ((%f11
(f11-1) f11-1
))
996 (labels ((%f6
(f6-1 f6-2 f6-3
) v1
))
997 (dpb (unwind-protect a
)
999 (labels ((%f4
() 27322826))
1000 (%f6 -
2 -
108626545 (%f4
))))))))))))
1004 (assert (eql (funcall
1009 ((-96879 -
1035 -
57680 -
106404 -
94516 -
125088)
1010 (unwind-protect 90309179))
1011 ((-20811 -
86901 -
9368 -
98520 -
71594)
1012 (let ((v9 (unwind-protect 136707)))
1015 (let ((v4 (return-from b3 v9
)))
1016 (- (ignore-errors (return-from b3 v4
))))))))
1024 (assert (eql (funcall
1035 &optional
(f17-4 185155520) (f17-5 c
)
1038 (%f17 -
1046 a
1115306 (%f17 b -
146330 422) -
337817)))
1039 (f15-5 a
) (f15-6 -
40))
1040 (return-from b3 -
16)))
1041 (multiple-value-call #'%f15
(values -
519354 a
121 c -
1905))))))
1046 (assert (eql (funcall
1050 (declare (notinline list apply
))
1051 (declare (optimize (safety 3)))
1052 (declare (optimize (speed 0)))
1053 (declare (optimize (debug 0)))
1054 (labels ((%f12
(f12-1 f12-2
)
1055 (labels ((%f2
(f2-1 f2-2
)
1062 (return-from %f12 b
)))
1065 (%f18
(%f18
150 -
64 f12-1
)
1072 &optional
(f7-3 (%f6
)))
1075 (%f2 b -
36582571))))
1076 (apply #'%f12
(list 774 -
4413)))))
1081 (assert (eql (funcall
1085 (declare (notinline values
))
1086 (declare (optimize (safety 3)))
1087 (declare (optimize (speed 0)))
1088 (declare (optimize (debug 0)))
1091 &optional
(f11-3 c
) (f11-4 7947114)
1093 (flet ((%f3
(f3-1 &optional
(f3-2 b
) (f3-3 5529))
1095 (multiple-value-call #'%f3
1096 (values (%f3 -
30637724 b
) c
)))))
1098 (if (and nil
(%f11 a a
))
1099 (if (%f11 a
421778 4030 1)
1105 (%f11 c a c -
4 214720)
1117 ;;; MISC.177, 182: IR2 copy propagation missed a hidden write to a
1118 ;;; local lambda argument
1124 (declare (type (integer 804561 7640697) a
))
1125 (declare (type (integer -
1 10441401) b
))
1126 (declare (type (integer -
864634669 55189745) c
))
1127 (declare (ignorable a b c
))
1128 (declare (optimize (speed 3)))
1129 (declare (optimize (safety 1)))
1130 (declare (optimize (debug 1)))
1133 (labels ((%f4
() (round 200048 (max 99 c
))))
1136 (labels ((%f3
(f3-1) -
162967612))
1137 (%f3
(let* ((v8 (%f4
)))
1138 (setq f11-1
(%f4
)))))))))
1139 (%f11 -
120429363 (%f11
62362 b
)))))
1140 6714367 9645616 -
637681868)
1143 ;;; Bug reported by Paul F. Dietz caused by derive type loss in VALUE
1145 (assert (equal (multiple-value-list
1147 (compile nil
'(lambda ()
1148 (declare (optimize (speed 1) (space 0) (safety 3) (debug 3) (compilation-speed 1)))
1151 (flet ((%f16
() 0)) (%f16
))))))))
1160 (declare (type (integer 867934833 3293695878) a
))
1161 (declare (type (integer -
82111 1776797) b
))
1162 (declare (type (integer -
1432413516 54121964) c
))
1163 (declare (optimize (speed 3)))
1164 (declare (optimize (safety 1)))
1165 (declare (optimize (debug 1)))
1167 (flet ((%f15
(f15-1 &optional
(f15-2 c
))
1168 (labels ((%f1
(f1-1 f1-2
) 0))
1171 (multiple-value-call #'%f15
1172 (values (%f15 c
0) (%f15
0)))))
1174 (flet ((%f8
(f8-1 &optional
(f8-2 (%f4
)) (f8-3 0))
1178 3040851270 1664281 -
1340106197)))
1186 (declare (notinline <=))
1187 (declare (optimize (speed 2) (space 3) (safety 0)
1188 (debug 1) (compilation-speed 3)))
1189 (if (if (<= 0) nil nil
)
1190 (labels ((%f9
(f9-1 f9-2 f9-3
)
1192 (dotimes (iv4 5 a
) (%f9
0 0 b
)))
1196 ;;; MISC.259-264 (aka "CSR screwed up implementing *-MOD32")
1202 (declare (type (integer 177547470 226026978) a
))
1203 (declare (optimize (speed 3) (space 0) (safety 0) (debug 0)
1204 (compilation-speed 1)))
1205 (logand a
(* a
438810))))
1210 ;;;; Bugs in stack analysis
1211 ;;; bug 299 (reported by PFD)
1217 (declare (optimize (debug 1)))
1218 (multiple-value-call #'list
1219 (if (eval t
) (eval '(values :a
:b
:c
)) nil
)
1220 (catch 'foo
(throw 'foo
(values :x
:y
)))))))
1222 ;;; bug 298 (= MISC.183)
1223 (assert (zerop (funcall
1227 (declare (type (integer -
368154 377964) a
))
1228 (declare (type (integer 5044 14959) b
))
1229 (declare (type (integer -
184859815 -
8066427) c
))
1230 (declare (ignorable a b c
))
1231 (declare (optimize (speed 3)))
1232 (declare (optimize (safety 1)))
1233 (declare (optimize (debug 1)))
1235 (flet ((%f3
(f3-1 f3-2 f3-3
) 0))
1236 (apply #'%f3
0 (catch 'foo
(return-from b7
(%f3
0 b c
))) c nil
)))))
1238 (assert (equal (eval '(let () (apply #'list
1 (list (catch 'a
(throw 'a
(block b
2)))))))
1244 (multiple-value-call #'list
1248 (multiple-value-call #'list
1254 (return-from quux
1)
1255 (throw 'baz
2))))))))))))))
1256 (assert (equal (funcall f t
) '(:b
1)))
1257 (assert (equal (funcall f nil
) '(:a
2))))
1265 (declare (type (integer 5 155656586618) a
))
1266 (declare (type (integer -
15492 196529) b
))
1267 (declare (type (integer 7 10) c
))
1268 (declare (optimize (speed 3)))
1269 (declare (optimize (safety 1)))
1270 (declare (optimize (debug 1)))
1273 &optional
(f3-4 a
) (f3-5 0)
1275 (labels ((%f10
(f10-1 f10-2 f10-3
)
1280 (- (if (equal a b
) b
(%f10 c a
0))
1281 (catch 'ct2
(throw 'ct2 c
)))
1284 (%f3
(%f3
(%f3 b
0 0 0) a
0) a b b b c
)))) 5 0 7)
1289 '(let* ((form '(labels ((%f3
(f3-1 f3-2
) f3-1
))
1290 (apply #'%f3 b
(catch 'ct8
(throw 'ct8
(logeqv (%f3 c
0)))) nil
)))
1293 (declare (type (integer -
2 19) b
)
1294 (type (integer -
1520 218978) c
)
1295 (optimize (speed 3) (safety 1) (debug 1)))
1298 (declare (notinline logeqv apply
)
1299 (optimize (safety 3) (speed 0) (debug 0)))
1301 (cf1 (compile nil fn1
))
1302 (cf2 (compile nil fn2
))
1303 (result1 (multiple-value-list (funcall cf1
2 18886)))
1304 (result2 (multiple-value-list (funcall cf2
2 18886))))
1305 (if (equal result1 result2
)
1307 (values result1 result2
))))
1317 (optimize (speed 3) (space 3) (safety 1)
1318 (debug 2) (compilation-speed 0)))
1319 (apply (constantly 0) (catch 'ct2
0) 0 (catch 'ct2
0) nil
))))))
1322 (assert (zerop (funcall
1326 (declare (optimize (speed 2) (space 0) (safety 3) (debug 1)
1327 (compilation-speed 2)))
1328 (apply (constantly 0)
1332 (apply (constantly 0)
1351 (declare (optimize (speed 1) (space 0) (safety 0) (debug 0)))
1352 (multiple-value-prog1
1353 (the integer
(catch 'ct8
(catch 'ct7
15867134)))
1354 (catch 'ct1
(throw 'ct1
0))))))
1357 ;;; misc.361: replacing CAST with (m-v-call #'%compile-time-type-error)
1358 ;;; could transform known-values LVAR to UVL
1359 (assert (zerop (funcall
1363 (declare (notinline boole values denominator list
))
1369 (compilation-speed 2)))
1374 (let ((v9 (ignore-errors (throw 'ct6
0))))
1376 (progv nil nil
(values (boole boole-and
0 v9
)))))))))
1379 ;;; non-continuous dead UVL blocks
1380 (defun non-continuous-stack-test (x)
1381 (multiple-value-call #'list
1382 (eval '(values 11 12))
1383 (eval '(values 13 14))
1385 (return-from non-continuous-stack-test
1386 (multiple-value-call #'list
1387 (eval '(values :b1
:b2
))
1388 (eval '(values :b3
:b4
))
1391 (multiple-value-call (eval #'values
)
1392 (eval '(values 1 2))
1393 (eval '(values 3 4))
1396 (multiple-value-call (eval #'values
)
1397 (eval '(values :a1
:a2
))
1398 (eval '(values :a3
:a4
))
1401 (multiple-value-call (eval #'values
)
1402 (eval '(values 5 6))
1403 (eval '(values 7 8))
1406 (return-from int
:int
))))))))))))))))
1407 (assert (equal (non-continuous-stack-test t
) '(11 12 13 14 1 2 3 4 5 6 7 8 :ext
)))
1408 (assert (equal (non-continuous-stack-test nil
) '(:b1
:b2
:b3
:b4
:a1
:a2
:a3
:a4
:int
)))
1410 ;;; MISC.362: environment of UNWIND-PROTECTor is different from that
1412 (assert (equal (multiple-value-list (funcall
1416 (declare (optimize (speed 3) (space 3) (safety 2)
1417 (debug 2) (compilation-speed 3)))
1420 (labels ((%f15
(f15-1 f15-2 f15-3
)
1421 (rational (throw 'ct5
0))))
1427 (progv '(*s2
* *s5
*) (list 0 (%f15
0 g
0)) b
)
1431 (common-lisp:handler-case
0)))))
1443 (declare (notinline funcall min coerce
))
1449 (compilation-speed 1)))
1450 (flet ((%f12
(f12-1)
1453 (if f12-1
(multiple-value-prog1
1454 b
(return-from %f12
0))
1457 (funcall #'%f12
0))))
1460 ;;; Discussion of a CMUCL PCL bug on Sparc with Raymond Toy revealed a
1461 ;;; potential problem: optimizers and type derivers for MAX and MIN
1462 ;;; were not consistent in treating EQUALP, but not EQL, arguments.
1463 (dolist (f '(min max
))
1464 (loop for complex-arg-args in
'((1d0 2d0
) (0d0 1d0
))
1465 for complex-arg
= `(if x
,@complex-arg-args
)
1467 (loop for args in
`((1 ,complex-arg
)
1469 for form
= `(,f
,@args
)
1470 for f1
= (compile nil
`(lambda (x) ,form
))
1471 and f2
= (compile nil
`(lambda (x) (declare (notinline min max
))
1474 (dolist (x '(nil t
))
1475 (assert (eql (funcall f1 x
) (funcall f2 x
)))))))
1478 (handler-case (compile nil
'(lambda (x)
1479 (declare (optimize (speed 3) (safety 0)))
1480 (the double-float
(sqrt (the double-float x
)))))
1481 (sb-ext:compiler-note
(c)
1482 ;; Ignore the note for the float -> pointer conversion of the
1484 (unless (string= (car (last (sb-c::simple-condition-format-arguments c
)))
1486 (error "Compiler does not trust result type assertion."))))
1488 (let ((f (compile nil
'(lambda (x)
1489 (declare (optimize speed
(safety 0)))
1492 (multiple-value-prog1
1493 (sqrt (the double-float x
))
1495 (return :minus
)))))))))
1496 (assert (eql (funcall f -
1d0
) :minus
))
1497 (assert (eql (funcall f
4d0
) 2d0
)))
1499 ;;; bug 304: SBCL produced something similar to (/ (ASH x 4) 8)
1501 (compile nil
'(lambda (a i
)
1503 (declare (optimize (speed 3) (safety 0) (space 0) (debug 0)
1504 (inhibit-warnings 0)))
1505 (declare (type (alien (* (unsigned 8))) a
)
1506 (type (unsigned-byte 32) i
))
1509 (unless (search "%ASH/RIGHT" (first (simple-condition-format-arguments c
)))
1510 (error "The code is not optimized."))))
1513 (compile nil
'(lambda (x)
1514 (declare (type (integer -
100 100) x
))
1515 (declare (optimize speed
))
1516 (declare (notinline identity
))
1518 (compiler-note () (error "IDENTITY derive-type not applied.")))
1520 (assert (null (funcall (compile nil
'(lambda (x) (funcall #'cddr x
))) nil
)))
1522 ;;; MISC.293 = easy variant of bug 303: repeated write to the same
1523 ;;; LVAR; here the first write may be cleared before the second is
1531 (declare (notinline complex
))
1532 (declare (optimize (speed 1) (space 0) (safety 1)
1533 (debug 3) (compilation-speed 3)))
1534 (flet ((%f
() (multiple-value-prog1 0 (return-from %f
0))))
1535 (complex (%f
) 0)))))))
1537 ;;; MISC.110A: CAST optimizer forgot to flush LVAR derived type
1538 (assert (zerop (funcall
1542 (declare (type (integer -
1294746569 1640996137) a
))
1543 (declare (type (integer -
807801310 3) c
))
1544 (declare (optimize (speed 3) (space 3) (safety 0) (debug 0) (compilation-speed 3)))
1551 (progn (if (ldb-test (byte 0 0) (rational (throw 'ct7
0))) 0 0) 0))))
1553 391833530 -
32785211)))
1555 ;;; efficiency notes for ordinary code
1556 (macrolet ((frob (arglist &body body
)
1559 (compile nil
'(lambda ,arglist
,@body
))
1560 (sb-ext:compiler-note
(e)
1561 (error "bad compiler note for ~S:~% ~A" ',body e
)))
1563 (handler-bind ((compiler-note
1565 (setq gotit t
) (muffle-warning c
))))
1566 (compile nil
'(lambda ,arglist
(declare (optimize speed
))
1569 (error "missing compiler note for ~S" ',body
))))))
1570 (frob (x) (funcall x
))
1571 (frob (x y
) (find x y
))
1572 (frob (x y
) (find-if x y
))
1573 (frob (x y
) (find-if-not x y
))
1574 (frob (x y
) (position x y
))
1575 (frob (x y
) (position-if x y
))
1576 (frob (x y
) (position-if-not x y
))
1577 (frob (x) (aref x
0)))
1579 (macrolet ((frob (style-warn-p form
)
1582 (handler-bind ((style-warning
1584 (setq gotit t
) (muffle-warning c
))))
1587 (error "missing style-warning for ~S" ',form
)))
1591 (error "bad style-warning for ~S: ~A" ',form e
))))))
1592 (frob t
(lambda (x &optional y
&key z
) (list x y z
)))
1593 (frob nil
(lambda (x &optional y z
) (list x y z
)))
1594 (frob nil
(lambda (x &key y z
) (list x y z
)))
1595 (frob t
(defgeneric #:foo
(x &optional y
&key z
)))
1596 (frob nil
(defgeneric #:foo
(x &optional y z
)))
1597 (frob nil
(defgeneric #:foo
(x &key y z
)))
1598 (frob t
(defun #:foo
(x) (flet ((foo (x &optional y
&key z
) (list x y z
))) (foo x x
:z x
)))))
1600 ;;; this was a bug in the LOGXOR type deriver. The top form gave a
1601 ;;; note, because the system failed to derive the fact that the return
1602 ;;; from LOGXOR was small and negative, though the bottom one worked.
1603 (handler-bind ((sb-ext:compiler-note
#'error
))
1604 (compile nil
'(lambda ()
1605 (declare (optimize speed
(safety 0)))
1607 (declare (type (integer 3 6) x
)
1608 (type (integer -
6 -
3) y
))
1609 (+ (logxor x y
) most-positive-fixnum
)))))
1610 (handler-bind ((sb-ext:compiler-note
#'error
))
1611 (compile nil
'(lambda ()
1612 (declare (optimize speed
(safety 0)))
1614 (declare (type (integer 3 6) y
)
1615 (type (integer -
6 -
3) x
))
1616 (+ (logxor x y
) most-positive-fixnum
)))))
1618 ;;; check that modular ash gives the right answer, to protect against
1619 ;;; possible misunderstandings about the hardware shift instruction.
1620 (assert (zerop (funcall
1621 (compile nil
'(lambda (x y
)
1622 (declare (optimize speed
)
1623 (type (unsigned-byte 32) x y
))
1624 (logand #xffffffff
(ash x y
))))
1627 ;;; code instrumenting problems
1630 (declare (optimize (debug 3)))
1631 (list (the integer
(if nil
14 t
)))))
1635 (DECLARE (NOTINLINE LOGORC1 BYTE MASK-FIELD
))
1641 (COMPILATION-SPEED 0)))
1642 (MASK-FIELD (BYTE 7 26)
1644 (TAGBODY (THE INTEGER
(CATCH 'CT4
(LOGORC1 C -
15950))) 1)
1648 '(lambda (buffer i end
)
1649 (declare (optimize (debug 3)))
1650 (loop (when (not (eql 0 end
)) (return)))
1651 (let ((s (make-string end
)))
1652 (setf (schar s i
) (schar buffer i
))
1655 ;;; check that constant string prefix and suffix don't cause the
1656 ;;; compiler to emit code deletion notes.
1657 (handler-bind ((sb-ext:code-deletion-note
#'error
))
1658 (compile nil
'(lambda (s x
)
1659 (pprint-logical-block (s x
:prefix
"(")
1661 (compile nil
'(lambda (s x
)
1662 (pprint-logical-block (s x
:per-line-prefix
";")
1664 (compile nil
'(lambda (s x
)
1665 (pprint-logical-block (s x
:suffix
">")
1668 ;;; MISC.427: loop analysis requires complete DFO structure
1669 (assert (eql 17 (funcall
1673 (declare (notinline list reduce logior
))
1674 (declare (optimize (safety 2) (compilation-speed 1)
1675 (speed 3) (space 2) (debug 2)))
1677 (let* ((v5 (reduce #'+ (list 0 a
))))
1678 (declare (dynamic-extent v5
))
1683 (assert (zerop (funcall
1687 (declare (type (integer -
8431780939320 1571817471932) a
))
1688 (declare (type (integer -
4085 0) b
))
1689 (declare (ignorable a b
))
1692 (compilation-speed 0)
1693 #+sbcl
(sb-c:insert-step-conditions
0)
1700 (elt '(1954479092053)
1704 (lognand iv1
(ash iv1
(min 53 iv1
)))
1707 -
7639589303599 -
1368)))
1712 (declare (type (integer) a
))
1713 (declare (type (integer) b
))
1714 (declare (ignorable a b
))
1715 (declare (optimize (space 2) (compilation-speed 0)
1716 (debug 0) (safety 0) (speed 3)))
1718 (when (< iv1
2) (print 'x
)) ;; request for second constraint propagation pass
1719 (print (if (< iv1 iv1
)
1720 (logand (ash iv1 iv1
) 1)
1723 ;;; MISC.435: lambda var substitution in a deleted code.
1724 (assert (zerop (funcall
1728 (declare (notinline aref logandc2 gcd make-array
))
1730 (optimize (space 0) (safety 0) (compilation-speed 3)
1731 (speed 3) (debug 1)))
1734 (let* ((v2 (make-array nil
:initial-element
(catch 'ct1
(go tag2
)))))
1735 (declare (dynamic-extent v2
))
1736 (gcd (go tag2
) (logandc2 (catch 'ct2 c
) (aref v2
))))
1739 3021871717588 -
866608 -
2 -
17194)))
1741 ;;; MISC.436, 438: lost reoptimization
1742 (assert (zerop (funcall
1746 (declare (type (integer -
2917822 2783884) a
))
1747 (declare (type (integer 0 160159) b
))
1748 (declare (ignorable a b
))
1750 (optimize (compilation-speed 1)
1754 ; #+sbcl (sb-c:insert-step-conditions 0)
1768 '(-10197561 486 430631291
1774 (assert (zerop (funcall
1778 (declare (type (integer 0 1696) a
))
1779 ; (declare (ignorable a))
1780 (declare (optimize (space 2) (debug 0) (safety 1)
1781 (compilation-speed 0) (speed 1)))
1782 (if (logbitp 0 (ash (1- a
) (min 11 a
))) 0 0)))
1789 (declare (type (simple-array function
(2)) s
) (type ei ei
))
1790 (funcall (aref s ei
) x y
))))
1792 ;;; MISC.320: ir1-transform can create an intercomponent reference to
1794 (assert (eql 102 (funcall
1798 (declare (optimize (speed 3) (space 0) (safety 2)
1799 (debug 2) (compilation-speed 0)))
1802 (flet ((%f12
() (rem 0 -
43)))
1803 (multiple-value-call #'%f12
(values))))))))))
1805 ;;; MISC.437: lost reoptimization after FLUSH-DEST
1806 (assert (zerop (funcall
1809 '(lambda (a b c d e
)
1810 (declare (notinline values complex eql
))
1812 (optimize (compilation-speed 3)
1819 &optional
(f10-4 (ignore-errors 0)) (f10-5 0)
1820 &key
&allow-other-keys
)
1821 (if (or (eql 0 0) t
) 0 (if f10-1
0 0))))
1822 (complex (multiple-value-call #'%f10
(values a c b
0 0)) 0))))
1823 80043 74953652306 33658947 -
63099937105 -
27842393)))
1825 ;;; bug #351 -- program-error for malformed LET and LET*, including those
1826 ;;; resulting from SETF of LET.
1827 (with-test (:name
:bug-351
)
1828 (dolist (fun (list (compile nil
'(lambda (x) (let :bogus-let
:oops
)))
1829 (compile nil
'(lambda (x) (let* :bogus-let
* :oops
)))
1830 (compile nil
'(lambda (x) (push x
(let ((y 0)) y
))))))
1831 (assert (functionp fun
))
1832 (multiple-value-bind (res err
) (ignore-errors (funcall fun t
))
1833 (princ err
) (terpri)
1835 (assert (typep err
'program-error
)))))
1837 (let ((fun (compile nil
'(lambda (x) (random (if x
10 20))))))
1838 (dotimes (i 100 (error "bad RANDOM distribution"))
1839 (when (> (funcall fun nil
) 9)
1842 (when (> (funcall fun t
) 9)
1843 (error "bad RANDOM event"))))
1845 ;;; 0.8.17.28-sma.1 lost derived type information.
1846 (with-test (:name
:0.8.17.28-sma
.1 :fails-on
:sparc
)
1847 (handler-bind ((sb-ext:compiler-note
(lambda (c) (error "~A" c
))))
1850 (declare (optimize (speed 3) (safety 0)))
1851 (declare (type (integer 0 80) x
)
1852 (type (integer 0 11) y
)
1853 (type (simple-array (unsigned-byte 32) (*)) v
))
1854 (setf (aref v
0) (* (* x
#.
(floor (ash 1 32) (* 11 80))) y
))
1857 ;;; Bug reported by Robert J. Macomber: instrumenting of more-entry
1858 ;;; prevented open coding of %LISTIFY-REST-ARGS.
1859 (let ((f (compile nil
'(lambda ()
1860 (declare (optimize (debug 3)))
1861 (with-simple-restart (blah "blah") (error "blah"))))))
1862 (handler-bind ((error (lambda (c) (invoke-restart 'blah
))))
1863 (assert (equal (multiple-value-list (funcall f
)) '(nil t
)))))
1865 ;;; Bug reported by Timmy Douglas: overflow in bit vector setter with
1866 ;;; constant index and value.
1867 (loop for n-bits
= 1 then
(* n-bits
2)
1868 for type
= `(unsigned-byte ,n-bits
)
1869 and v-max
= (1- (ash 1 n-bits
))
1870 while
(<= n-bits sb-vm
:n-word-bits
)
1872 (let* ((n (* 2 (1+ (- sb-vm
::n-word-bits n-bits
))))
1873 (array1 (make-array n
:element-type type
))
1874 (array2 (make-array n
:element-type type
)))
1876 (dolist (v (list 0 v-max
))
1877 (let ((f (compile nil
`(lambda (a)
1878 (declare (type (simple-array ,type
(,n
)) a
))
1879 (setf (aref a
,i
) ,v
)))))
1880 (fill array1
(- v-max v
))
1881 (fill array2
(- v-max v
))
1883 (setf (aref array2 i
) v
)
1884 (assert (every #'= array1 array2
)))))))
1886 (let ((fn (compile nil
'(lambda (x)
1887 (declare (type bit x
))
1888 (declare (optimize speed
))
1889 (let ((b (make-array 64 :element-type
'bit
1890 :initial-element
0)))
1892 (assert (= (funcall fn
0) 64))
1893 (assert (= (funcall fn
1) 0)))
1895 (let ((fn (compile nil
'(lambda (x y
)
1896 (declare (type simple-bit-vector x y
))
1897 (declare (optimize speed
))
1901 (make-array 64 :element-type
'bit
:initial-element
0)
1902 (make-array 64 :element-type
'bit
:initial-element
0)))
1906 (make-array 64 :element-type
'bit
:initial-element
0)
1907 (let ((b (make-array 64 :element-type
'bit
:initial-element
0)))
1908 (setf (sbit b
63) 1)
1911 ;;; MISC.535: compiler failure
1912 (let ((c0 #c
(4196.088977268509d0 -
15943.3603515625d0
)))
1913 (assert (not (funcall
1917 (declare (optimize speed
(safety 1))
1920 (eql (the (complex double-float
) p1
) p2
)))
1921 c0
#c
(12 612/979)))))
1923 ;;; reported by Lutz Euler: we shouldn't signal a compiler note for
1924 ;;; simple-bit-vector functions.
1925 (handler-bind ((sb-ext:compiler-note
#'error
))
1926 (compile nil
'(lambda (x)
1927 (declare (type simple-bit-vector x
))
1929 (handler-bind ((sb-ext:compiler-note
#'error
))
1930 (compile nil
'(lambda (x y
)
1931 (declare (type simple-bit-vector x y
))
1934 ;;; MISC.550: CAST merging in IR1 finalization caused unexpected
1935 ;;; code transformations.
1936 (assert (eql (funcall
1940 (declare (optimize (speed 3) (safety 2) (debug 3) (space 3))
1943 (or p1
(the (eql t
) p2
))))
1947 ;;; MISC.548: type check weakening converts required type into
1954 (declare (optimize (speed 2) (safety 1) (debug 3) (space 2)))
1955 (atom (the (member f assoc-if write-line t w
) p1
))))
1958 ;;; Free special bindings only apply to the body of the binding form, not
1959 ;;; the initialization forms.
1961 (funcall (compile 'nil
1964 (declare (special x
))
1966 ((lambda (&optional
(y x
))
1967 (declare (special x
)) y
)))))))))
1969 ;;; Bug from pfdietz's random tester: the compiler knew that IMAGPART of
1970 ;;; a rational was zero, but didn't do the substitution, leading to a
1971 ;;; crash in the ASH vop (since a shift of 57 wouldn't fit in the
1972 ;;; machine's ASH instruction's immediate field) that the compiler
1973 ;;; thought was legitimate.
1974 (with-test (:name
:overlarge-immediate-in-ash-vop
)
1977 (DECLARE (TYPE (INTEGER -
2 14) B
))
1978 (DECLARE (IGNORABLE B
))
1979 (ASH (IMAGPART B
) 57))))
1981 ;;; bug reported by Eduardo Mu\~noz
1982 (multiple-value-bind (fun warnings failure
)
1983 (compile nil
'(lambda (struct first
)
1984 (declare (optimize speed
))
1985 (let* ((nodes (nodes struct
))
1986 (bars (bars struct
))
1987 (length (length nodes
))
1988 (new (make-array length
:fill-pointer
0)))
1989 (vector-push first new
)
1990 (loop with i fixnum
= 0
1991 for newl fixnum
= (length new
)
1992 while
(< newl length
) do
1993 (let ((oldl (length new
)))
1994 (loop for j fixnum from i below newl do
1995 (dolist (n (node-neighbours (aref new j
) bars
))
1996 (unless (find n new
)
1997 (vector-push n new
))))
2000 (declare (ignore fun warnings failure
))
2001 (assert (not failure
)))
2003 ;;; bug #389: "0.0 can't be converted to type NIL." (Brian Rowe
2005 (compile nil
'(lambda (x y a b c
)
2006 (- y
(* (signum x
) (sqrt (abs (- (* b x
) c
)))))))
2008 ;;; Type inference from CHECK-TYPE
2009 (let ((count0 0) (count1 0))
2010 (handler-bind ((sb-ext:compiler-note
(lambda (c) (incf count0
))))
2011 (compile nil
'(lambda (x)
2012 (declare (optimize (speed 3)))
2014 ;; forced-to-do GENERIC-+, etc, possible word -> bignum conversion note
2015 (assert (> count0
1))
2016 (handler-bind ((sb-ext:compiler-note
(lambda (c) (incf count1
))))
2017 (compile nil
'(lambda (x)
2018 (declare (optimize (speed 3)))
2019 (check-type x fixnum
)
2021 ;; Only the posssible word -> bignum conversion note
2022 (assert (= count1
1)))
2024 ;;; Up to 0.9.8.22 x86-64 had broken return value handling in the
2025 ;;; %SET-SAP-REF-DOUBLE/SINGLE VOPs.
2026 (with-test (:name
:sap-ref-float
)
2027 (compile nil
'(lambda (sap)
2028 (let ((x (setf (sb-vm::sap-ref-double sap
0) 1d0
)))
2030 (compile nil
'(lambda (sap)
2031 (let ((x (setf (sb-vm::sap-ref-single sap
0) 1d0
)))
2035 (with-test (:name
:string-union-types
)
2036 (compile nil
'(lambda (x)
2037 (declare (type (or (simple-array character
(6))
2038 (simple-array character
(5))) x
))
2041 ;;; MISC.623: missing functions for constant-folding
2047 (declare (optimize (space 2) (speed 0) (debug 2)
2048 (compilation-speed 3) (safety 0)))
2049 (loop for lv3 below
1
2051 (loop for lv2 below
2
2053 (bit #*1001101001001
2054 (min 12 (max 0 lv3
))))))))))))
2056 ;;; MISC.624: erroneous AVER in x86's %LOGBITP VOPs
2062 (declare (type (integer 21 28) a
))
2063 (declare (optimize (compilation-speed 1) (safety 2)
2064 (speed 0) (debug 0) (space 1)))
2065 (let* ((v7 (flet ((%f3
(f3-1 f3-2
)
2066 (loop for lv2 below
1
2070 (min 7 (max 0 (eval '0))))))))
2075 ;;; MISC.626: bandaged AVER was still wrong
2076 (assert (eql -
829253
2081 (declare (type (integer -
902970 2) a
))
2082 (declare (optimize (space 2) (debug 0) (compilation-speed 1)
2083 (speed 0) (safety 3)))
2084 (prog2 (if (logbitp 30 a
) 0 (block b3
0)) a
)))
2087 ;; MISC.628: constant-folding %LOGBITP was buggy
2093 (declare (optimize (safety 3) (space 3) (compilation-speed 3)
2094 (speed 0) (debug 1)))
2095 (not (not (logbitp 0 (floor 2147483651 (min -
23 0))))))))))
2097 ;; mistyping found by random-tester
2103 (declare (optimize (speed 1) (debug 0)
2104 (space 2) (safety 0) (compilation-speed 0)))
2106 (* (/ (multiple-value-prog1 -
29457482 -
5602513511) 1))))))))
2108 ;; aggressive constant folding (bug #400)
2110 (eq t
(funcall (compile nil
'(lambda () (or t
(the integer
(/ 1 0))))))))
2112 (with-test (:name
(:compiler
:constraint-propagation
:var-eql-to-non-var-1
))
2115 (compile nil
'(lambda (x y
)
2116 (when (eql x
(length y
))
2118 (declare (optimize (speed 3)))
2120 (compiler-note () (error "The code is not optimized.")))))
2122 (with-test (:name
(:compiler
:constraint-propagation
:var-eql-to-non-var-2
))
2125 (compile nil
'(lambda (x y
)
2126 (when (eql (length y
) x
)
2128 (declare (optimize (speed 3)))
2130 (compiler-note () (error "The code is not optimized.")))))
2132 (with-test (:name
(:compiler
:constraint-propagation
:float-bounds-1
))
2134 (compile nil
'(lambda (x)
2135 (declare (type (single-float * (3.0
)) x
))
2139 (compiler-note () (error "Deleted reachable code."))))
2141 (defun assert-code-deletion-note (lambda &optional
(howmany 1))
2143 (handler-bind ((code-deletion-note
2146 ;; even though notes are not warnings,
2147 ;; compiler-notify provides the MUFFLE-WARNING restart.
2148 (muffle-warning c
))))
2149 (compile nil lambda
)
2150 (assert (eql n howmany
)))))
2152 (with-test (:name
(:compiler
:constraint-propagation
:float-bounds-2
))
2153 (assert-code-deletion-note
2155 (declare (type single-float x
))
2158 (error "This is unreachable."))))))
2160 (with-test (:name
(:compiler
:constraint-propagation
:float-bounds-3
2162 (assert-code-deletion-note
2164 (declare (type (single-float 0.0) x
))
2167 (error "This is unreachable."))))))
2169 (with-test (:name
(:compiler
:constraint-propagation
:float-bounds-4
2171 (assert-code-deletion-note
2173 (declare (type (single-float 0.0) x
)
2174 (type (single-float (0.0
)) y
))
2177 (error "This is unreachable."))))))
2179 (with-test (:name
(:compiler
:constraint-propagation
:var-eql-to-var-1
))
2180 (assert-code-deletion-note
2182 (when (typep y
'fixnum
)
2184 (unless (typep x
'fixnum
)
2185 (error "This is unreachable"))
2188 (with-test (:name
(:compiler
:constraint-propagation
:var-eql-to-var-2
))
2189 (assert-code-deletion-note
2191 (when (typep y
'fixnum
)
2193 (unless (typep x
'fixnum
)
2194 (error "This is unreachable"))
2197 ;; Reported by John Wiseman, sbcl-devel
2198 ;; Subject: [Sbcl-devel] float type derivation bug?
2199 ;; Date: Tue, 4 Apr 2006 15:28:15 -0700
2200 (with-test (:name
(:type-derivation
:float-bounds
))
2201 (compile nil
'(lambda (bits)
2202 (let* ((s (if (= (ash bits -
31) 0) 1 -
1))
2203 (e (logand (ash bits -
23) #xff
))
2205 (ash (logand bits
#x7fffff
) 1)
2206 (logior (logand bits
#x7fffff
) #x800000
))))
2207 (float (* s m
(expt 2 (- e
150))))))))
2209 ;; Reported by James Knight
2210 ;; Subject: [Sbcl-devel] AVER: "(EQ (SB-NAME (SC-SB (TN-SC TN))) 'REGISTERS)"
2211 ;; Date: Fri, 24 Mar 2006 19:30:00 -0500
2212 (with-test (:name
:logbitp-vop
)
2214 '(lambda (days shift
)
2215 (declare (type fixnum shift days
))
2217 (canonicalized-shift (+ shift
1))
2218 (first-wrapping-day (- 1 canonicalized-shift
)))
2219 (declare (type fixnum result
))
2220 (dotimes (source-day 7)
2221 (declare (type (integer 0 6) source-day
))
2222 (when (logbitp source-day days
)
2226 (if (< source-day first-wrapping-day
)
2227 (+ source-day canonicalized-shift
)
2229 canonicalized-shift
) 7)))))))
2232 ;;; MISC.637: incorrect delaying of conversion of optional entries
2233 ;;; with hairy constant defaults
2234 (let ((f '(lambda ()
2235 (labels ((%f11
(f11-2 &key key1
)
2236 (labels ((%f8
(f8-2 &optional
(f8-5 (if nil
(return-from %f11
0) 0)))
2241 (assert (eq (funcall (compile nil f
)) :good
)))
2243 ;;; MISC.555: new reference to an already-optimized local function
2244 (let* ((l '(lambda (p1)
2245 (declare (optimize (speed 1) (safety 2) (debug 2) (space 0)) (type keyword p1
))
2247 (f (compile nil l
)))
2248 (assert (funcall f
:good
))
2249 (assert (nth-value 1 (ignore-errors (funcall f
42)))))
2251 ;;; Check that the compiler doesn't munge *RANDOM-STATE*.
2252 (let* ((state (make-random-state))
2253 (*random-state
* (make-random-state state
))
2254 (a (random most-positive-fixnum
)))
2255 (setf *random-state
* state
)
2256 (compile nil
`(lambda (x a
)
2257 (declare (single-float x
)
2258 (type (simple-array double-float
) a
))
2259 (+ (loop for i across a
2262 (assert (= a
(random most-positive-fixnum
))))
2264 ;;; MISC.641: LET-conversion after physical environment analysis lost NLX-INFOs
2265 (let ((form '(lambda ()
2266 (declare (optimize (speed 1) (space 0) (debug 2)
2267 (compilation-speed 0) (safety 1)))
2268 (flet ((%f3
(f3-1 &key
(key1 (count (floor 0 (min -
74 0)) #())))
2270 (apply #'%f3
0 nil
)))))
2271 (assert (zerop (funcall (compile nil form
)))))
2273 ;;; size mismatch: #<SB-VM::EA :DWORD base=#<SB-C:TN t1[RDX]> disp=1> is a :DWORD and #<SB-C:TN t2[RAX]> is a :QWORD. on x86-64
2274 (compile nil
'(lambda ()
2275 (let ((x (make-array '(1) :element-type
'(signed-byte 32))))
2276 (setf (aref x
0) 1))))
2278 ;;; step instrumentation confusing the compiler, reported by Faré
2279 (handler-bind ((warning #'error
))
2280 (compile nil
'(lambda ()
2281 (declare (optimize (debug 2))) ; not debug 3!
2282 (let ((val "foobar"))
2283 (map-into (make-array (list (length val
))
2284 :element-type
'(unsigned-byte 8))
2285 #'char-code val
)))))
2287 ;;; overconfident primitive type computation leading to bogus type
2289 (let* ((form1 '(lambda (x)
2290 (declare (type (and condition function
) x
))
2292 (fun1 (compile nil form1
))
2294 (declare (type (and standard-object function
) x
))
2296 (fun2 (compile nil form2
)))
2297 (assert-error (funcall fun1
(make-condition 'error
)))
2298 (assert-error (funcall fun1 fun1
))
2299 (assert-error (funcall fun2 fun2
))
2300 (assert (eq (funcall fun2
#'print-object
) #'print-object
)))
2302 ;;; LET* + VALUES declaration: while the declaration is a non-standard
2303 ;;; and possibly a non-conforming extension, as long as we do support
2304 ;;; it, we might as well get it right.
2306 ;;; Bug reported by Kaersten Poeck on sbcl-devel 20061023.
2307 (compile nil
'(lambda () (let* () (declare (values list
)))))
2310 ;;; test for some problems with too large immediates in x86-64 modular
2312 (compile nil
'(lambda (x) (declare (fixnum x
))
2313 (logand most-positive-fixnum
(logxor x most-positive-fixnum
))))
2315 (compile nil
'(lambda (x) (declare (fixnum x
))
2316 (logand most-positive-fixnum
(+ x most-positive-fixnum
))))
2318 (compile nil
'(lambda (x) (declare (fixnum x
))
2319 (logand most-positive-fixnum
(* x most-positive-fixnum
))))
2322 (with-test (:name
:propagate-type-through-error-and-binding
)
2323 (assert (let (warned-p)
2324 (handler-bind ((warning (lambda (w) (setf warned-p t
))))
2327 (list (let ((y (the real x
)))
2328 (unless (floatp y
) (error ""))
2330 (integer-length x
)))))
2333 ;; Dead / in safe code
2334 (with-test (:name
:safe-dead-
/)
2337 (funcall (compile nil
2339 (declare (optimize (safety 3)))
2344 (division-by-zero ()
2347 ;;; Dead unbound variable (bug 412)
2348 (with-test (:name
:dead-unbound
)
2351 (funcall (compile nil
2355 (unbound-variable ()
2358 ;;; No compiler notes from compiling SUBSEQ SIMPLE-VECTOR.
2359 (handler-bind ((sb-ext:compiler-note
'error
))
2362 (funcall (compile nil
`(lambda (s p e
)
2363 (declare (optimize speed
)
2370 ;;; No compiler notes from compiling COPY-SEQ SIMPLE-VECTOR.
2371 (handler-bind ((sb-ext:compiler-note
'error
))
2374 (funcall (compile nil
`(lambda (s)
2375 (declare (optimize speed
)
2378 (vector 1 2 3 4)))))
2380 ;;; bug in adding DATA-VECTOR-REF-WITH-OFFSET to x86-64
2381 (assert (not (mismatch #(1.0f0
2.0f0
) (make-array 2 :element-type
'single-float
:initial-contents
(list 1.0f0
2.0f0
)))))
2383 ;;; bug in interval-arithmetic used by the compiler: needless attempt to coerce too
2384 ;;; large bignums to floats
2385 (dolist (op '(* / + -
))
2389 (declare (type (integer 0 #.
(* 2 (truncate most-positive-double-float
))) x
))
2392 do
(let ((arg (random (truncate most-positive-double-float
))))
2393 (assert (eql (funcall fun arg
)
2394 (funcall op
0.0d0 arg
)))))))
2396 (with-test (:name
:high-debug-known-function-inlining
)
2397 (let ((fun (compile nil
2399 (declare (optimize (debug 3)) (inline append
))
2400 (let ((fun (lambda (body)
2405 '((foo (bar)))))))))
2408 (with-test (:name
:high-debug-known-function-transform-with-optional-arguments
)
2409 (compile nil
'(lambda (x y
)
2410 (declare (optimize sb-c
::preserve-single-use-debug-variables
))
2412 (some-unknown-function
2414 (return (member x y
))))
2419 ;;; Compiling W-P-O when the pinned objects are known to be fixnums
2421 (compile nil
'(lambda (x y
)
2422 (declare (fixnum y
) (character x
))
2423 (sb-sys:with-pinned-objects
(x y
)
2424 (some-random-function))))
2426 ;;; *CHECK-CONSISTENCY* and TRULY-THE
2428 (with-test (:name
:bug-423
)
2429 (let ((sb-c::*check-consistency
* t
))
2430 (handler-bind ((warning #'error
))
2431 (flet ((make-lambda (type)
2435 (let ((q (truly-the list z
)))
2438 (let ((q (truly-the vector z
)))
2442 (compile nil
(make-lambda 'list
))
2443 (compile nil
(make-lambda 'vector
))))))
2445 ;;; this caused a momentary regression when an ill-adviced fix to
2446 ;;; bug 427 made ANY-REG suitable for primitive-type T:
2448 ;;; no :MOVE-ARG VOP defined to move #<SB-C:TN t1> (SC SB-VM::SINGLE-REG) to #<SB-C:TN t2> (SC SB-VM::ANY-REG)
2449 ;;; [Condition of type SIMPLE-ERROR]
2456 (setf (sb-alien:deref
(sb-alien:cast
(sb-alien:sap-alien
(unknown1) (* unsigned-char
))
2457 (* double-float
))) frob
))
2459 (%zig
(the (values (single-float (0.0
) 1.0) &optional
) (unknown2)))
2463 ;;; non-required arguments in HANDLER-BIND
2464 (assert (eq :oops
(car (funcall (compile nil
2467 (handler-bind ((error (lambda (&rest args
) (return (cons :oops args
)))))
2471 ;;; NIL is a legal function name
2472 (assert (eq 'a
(flet ((nil () 'a
)) (nil))))
2475 (assert (null (let* ((x 296.3066f0
)
2477 (form `(lambda (r p2
)
2478 (declare (optimize speed
(safety 1))
2479 (type (simple-array single-float nil
) r
)
2480 (type (integer -
9369756340 22717335) p2
))
2481 (setf (aref r
) (* ,x
(the (eql 22717067) p2
)))
2483 (r (make-array nil
:element-type
'single-float
))
2485 (funcall (compile nil form
) r y
)
2486 (let ((actual (aref r
)))
2487 (unless (eql expected actual
)
2488 (list expected actual
))))))
2490 (assert (null (let* ((x -
2367.3296f0
)
2492 (form `(lambda (r p2
)
2493 (declare (optimize speed
(safety 1))
2494 (type (simple-array single-float nil
) r
)
2495 (type (eql 46790178) p2
))
2496 (setf (aref r
) (+ ,x
(the (integer 45893897) p2
)))
2498 (r (make-array nil
:element-type
'single-float
))
2500 (funcall (compile nil form
) r y
)
2501 (let ((actual (aref r
)))
2502 (unless (eql expected actual
)
2503 (list expected actual
))))))
2508 (compile nil
'(lambda (p1 p2
)
2510 (optimize (speed 1) (safety 0)
2511 (debug 0) (space 0))
2512 (type (member 8174.8604) p1
)
2513 (type (member -
95195347) p2
))
2515 8174.8604 -
95195347)))
2523 (declare (optimize (speed 3) (safety 0) (debug 3) (space 1))
2524 (type (member -
94430.086f0
) p1
))
2525 (floor (the single-float p1
) 19311235)))
2534 (declare (optimize (speed 1) (safety 2)
2535 (debug 2) (space 3))
2536 (type (eql -
39466.56f0
) p1
))
2537 (ffloor p1
305598613)))
2546 (declare (optimize (speed 1) (safety 1) (debug 1) (space 2))
2547 (type (eql -
83232.09f0
) p1
))
2548 (ceiling p1 -
83381228)))
2557 (declare (optimize (speed 1) (safety 1)
2558 (debug 1) (space 0))
2559 (type (member -
66414.414f0
) p1
))
2560 (ceiling p1 -
63019173f0
)))
2569 (declare (optimize (speed 0) (safety 1)
2570 (debug 0) (space 1))
2571 (type (eql 20851.398f0
) p1
))
2572 (fceiling p1
80839863)))
2578 (compile nil
'(lambda (x)
2579 (declare (type (eql -
5067.2056) x
))
2586 (compile nil
'(lambda (x) (declare (type (eql -
1.0) x
))
2592 (assert (plusp (funcall
2596 (declare (optimize (speed 0) (safety 1) (debug 1) (space 1))
2597 (type (eql -
39887.645) p1
))
2598 (mod p1
382352925)))
2602 (assert (let ((result (funcall
2606 (declare (optimize (speed 0) (safety 3) (debug 1) (space 0))
2607 (type (eql 33558541) p2
))
2610 (typep result
'single-float
)))
2614 (let* ((form '(lambda (p2)
2615 (declare (optimize (speed 0) (safety 1)
2616 (debug 2) (space 2))
2617 (type (member -
19261719) p2
))
2618 (ceiling -
46022.094 p2
))))
2619 (values (funcall (compile nil form
) -
19261719)))))
2622 (assert (let* ((x 26899.875)
2624 (declare (optimize (speed 3) (safety 1) (debug 3) (space 1))
2625 (type (member ,x
#:g5437 char-code
#:g5438
) p2
))
2627 (floatp (funcall (compile nil form
) x
))))
2635 (declare (optimize (speed 3) (safety 2) (debug 3) (space 0))
2637 (+ 81535869 (the (member 17549.955 #:g35917
) p2
))))
2639 (+ 81535869 17549.955)))
2643 (let ((form '(lambda (p2)
2644 (declare (optimize (speed 0) (safety 2) (debug 0) (space 2))
2645 (type (member integer eql
) p2
))
2647 (funcall (compile nil form
) 'integer
))))
2651 (let ((form '(lambda (p2)
2652 (declare (optimize (speed 0) (safety 2) (debug 0) (space 2))
2653 (type (member integer mod
) p2
))
2655 (funcall (compile nil form
) 'integer
))))
2659 (let ((form '(lambda (p2)
2660 (declare (optimize (speed 0) (safety 2) (debug 0) (space 2))
2661 (type (member integer values
) p2
))
2663 (funcall (compile nil form
) 'integer
))))
2665 (with-test (:name
:string-aref-type
)
2666 (assert (eq 'character
2667 (funcall (compile nil
2669 (ctu:compiler-derived-type
(aref (the string s
) 0))))
2672 (with-test (:name
:base-string-aref-type
)
2673 (assert (eq #+sb-unicode
'base-char
2674 #-sb-unicode
'character
2675 (funcall (compile nil
2677 (ctu:compiler-derived-type
(aref (the base-string s
) 0))))
2678 (coerce "foo" 'base-string
)))))
2680 (with-test (:name
:dolist-constant-type-derivation
)
2681 (assert (equal '(integer 1 3)
2682 (funcall (compile nil
2684 (dolist (y '(1 2 3))
2686 (return (ctu:compiler-derived-type y
))))))
2689 (with-test (:name
:dolist-simple-list-type-derivation
)
2690 (assert (equal '(integer 1 3)
2691 (funcall (compile nil
2693 (dolist (y (list 1 2 3))
2695 (return (ctu:compiler-derived-type y
))))))
2698 (with-test (:name
:dolist-dotted-constant-list-type-derivation
)
2700 (fun (handler-bind ((style-warning (lambda (c) (push c warned
))))
2703 (dolist (y '(1 2 3 .
4) :foo
)
2705 (return (ctu:compiler-derived-type y
)))))))))
2706 (assert (equal '(integer 1 3) (funcall fun t
)))
2707 (assert (= 1 (length warned
)))
2708 (multiple-value-bind (res err
) (ignore-errors (funcall fun nil
))
2710 (assert (typep err
'type-error
)))))
2712 (with-test (:name
:constant-list-destructuring
)
2713 (handler-bind ((sb-ext:compiler-note
#'error
))
2719 (destructuring-bind (a (b c
) d
) '(1 (2 3) 4)
2726 (destructuring-bind (a (b c
) d
) '(1 "foo" 4)
2730 ;;; Functions with non-required arguments used to end up with
2731 ;;; (&OPTIONAL-DISPATCH ...) as their names.
2732 (with-test (:name
:hairy-function-name
)
2733 (assert (eq 'read-line
(nth-value 2 (function-lambda-expression #'read-line
))))
2734 (assert (equal "#<FUNCTION READ-LINE>" (princ-to-string #'read-line
))))
2736 ;;; PROGV + RESTRICT-COMPILER-POLICY
2737 (with-test (:name
:progv-and-restrict-compiler-policy
)
2738 (let ((sb-c::*policy-restrictions
* sb-c
::*policy-restrictions
*))
2739 (restrict-compiler-policy 'debug
3)
2740 (let ((fun (compile nil
'(lambda (x)
2742 (declare (special i
))
2744 (progv '(i) (list (+ i
1))
2747 (assert (equal '(1 2 1) (funcall fun
1))))))
2749 ;;; It used to be possible to confuse the compiler into
2750 ;;; IR2-converting such a call to CONS
2751 (with-test (:name
:late-bound-primitive
)
2752 (compile nil
`(lambda ()
2753 (funcall 'cons
1))))
2755 (with-test (:name
:hairy-array-element-type-derivation
)
2756 (compile nil
'(lambda (x)
2757 (declare (type (and simple-string
(satisfies array-has-fill-pointer-p
)) x
))
2758 (array-element-type x
))))
2760 (with-test (:name
:rest-list-type-derivation
)
2761 (multiple-value-bind (type derivedp
)
2762 (funcall (compile nil
`(lambda (&rest args
)
2763 (ctu:compiler-derived-type args
)))
2765 (assert (eq 'list type
))
2768 (with-test (:name
:rest-list-type-derivation2
)
2769 (multiple-value-bind (type derivedp
)
2770 (funcall (funcall (compile nil
`(lambda ()
2771 (lambda (&rest args
)
2772 (ctu:compiler-derived-type args
))))))
2773 (assert (eq 'list type
))
2776 (with-test (:name
:rest-list-type-derivation3
)
2777 (multiple-value-bind (type derivedp
)
2778 (funcall (funcall (compile nil
`(lambda ()
2779 (lambda (&optional x
&rest args
)
2780 (unless x
(error "oops"))
2781 (ctu:compiler-derived-type args
)))))
2783 (assert (eq 'list type
))
2786 (with-test (:name
:rest-list-type-derivation4
)
2787 (multiple-value-bind (type derivedp
)
2788 (funcall (funcall (compile nil
`(lambda ()
2789 (lambda (&optional x
&rest args
)
2790 (declare (type (or null integer
) x
))
2791 (when x
(setf args x
))
2792 (ctu:compiler-derived-type args
)))))
2794 (assert (equal '(or cons null integer
) type
))
2797 (with-test (:name
:base-char-typep-elimination
)
2798 (assert (eq (funcall (compile nil
2800 (declare (type base-char ch
) (optimize (speed 3) (safety 0)))
2801 (typep ch
'base-char
)))
2805 (with-test (:name
:regression-1.0
.24.37)
2806 (compile nil
'(lambda (&key
(test (constantly t
)))
2807 (when (funcall test
)
2810 ;;; Attempt to test a decent cross section of conditions
2811 ;;; and values types to move conditionally.
2813 ((test-comparison (comparator type x y
)
2815 ,@(loop for
(result-type a b
)
2821 (nil #c
(1.0
1.0) #c
(2.0
2.0))
2825 ((unsigned-byte #.sb-vm
:n-word-bits
)
2826 (1+ most-positive-fixnum
)
2827 (+ 2 most-positive-fixnum
))
2828 ((signed-byte #.sb-vm
:n-word-bits
)
2829 -
1 (* 2 most-negative-fixnum
))
2830 (single-float 0.0 1.0)
2831 (double-float 0d0
1d0
))
2832 for lambda
= (if result-type
2834 (declare (,type x y
)
2836 (if (,comparator x y
)
2839 (declare (,type x y
))
2840 (if (,comparator x y
)
2842 for args
= `(,x
,y
,@(and result-type
2846 (eql (funcall (compile nil
',lambda
)
2848 (eval '(,lambda
,@args
))))))))
2849 (sb-vm::with-float-traps-masked
2850 (:divide-by-zero
:overflow
:inexact
:invalid
)
2851 (let (#+sb-eval
(sb-ext:*evaluator-mode
* :interpret
))
2852 (declare (sb-ext:muffle-conditions style-warning
))
2853 (test-comparison eql t t nil
)
2854 (test-comparison eql t t t
)
2856 (test-comparison = t
1 0)
2857 (test-comparison = t
1 1)
2858 (test-comparison = t
(1+ most-positive-fixnum
) (+ 2 most-positive-fixnum
))
2859 (test-comparison = fixnum
1 0)
2860 (test-comparison = fixnum
0 0)
2861 (test-comparison = (unsigned-byte #.sb-vm
:n-word-bits
) 1 0)
2862 (test-comparison = (unsigned-byte #.sb-vm
:n-word-bits
) 0 0)
2863 (test-comparison = (signed-byte #.sb-vm
:n-word-bits
) 1 0)
2864 (test-comparison = (signed-byte #.sb-vm
:n-word-bits
) 1 1)
2866 (test-comparison = single-float
0.0 1.0)
2867 (test-comparison = single-float
1.0 1.0)
2868 (test-comparison = single-float
(/ 1.0 0.0) (/ 1.0 0.0))
2869 (test-comparison = single-float
(/ 1.0 0.0) 1.0)
2870 (test-comparison = single-float
(/ 0.0 0.0) (/ 0.0 0.0))
2871 (test-comparison = single-float
(/ 0.0 0.0) 0.0)
2873 (test-comparison = double-float
0d0
1d0
)
2874 (test-comparison = double-float
1d0
1d0
)
2875 (test-comparison = double-float
(/ 1d0
0d0
) (/ 1d0
0d0
))
2876 (test-comparison = double-float
(/ 1d0
0d0
) 1d0
)
2877 (test-comparison = double-float
(/ 0d0
0d0
) (/ 0d0
0d0
))
2878 (test-comparison = double-float
(/ 0d0
0d0
) 0d0
)
2880 (test-comparison < t
1 0)
2881 (test-comparison < t
0 1)
2882 (test-comparison < t
1 1)
2883 (test-comparison < t
(1+ most-positive-fixnum
) (+ 2 most-positive-fixnum
))
2884 (test-comparison < t
(+ 2 most-positive-fixnum
) (1+ most-positive-fixnum
))
2885 (test-comparison < fixnum
1 0)
2886 (test-comparison < fixnum
0 1)
2887 (test-comparison < fixnum
0 0)
2888 (test-comparison < (unsigned-byte #.sb-vm
:n-word-bits
) 1 0)
2889 (test-comparison < (unsigned-byte #.sb-vm
:n-word-bits
) 0 1)
2890 (test-comparison < (unsigned-byte #.sb-vm
:n-word-bits
) 0 0)
2891 (test-comparison < (signed-byte #.sb-vm
:n-word-bits
) 1 0)
2892 (test-comparison < (signed-byte #.sb-vm
:n-word-bits
) 0 1)
2893 (test-comparison < (signed-byte #.sb-vm
:n-word-bits
) 1 1)
2895 (test-comparison < single-float
0.0 1.0)
2896 (test-comparison < single-float
1.0 0.0)
2897 (test-comparison < single-float
1.0 1.0)
2898 (test-comparison < single-float
(/ 1.0 0.0) (/ 1.0 0.0))
2899 (test-comparison < single-float
(/ 1.0 0.0) 1.0)
2900 (test-comparison < single-float
1.0 (/ 1.0 0.0))
2901 (test-comparison < single-float
(/ 0.0 0.0) (/ 0.0 0.0))
2902 (test-comparison < single-float
(/ 0.0 0.0) 0.0)
2904 (test-comparison < double-float
0d0
1d0
)
2905 (test-comparison < double-float
1d0
0d0
)
2906 (test-comparison < double-float
1d0
1d0
)
2907 (test-comparison < double-float
(/ 1d0
0d0
) (/ 1d0
0d0
))
2908 (test-comparison < double-float
(/ 1d0
0d0
) 1d0
)
2909 (test-comparison < double-float
1d0
(/ 1d0
0d0
))
2910 (test-comparison < double-float
(/ 0d0
0d0
) (/ 0d0
0d0
))
2911 (test-comparison < double-float
(/ 0d0
0d0
) 0d0
)
2912 (test-comparison < double-float
0d0
(/ 0d0
0d0
))
2914 (test-comparison > t
1 0)
2915 (test-comparison > t
0 1)
2916 (test-comparison > t
1 1)
2917 (test-comparison > t
(1+ most-positive-fixnum
) (+ 2 most-positive-fixnum
))
2918 (test-comparison > t
(+ 2 most-positive-fixnum
) (1+ most-positive-fixnum
))
2919 (test-comparison > fixnum
1 0)
2920 (test-comparison > fixnum
0 1)
2921 (test-comparison > fixnum
0 0)
2922 (test-comparison > (unsigned-byte #.sb-vm
:n-word-bits
) 1 0)
2923 (test-comparison > (unsigned-byte #.sb-vm
:n-word-bits
) 0 1)
2924 (test-comparison > (unsigned-byte #.sb-vm
:n-word-bits
) 0 0)
2925 (test-comparison > (signed-byte #.sb-vm
:n-word-bits
) 1 0)
2926 (test-comparison > (signed-byte #.sb-vm
:n-word-bits
) 0 1)
2927 (test-comparison > (signed-byte #.sb-vm
:n-word-bits
) 1 1)
2929 (test-comparison > single-float
0.0 1.0)
2930 (test-comparison > single-float
1.0 0.0)
2931 (test-comparison > single-float
1.0 1.0)
2932 (test-comparison > single-float
(/ 1.0 0.0) (/ 1.0 0.0))
2933 (test-comparison > single-float
(/ 1.0 0.0) 1.0)
2934 (test-comparison > single-float
1.0 (/ 1.0 0.0))
2935 (test-comparison > single-float
(/ 0.0 0.0) (/ 0.0 0.0))
2936 (test-comparison > single-float
(/ 0.0 0.0) 0.0)
2938 (test-comparison > double-float
0d0
1d0
)
2939 (test-comparison > double-float
1d0
0d0
)
2940 (test-comparison > double-float
1d0
1d0
)
2941 (test-comparison > double-float
(/ 1d0
0d0
) (/ 1d0
0d0
))
2942 (test-comparison > double-float
(/ 1d0
0d0
) 1d0
)
2943 (test-comparison > double-float
1d0
(/ 1d0
0d0
))
2944 (test-comparison > double-float
(/ 0d0
0d0
) (/ 0d0
0d0
))
2945 (test-comparison > double-float
(/ 0d0
0d0
) 0d0
)
2946 (test-comparison > double-float
0d0
(/ 0d0
0d0
)))))
2948 (with-test (:name
:car-and-cdr-type-derivation-conservative
)
2949 (let ((f1 (compile nil
2951 (declare (optimize speed
))
2952 (let ((x (the (cons fixnum fixnum
) (cons 1 2))))
2953 (declare (type (cons t fixnum
) x
))
2955 (+ (car x
) (cdr x
))))))
2958 (declare (optimize speed
))
2959 (let ((x (the (cons fixnum fixnum
) (cons 1 2))))
2961 (+ (car x
) (cdr x
)))))))
2962 (flet ((test-error (e value
)
2963 (assert (typep e
'type-error
))
2964 (assert (eq 'number
(type-error-expected-type e
)))
2965 (assert (eq value
(type-error-datum e
)))))
2968 (multiple-value-bind (res err
) (ignore-errors (funcall f1 v1
))
2970 (test-error err v1
))
2971 (multiple-value-bind (res err
) (ignore-errors (funcall f2 v2
))
2973 (test-error err v2
))))))
2975 (with-test (:name
:array-dimension-derivation-conservative
)
2976 (let ((f (compile nil
2978 (declare (optimize speed
))
2979 (declare (type (array * (4 4)) x
))
2981 (setq x
(make-array '(4 4)))
2982 (adjust-array y
'(3 5))
2983 (array-dimension y
0))))))
2984 (assert (= 3 (funcall f
(make-array '(4 4) :adjustable t
))))))
2986 (with-test (:name
:with-timeout-code-deletion-note
)
2987 (handler-bind ((sb-ext:code-deletion-note
#'error
))
2988 (compile nil
`(lambda ()
2989 (sb-ext:with-timeout
0
2992 (with-test (:name
:full-warning-for-undefined-type-in-cl
)
2995 (compile nil
`(lambda (x) (the replace x
)))
3001 (with-test (:name
:single-warning-for-single-undefined-type
)
3003 (handler-bind ((warning (lambda (c)
3004 (declare (ignore c
))
3006 (compile nil
`(lambda (x) (the #:no-type x
)))
3008 (compile nil
`(lambda (x) (the 'fixnum x
)))
3011 (with-test (:name
:complex-subtype-dumping-in-xc
)
3013 (= sb-vm
:complex-single-float-widetag
3014 (sb-kernel:widetag-of
3015 (sb-vm:saetp-initial-element-default
(sb-c::find-saetp
'(complex single-float
))))))
3017 (= sb-vm
:complex-double-float-widetag
3018 (sb-kernel:widetag-of
3019 (sb-vm:saetp-initial-element-default
(sb-c::find-saetp
'(complex double-float
)))))))
3021 (with-test (:name
:complex-single-float-fill
)
3022 (assert (every (lambda (x) (= #c
(1.0
2.0) x
))
3026 (make-array (list n
)
3027 :element-type
'(complex single-float
)
3028 :initial-element x
)))
3032 (with-test (:name
:regression-1.0
.28.21)
3033 (let ((fun (compile nil
`(lambda (x) (typep x
'(simple-array * 1))))))
3034 (assert (funcall fun
(vector 1 2 3)))
3035 (assert (funcall fun
"abc"))
3036 (assert (not (funcall fun
(make-array '(2 2)))))))
3038 (with-test (:name
:no-silly-compiler-notes-from-character-function
)
3040 (handler-bind ((compiler-note (lambda (e) (error "~S: ~A" current e
))))
3041 (dolist (name '(char-code char-int character char-name standard-char-p
3042 graphic-char-p alpha-char-p upper-case-p lower-case-p
3043 both-case-p digit-char-p alphanumericp digit-char-p
))
3045 (compile nil
`(lambda (x)
3046 (declare (character x
) (optimize speed
))
3048 (dolist (name '(char= char
/= char
< char
> char
<= char
>=
3049 char-lessp char-greaterp char-not-greaterp
3052 (compile nil
`(lambda (x y
)
3053 (declare (character x y
) (optimize speed
))
3056 ;;; optimizing make-array
3057 (with-test (:name
(make-array :open-code-initial-contents
))
3058 (assert (not (ctu:find-named-callees
3061 (make-array '(3) :initial-contents
(list x y z
)))))))
3062 (assert (not (ctu:find-named-callees
3065 (make-array '3 :initial-contents
(vector x y z
)))))))
3066 (assert (not (ctu:find-named-callees
3069 (make-array '3 :initial-contents
`(,x
,y
,z
))))))))
3071 ;;; optimizing array-in-bounds-p
3072 (with-test (:name
:optimize-array-in-bounds-p
)
3074 (macrolet ((find-callees (&body body
)
3075 `(ctu:find-named-callees
3079 :name
'array-in-bounds-p
))
3080 (must-optimize (&body exprs
)
3082 ,@(loop for expr in exprs
3083 collect
`(assert (not (find-callees
3085 (must-not-optimize (&body exprs
)
3087 ,@(loop for expr in exprs
3088 collect
`(assert (find-callees
3092 (let ((a (make-array '(1))))
3093 (array-in-bounds-p a
0))
3094 ;; exceeds upper bound (constant)
3095 (let ((a (make-array '(1))))
3096 (array-in-bounds-p a
1))
3097 ;; exceeds upper bound (interval)
3098 (let ((a (make-array '(1))))
3099 (array-in-bounds-p a
(+ 1 (random 2))))
3100 ;; negative lower bound (constant)
3101 (let ((a (make-array '(1))))
3102 (array-in-bounds-p a -
1))
3103 ;; negative lower bound (interval)
3104 (let ((a (make-array 3))
3105 (i (- (random 1) 20)))
3106 (array-in-bounds-p a i
))
3107 ;; multiple known dimensions
3108 (let ((a (make-array '(1 1))))
3109 (array-in-bounds-p a
0 0))
3111 (let ((s (the (simple-string 10) (eval "0123456789"))))
3112 (array-in-bounds-p s
9)))
3114 ;; don't trust non-simple array length in safety=1
3115 (let ((a (the (array * (10)) (make-array 10 :adjustable t
))))
3116 (eval `(adjust-array ,a
0))
3117 (array-in-bounds-p a
9))
3118 ;; same for a union type
3119 (let ((s (the (string 10) (make-array 10
3120 :element-type
'character
3122 (eval `(adjust-array ,s
0))
3123 (array-in-bounds-p s
9))
3124 ;; single unknown dimension
3125 (let ((a (make-array (random 20))))
3126 (array-in-bounds-p a
10))
3127 ;; multiple unknown dimensions
3128 (let ((a (make-array (list (random 20) (random 5)))))
3129 (array-in-bounds-p a
5 2))
3130 ;; some other known dimensions
3131 (let ((a (make-array (list 1 (random 5)))))
3132 (array-in-bounds-p a
0 2))
3133 ;; subscript might be negative
3134 (let ((a (make-array 5)))
3135 (array-in-bounds-p a
(- (random 3) 2)))
3136 ;; subscript might be too large
3137 (let ((a (make-array 5)))
3138 (array-in-bounds-p a
(random 6)))
3139 ;; unknown upper bound
3140 (let ((a (make-array 5)))
3141 (array-in-bounds-p a
(get-universal-time)))
3142 ;; unknown lower bound
3143 (let ((a (make-array 5)))
3144 (array-in-bounds-p a
(- (get-universal-time))))
3145 ;; in theory we should be able to optimize
3146 ;; the following but the current implementation
3147 ;; doesn't cut it because the array type's
3148 ;; dimensions get reported as (* *).
3149 (let ((a (make-array (list (random 20) 1))))
3150 (array-in-bounds-p a
5 2))))))
3152 ;;; optimizing (EXPT -1 INTEGER)
3153 (with-test (:name
(expt -
1 integer
))
3154 (dolist (x '(-1 -
1.0 -
1.0d0
))
3155 (let ((fun (compile nil
`(lambda (x) (expt ,x
(the fixnum x
))))))
3156 (assert (not (ctu:find-named-callees fun
)))
3159 (assert (eql x
(funcall fun i
)))
3160 (assert (eql (- x
) (funcall fun i
))))))))
3162 (with-test (:name
:float-division-using-exact-reciprocal
)
3163 (flet ((test (lambda-form arg res
&key
(check-insts t
))
3164 (let* ((fun (compile nil lambda-form
))
3165 (disassembly (with-output-to-string (s)
3166 (disassemble fun
:stream s
))))
3167 ;; Let's make sure there is no division at runtime: for x86 and
3168 ;; x86-64 that implies an FDIV, DIVSS, or DIVSD instruction, so
3169 ;; look for DIV in the disassembly. It's a terrible KLUDGE, but
3173 (assert (not (search "DIV" disassembly
))))
3174 ;; No generic arithmetic!
3175 (assert (not (search "GENERIC" disassembly
)))
3176 (assert (eql res
(funcall fun arg
))))))
3177 (dolist (c '(128 64 32 16 8 4 2 1 1/2 1/4 1/8 1/16 1/32 1/64))
3178 (dolist (type '(single-float double-float
))
3179 (let* ((cf (coerce c type
))
3180 (arg (- (random (* 2 cf
)) cf
))
3181 (r1 (eval `(/ ,arg
,cf
)))
3182 (r2 (eval `(/ ,arg
,(- cf
)))))
3183 (test `(lambda (x) (declare (,type x
)) (/ x
,cf
)) arg r1
)
3184 (test `(lambda (x) (declare (,type x
)) (/ x
,(- cf
))) arg r2
)
3185 ;; rational args should get optimized as well
3186 (test `(lambda (x) (declare (,type x
)) (/ x
,c
)) arg r1
)
3187 (test `(lambda (x) (declare (,type x
)) (/ x
,(- c
))) arg r2
))))
3188 ;; Also check that inexact reciprocals (1) are not used by default (2) are
3189 ;; used with FLOAT-ACCURACY=0.
3190 (dolist (type '(single-float double-float
))
3191 (let ((trey (coerce 3 type
))
3192 (one (coerce 1 type
)))
3193 (test `(lambda (x) (declare (,type x
)) (/ x
3)) trey one
3197 (optimize (sb-c::float-accuracy
0)))
3199 trey
(eval `(* ,trey
(/ ,trey
))))))))
3201 (with-test (:name
:float-multiplication-by-one
)
3202 (flet ((test (lambda-form arg
&optional
(result arg
))
3203 (let* ((fun1 (compile nil lambda-form
))
3204 (fun2 (funcall (compile nil
`(lambda ()
3205 (declare (optimize (sb-c::float-accuracy
0)))
3207 (disassembly1 (with-output-to-string (s)
3208 (disassemble fun1
:stream s
)))
3209 (disassembly2 (with-output-to-string (s)
3210 (disassemble fun2
:stream s
))))
3211 ;; Multiplication at runtime should be eliminated only with
3212 ;; FLOAT-ACCURACY=0. (To catch SNaNs.)
3214 (assert (and (search "MUL" disassembly1
)
3215 (not (search "MUL" disassembly2
))))
3216 ;; Not generic arithmetic, please!
3217 (assert (and (not (search "GENERIC" disassembly1
))
3218 (not (search "GENERIC" disassembly2
))))
3219 (assert (eql result
(funcall fun1 arg
)))
3220 (assert (eql result
(funcall fun2 arg
))))))
3221 (dolist (type '(single-float double-float
))
3222 (let* ((one (coerce 1 type
))
3223 (arg (random (* 2 one
)))
3225 (test `(lambda (x) (declare (,type x
)) (* x
1)) arg
)
3226 (test `(lambda (x) (declare (,type x
)) (* x -
1)) arg -r
)
3227 (test `(lambda (x) (declare (,type x
)) (* x
,one
)) arg
)
3228 (test `(lambda (x) (declare (,type x
)) (* x
,(- one
))) arg -r
)))))
3230 (with-test (:name
:float-addition-of-zero
)
3231 (flet ((test (lambda-form arg
&optional
(result arg
))
3232 (let* ((fun1 (compile nil lambda-form
))
3233 (fun2 (funcall (compile nil
`(lambda ()
3234 (declare (optimize (sb-c::float-accuracy
0)))
3236 (disassembly1 (with-output-to-string (s)
3237 (disassemble fun1
:stream s
)))
3238 (disassembly2 (with-output-to-string (s)
3239 (disassemble fun2
:stream s
))))
3240 ;; Let's make sure there is no addition at runtime: for x86 and
3241 ;; x86-64 that implies an FADD, ADDSS, or ADDSD instruction, so
3242 ;; look for the ADDs in the disassembly. It's a terrible KLUDGE,
3243 ;; but it works. Unless FLOAT-ACCURACY is zero, we leave the
3244 ;; addition in to catch SNaNs.
3246 (assert (and (search "FADD" disassembly1
)
3247 (not (search "FADD" disassembly2
))))
3249 (let ((inst (if (typep result
'double-float
)
3251 (assert (and (search inst disassembly1
)
3252 (not (search inst disassembly2
)))))
3253 (assert (eql result
(funcall fun1 arg
)))
3254 (assert (eql result
(funcall fun2 arg
))))))
3255 (test `(lambda (x) (declare (single-float x
)) (+ x
0)) 123.45)
3256 (test `(lambda (x) (declare (single-float x
)) (+ x
0.0)) 543.21)
3257 (test `(lambda (x) (declare (single-float x
)) (+ x
0.0d0
)) 42.00 42.d0
)
3258 (test `(lambda (x) (declare (double-float x
)) (+ x
0)) 123.45d0
)
3259 (test `(lambda (x) (declare (double-float x
)) (+ x
0.0)) 543.21d0
)
3260 (test `(lambda (x) (declare (double-float x
)) (+ x
0.0d0
)) 42.d0
)))
3262 (with-test (:name
:float-substraction-of-zero
)
3263 (flet ((test (lambda-form arg
&optional
(result arg
))
3264 (let* ((fun1 (compile nil lambda-form
))
3265 (fun2 (funcall (compile nil
`(lambda ()
3266 (declare (optimize (sb-c::float-accuracy
0)))
3268 (disassembly1 (with-output-to-string (s)
3269 (disassemble fun1
:stream s
)))
3270 (disassembly2 (with-output-to-string (s)
3271 (disassemble fun2
:stream s
))))
3272 ;; Let's make sure there is no substraction at runtime: for x86
3273 ;; and x86-64 that implies an FSUB, SUBSS, or SUBSD instruction,
3274 ;; so look for SUB in the disassembly. It's a terrible KLUDGE,
3275 ;; but it works. Unless FLOAT-ACCURACY is zero, we leave the
3276 ;; substraction in in to catch SNaNs.
3278 (assert (and (search "FSUB" disassembly1
)
3279 (not (search "FSUB" disassembly2
))))
3281 (let ((inst (if (typep result
'double-float
)
3283 (assert (and (search inst disassembly1
)
3284 (not (search inst disassembly2
)))))
3285 (assert (eql result
(funcall fun1 arg
)))
3286 (assert (eql result
(funcall fun2 arg
))))))
3287 (test `(lambda (x) (declare (single-float x
)) (- x
0)) 123.45)
3288 (test `(lambda (x) (declare (single-float x
)) (- x
0.0)) 543.21)
3289 (test `(lambda (x) (declare (single-float x
)) (- x
0.0d0
)) 42.00 42.d0
)
3290 (test `(lambda (x) (declare (double-float x
)) (- x
0)) 123.45d0
)
3291 (test `(lambda (x) (declare (double-float x
)) (- x
0.0)) 543.21d0
)
3292 (test `(lambda (x) (declare (double-float x
)) (- x
0.0d0
)) 42.d0
)))
3294 (with-test (:name
:float-multiplication-by-two
)
3295 (flet ((test (lambda-form arg
&optional
(result arg
))
3296 (let* ((fun1 (compile nil lambda-form
))
3297 (fun2 (funcall (compile nil
`(lambda ()
3298 (declare (optimize (sb-c::float-accuracy
0)))
3300 (disassembly1 (with-output-to-string (s)
3301 (disassemble fun1
:stream s
)))
3302 (disassembly2 (with-output-to-string (s)
3303 (disassemble fun2
:stream s
))))
3304 ;; Let's make sure there is no multiplication at runtime: for x86
3305 ;; and x86-64 that implies an FMUL, MULSS, or MULSD instruction,
3306 ;; so look for MUL in the disassembly. It's a terrible KLUDGE,
3309 (assert (and (not (search "MUL" disassembly1
))
3310 (not (search "MUL" disassembly2
))))
3311 (assert (eql result
(funcall fun1 arg
)))
3312 (assert (eql result
(funcall fun2 arg
))))))
3313 (test `(lambda (x) (declare (single-float x
)) (* x
2)) 123.45 246.9)
3314 (test `(lambda (x) (declare (single-float x
)) (* x
2.0)) 543.21 1086.42)
3315 (test `(lambda (x) (declare (single-float x
)) (* x
2.0d0
)) 42.00 84.d0
)
3316 (test `(lambda (x) (declare (double-float x
)) (* x
2)) 123.45d0
246.9d0
)
3317 (test `(lambda (x) (declare (double-float x
)) (* x
2.0)) 543.21d0
1086.42d0
)
3318 (test `(lambda (x) (declare (double-float x
)) (* x
2.0d0
)) 42.0d0
84.0d0
)))
3320 (with-test (:name
:bug-392203
)
3321 ;; Used to hit an AVER in COMVERT-MV-CALL.
3326 (flet ((k (&rest x
) (declare (ignore x
)) 0))
3327 (multiple-value-call #'k
#'k
))))))))
3329 (with-test (:name
:allocate-closures-failing-aver
)
3330 (let ((f (compile nil
`(lambda ()
3331 (labels ((k (&optional x
) #'k
)))))))
3332 (assert (null (funcall f
)))))
3334 (with-test (:name
:flush-vector-creation
)
3335 (let ((f (compile nil
`(lambda ()
3339 (ctu:assert-no-consing
(funcall f
))))
3341 (with-test (:name
:array-type-predicates
)
3342 (dolist (et (list* '(integer -
1 200) '(integer -
256 1)
3345 '(double-float 0d0
(1d0))
3346 '(single-float (0s0) (1s0))
3347 '(or (eql 1d0
) (eql 10d0
))
3349 '(complex (member 10 20))
3350 '(complex (member 10d0
20d0
))
3351 '(complex (member 10s0
20s0
))
3352 '(or integer double-float
)
3356 #+sb-unicode
'extended-char
3357 #+sb-unicode
'(eql #\cyrillic_small_letter_yu
)
3358 sb-kernel
::*specialized-array-element-types
*))
3360 (let* ((v (make-array 3 :element-type et
))
3361 (fun (compile nil
`(lambda ()
3363 (if (typep ,v
'(simple-array ,et
(*)))
3366 (if (typep (elt ,v
0) '(simple-array ,et
(*)))
3369 (assert (equal '(:good
:good
) (funcall fun
)))))))
3371 (with-test (:name
:truncate-float
)
3372 (let ((s (compile nil
`(lambda (x)
3373 (declare (single-float x
))
3375 (d (compile nil
`(lambda (x)
3376 (declare (double-float x
))
3378 (s-inlined (compile nil
'(lambda (x)
3379 (declare (type (single-float 0.0s0
1.0s0
) x
))
3381 (d-inlined (compile nil
'(lambda (x)
3382 (declare (type (double-float 0.0d0
1.0d0
) x
))
3384 ;; Check that there is no generic arithmetic
3385 (assert (not (search "GENERIC"
3386 (with-output-to-string (out)
3387 (disassemble s
:stream out
)))))
3388 (assert (not (search "GENERIC"
3389 (with-output-to-string (out)
3390 (disassemble d
:stream out
)))))
3391 ;; Check that we actually inlined the call when we were supposed to.
3392 (assert (not (search "UNARY-TRUNCATE"
3393 (with-output-to-string (out)
3394 (disassemble s-inlined
:stream out
)))))
3395 (assert (not (search "UNARY-TRUNCATE"
3396 (with-output-to-string (out)
3397 (disassemble d-inlined
:stream out
)))))))
3399 (with-test (:name
:make-array-unnamed-dimension-leaf
)
3400 (let ((fun (compile nil
`(lambda (stuff)
3401 (make-array (map 'list
'length stuff
))))))
3402 (assert (equalp #2A
((0 0 0) (0 0 0))
3403 (funcall fun
'((1 2) (1 2 3)))))))
3405 (with-test (:name
:fp-decoding-funs-not-flushable-in-safe-code
)
3406 (dolist (name '(float-sign float-radix float-digits float-precision decode-float
3407 integer-decode-float
))
3408 (let ((fun (compile nil
`(lambda (x)
3409 (declare (optimize safety
))
3417 (error "(~S ~S) did not error"
3423 (when (member name
'(decode-float integer-decode-float
))
3424 (test sb-ext
:single-float-positive-infinity
))))))
3426 (with-test (:name
:sap-ref-16
)
3427 (let* ((fun (compile nil
`(lambda (x y
)
3428 (declare (type sb-sys
:system-area-pointer x
)
3429 (type (integer 0 100) y
))
3430 (sb-sys:sap-ref-16 x
(+ 4 y
)))))
3431 (vector (coerce '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
3432 '(simple-array (unsigned-byte 8) (*))))
3433 (sap (sb-sys:vector-sap vector
))
3434 (ret (funcall fun sap
0)))
3435 ;; test for either endianness
3436 (assert (or (= ret
(+ (* 5 256) 4)) (= ret
(+ (* 4 256) 5))))))
3438 (with-test (:name
:coerce-type-warning
)
3439 (dolist (type '(t (unsigned-byte 8) (unsigned-byte 16) (unsigned-byte 32)
3440 (signed-byte 8) (signed-byte 16) (signed-byte 32)))
3441 (multiple-value-bind (fun warningsp failurep
)
3442 (compile nil
`(lambda (x)
3443 (declare (type simple-vector x
))
3444 (coerce x
'(vector ,type
))))
3445 (assert (null warningsp
))
3446 (assert (null failurep
))
3447 (assert (typep (funcall fun
#(1)) `(simple-array ,type
(*)))))))
3449 (with-test (:name
:truncate-double-float
)
3450 (let ((fun (compile nil
`(lambda (x)
3451 (multiple-value-bind (q r
)
3452 (truncate (coerce x
'double-float
))
3453 (declare (type unsigned-byte q
)
3454 (type double-float r
))
3456 (assert (equal (funcall fun
1.0d0
) '(1 0.0d0
)))))
3458 (with-test (:name
:set-slot-value-no-warning
)
3460 (handler-bind ((warning #'error
)
3461 (sb-ext:compiler-note
(lambda (c)
3462 (declare (ignore c
))
3464 (compile nil
`(lambda (x y
)
3465 (declare (optimize speed safety
))
3466 (setf (slot-value x
'bar
) y
))))
3467 (assert (= 1 notes
))))
3469 (with-test (:name
:concatenate-string-opt
)
3470 (flet ((test (type grep
)
3471 (let* ((fun (compile nil
`(lambda (a b c d e
)
3472 (concatenate ',type a b c d e
))))
3473 (args '("foo" #(#\.
) "bar" (#\-
) "quux"))
3474 (res (apply fun args
)))
3475 (assert (search grep
(with-output-to-string (out)
3476 (disassemble fun
:stream out
))))
3477 (assert (equal (apply #'concatenate type args
)
3479 (assert (typep res type
)))))
3480 (test 'string
"%CONCATENATE-TO-STRING")
3481 (test 'simple-string
"%CONCATENATE-TO-STRING")
3482 (test 'base-string
"%CONCATENATE-TO-BASE-STRING")
3483 (test 'simple-base-string
"%CONCATENATE-TO-BASE-STRING")))
3485 (with-test (:name
:satisfies-no-local-fun
)
3486 (let ((fun (compile nil
`(lambda (arg)
3487 (labels ((local-not-global-bug (x)
3490 (typep x
'(satisfies local-not-global-bug
))))
3492 (assert (eq 'local-not-global-bug
3495 (undefined-function (c)
3496 (cell-error-name c
)))))))
3498 ;;; Prior to 1.0.32.x, dumping a fasl with a function with a default
3499 ;;; argument that is a complex structure (needing make-load-form
3500 ;;; processing) failed an AVER. The first attempt at a fix caused
3501 ;;; doing the same in-core to break.
3502 (with-test (:name
:bug-310132
)
3503 (compile nil
'(lambda (&optional
(foo #p
"foo/bar")))))
3505 (with-test (:name
:bug-309129
)
3506 (let* ((src '(lambda (v) (values (svref v
0) (vector-pop v
))))
3508 (fun (handler-bind ((warning (lambda (c)
3509 (setf warningp t
) (muffle-warning c
))))
3510 (compile nil src
))))
3512 (handler-case (funcall fun
#(1))
3514 ;; we used to put simply VECTOR into EXPECTED-TYPE, rather
3515 ;; than explicitly (AND VECTOR (NOT SIMPLE-ARRAY))
3516 (assert (not (typep (type-error-datum c
) (type-error-expected-type c
)))))
3517 (:no-error
(&rest values
)
3518 (declare (ignore values
))
3519 (error "no error")))))
3521 (with-test (:name
:unary-round-type-derivation
)
3522 (let* ((src '(lambda (zone)
3523 (multiple-value-bind (h m
) (truncate (abs zone
) 1.0)
3524 (declare (ignore h
))
3525 (round (* 60.0 m
)))))
3526 (fun (compile nil src
)))
3527 (assert (= (funcall fun
0.5) 30))))
3529 (with-test (:name
:bug-525949
)
3530 (let* ((src '(lambda ()
3531 (labels ((always-one () 1)
3533 (let ((n (funcall z
)))
3534 (declare (fixnum n
))
3535 (the double-float
(expt n
1.0d0
)))))
3538 (fun (handler-bind ((warning (lambda (c)
3539 (setf warningp t
) (muffle-warning c
))))
3540 (compile nil src
))))
3541 (assert (not warningp
))
3542 (assert (= 1.0d0
(funcall fun
)))))
3544 (with-test (:name
:%array-data-vector-type-derivation
)
3545 (let* ((f (compile nil
3547 (declare (type (simple-array (unsigned-byte 32) (3 3)) ary
))
3548 (setf (aref ary
0 0) 0))))
3549 (text (with-output-to-string (s)
3550 (disassemble f
:stream s
))))
3551 (assert (not (search "OBJECT-NOT-SIMPLE-ARRAY-UNSIGNED-BYTE-32-ERROR" text
)))))
3553 (with-test (:name
:array-storage-vector-type-derivation
)
3554 (let ((f (compile nil
3556 (declare (type (simple-array (unsigned-byte 32) (3 3)) ary
))
3557 (ctu:compiler-derived-type
(array-storage-vector ary
))))))
3558 (assert (equal '(simple-array (unsigned-byte 32) (9))
3559 (funcall f
(make-array '(3 3) :element-type
'(unsigned-byte 32)))))))
3561 (with-test (:name
:bug-523612
)
3564 `(lambda (&key toff
)
3565 (make-array 3 :element-type
'double-float
3567 (if toff
(list toff
0d0
0d0
) (list 0d0
0d0
0d0
)))))))
3568 (assert (equalp (vector 0.0d0
0.0d0
0.0d0
) (funcall fun
:toff nil
)))
3569 (assert (equalp (vector 2.3d0
0.0d0
0.0d0
) (funcall fun
:toff
2.3d0
)))))
3571 (with-test (:name
:bug-309788
)
3575 (declare (optimize speed
))
3577 (typep x
'fixnum env
))))))
3578 (assert (not (ctu:find-named-callees fun
)))))
3580 (with-test (:name
:bug-309124
)
3584 (declare (integer x
))
3585 (declare (optimize speed
))
3586 (cond ((typep x
'fixnum
)
3594 (assert (equal (list "hala" "hip")
3595 (sort (ctu:find-code-constants fun
:type
'string
)
3598 (with-test (:name
:bug-316078
)
3602 (declare (type (and simple-bit-vector
(satisfies bar
)) x
)
3605 (assert (not (ctu:find-named-callees fun
)))
3606 (assert (= 1 (funcall fun
#*000001)))
3607 (assert (= 0 (funcall fun
#*000010)))))
3609 (with-test (:name
:mult-by-one-in-float-acc-zero
)
3610 (assert (eql 1.0 (funcall (compile nil
`(lambda (x)
3611 (declare (optimize (sb-c::float-accuracy
0)))
3614 (assert (eql -
1.0 (funcall (compile nil
`(lambda (x)
3615 (declare (optimize (sb-c::float-accuracy
0)))
3618 (assert (eql 1.0d0
(funcall (compile nil
`(lambda (x)
3619 (declare (optimize (sb-c::float-accuracy
0)))
3622 (assert (eql -
1.0d0
(funcall (compile nil
`(lambda (x)
3623 (declare (optimize (sb-c::float-accuracy
0)))
3627 (with-test (:name
:dotimes-non-integer-counter-value
)
3628 (assert-error (dotimes (i 8.6)) type-error
))
3630 (with-test (:name
:bug-454681
)
3631 ;; This used to break due to reference to a dead lambda-var during
3632 ;; inline expansion.
3633 (assert (compile nil
3635 (multiple-value-bind (iterator+977 getter
+978)
3636 (does-not-exist-but-does-not-matter)
3637 (flet ((iterator+976 ()
3638 (funcall iterator
+977)))
3639 (declare (inline iterator
+976))
3640 (let ((iterator+976 #'iterator
+976))
3641 (funcall iterator
+976))))))))
3643 (with-test (:name
:complex-float-local-fun-args
)
3644 ;; As of 1.0.27.14, the lambda below failed to compile due to the
3645 ;; compiler attempting to pass unboxed complex floats to Z and the
3646 ;; MOVE-ARG method not expecting the register being used as a
3647 ;; temporary frame pointer. Reported by sykopomp in #lispgames,
3648 ;; reduced test case provided by _3b`.
3649 (compile nil
'(lambda (a)
3651 (declare ((complex double-float
) b c
))
3653 (loop for i below
10 do
3654 (setf a
(z a a
)))))))
3656 (with-test (:name
:bug-309130
)
3657 (assert (eq :warning
3659 (compile nil
`(lambda () (svref (make-array 8 :adjustable t
) 1)))
3660 ((and warning
(not style-warning
)) ()
3662 (assert (eq :warning
3664 (compile nil
`(lambda (x)
3665 (declare (optimize (debug 0)))
3666 (declare (type vector x
))
3667 (list (fill-pointer x
) (svref x
1))))
3668 ((and warning
(not style-warning
)) ()
3670 (assert (eq :warning
3672 (compile nil
`(lambda (x)
3673 (list (vector-push (svref x
0) x
))))
3674 ((and warning
(not style-warning
)) ()
3676 (assert (eq :warning
3678 (compile nil
`(lambda (x)
3679 (list (vector-push-extend (svref x
0) x
))))
3680 ((and warning
(not style-warning
)) ()
3683 (with-test (:name
:bug-646796
)
3688 (load-time-value (the (values fixnum
) 42)))))))
3690 (with-test (:name
:bug-654289
)
3691 ;; Test that compile-times don't explode when quoted constants
3693 (labels ((time-n (n)
3694 (gc :full t
) ; Let's not confuse the issue with GC
3695 (let* ((tree (make-tree (expt 10 n
) nil
))
3696 (t0 (get-internal-run-time))
3697 (f (compile nil
`(lambda (x) (eq x
(quote ,tree
)))))
3698 (t1 (get-internal-run-time)))
3699 (assert (funcall f tree
))
3702 (cond ((zerop n
) acc
)
3703 (t (make-tree (1- n
) (cons acc acc
))))))
3704 (let* ((times (loop for i from
0 upto
4
3705 collect
(time-n i
)))
3706 (max-small (reduce #'max times
:end
3))
3707 (max-big (reduce #'max times
:start
3)))
3708 ;; This way is hopefully fairly CPU-performance insensitive.
3709 (unless (> (+ (truncate internal-time-units-per-second
10)
3712 (error "Bad scaling or test? ~S" times
)))))
3714 (with-test (:name
:bug-309063
)
3715 (let ((fun (compile nil
`(lambda (x)
3716 (declare (type (integer 0 0) x
))
3718 (assert (zerop (funcall fun
0)))))
3720 (with-test (:name
:bug-655872
)
3721 (let ((f (compile nil
`(lambda (x)
3722 (declare (optimize (safety 3)))
3723 (aref (locally (declare (optimize (safety 0)))
3724 (coerce x
'(simple-vector 128)))
3726 (long (make-array 100 :element-type
'fixnum
)))
3728 (setf (aref long i
) i
))
3729 ;; 1. COERCE doesn't check the length in unsafe code.
3730 (assert (eql 60 (funcall f long
)))
3731 ;; 2. The compiler doesn't trust the length from COERCE
3734 (funcall f
(list 1 2 3))
3735 (sb-int:invalid-array-index-error
(e)
3736 (assert (eql 60 (type-error-datum e
)))
3737 (assert (equal '(integer 0 (3)) (type-error-expected-type e
)))
3740 (with-test (:name
:bug-655203-regression
)
3741 (let ((fun (compile nil
3745 (&OPTIONAL DUMMY
&REST OTHER
)
3746 (DECLARE (IGNORE OTHER
))
3749 (FUNCALL CONTINUATION
(LIST 1 2)))))))
3750 ;; This used to signal a bogus type-error.
3751 (assert (equal (with-output-to-string (*standard-output
*)
3755 (with-test (:name
:constant-concatenate-compile-time
)
3756 (flet ((make-lambda (n)
3758 (declare (optimize (speed 3) (space 0)))
3759 (concatenate 'string x
,(make-string n
)))))
3760 (let* ((l0 (make-lambda 1))
3761 (l1 (make-lambda 10))
3762 (l2 (make-lambda 100))
3763 (l3 (make-lambda 1000))
3764 (t0 (get-internal-run-time))
3765 (f0 (compile nil l0
))
3766 (t1 (get-internal-run-time))
3767 (f1 (compile nil l1
))
3768 (t2 (get-internal-run-time))
3769 (f2 (compile nil l2
))
3770 (t3 (get-internal-run-time))
3771 (f3 (compile nil l3
))
3772 (t4 (get-internal-run-time))
3777 (short-avg (/ (+ d0 d1 d2
) 3)))
3778 (assert (and f1 f2 f3
))
3779 (assert (< d3
(* 10 short-avg
))))))
3781 (with-test (:name
:bug-384892
)
3783 ;; The assertion that BOOLEAN becomes (MEMBER T NIL)
3784 ;; is slightly brittle, but the rest of the
3786 '(function (fixnum fixnum
&key
(:k1
(member t nil
)))
3787 (values (member t
) &optional
))
3788 (sb-kernel:%simple-fun-type
3789 (compile nil
`(lambda (x y
&key k1
)
3790 (declare (fixnum x y
))
3791 (declare (boolean k1
))
3792 (declare (ignore x y k1
))
3795 (with-test (:name
:bug-309448
)
3796 ;; Like all tests trying to verify that something doesn't blow up
3797 ;; compile-times this is bound to be a bit brittle, but at least
3798 ;; here we try to establish a decent baseline.
3799 (labels ((time-it (lambda want
&optional times
)
3800 (gc :full t
) ; let's keep GCs coming from other code out...
3801 (let* ((start (get-internal-run-time))
3805 for result
= (compile nil lambda
)
3806 finally
(return result
))
3807 (loop for result
= (compile nil lambda
)
3808 do
(incf iterations
)
3809 until
(> (get-internal-run-time) (+ start
10))
3810 finally
(return result
))))
3811 (end (get-internal-run-time))
3812 (got (funcall fun
)))
3813 (unless (eql want got
)
3814 (error "wanted ~S, got ~S" want got
))
3815 (values (- end start
) iterations
)))
3816 (test-it (simple result1 complex result2
)
3817 (multiple-value-bind (time-simple iterations
)
3818 (time-it simple result1
)
3819 (assert (>= (* 10 (1+ time-simple
))
3820 (time-it complex result2 iterations
))))))
3821 ;; This is mostly identical as the next one, but doesn't create
3822 ;; hairy unions of numeric types.
3823 (test-it `(lambda ()
3824 (labels ((bar (baz bim
)
3825 (let ((n (+ baz bim
)))
3826 (* n
(+ n
1) bim
))))
3833 (labels ((bar (baz bim
)
3834 (let ((n (+ baz bim
)))
3835 (* n
(+ n
1) bim
))))
3841 (test-it `(lambda ()
3843 (let ((m (truncate 999 n
)))
3844 (/ (* n m
(1+ m
)) 2))))
3851 (let ((m (truncate 999 n
)))
3852 (/ (* n m
(1+ m
)) 2))))
3858 (with-test (:name
:regression-1.0
.44.34)
3859 (compile nil
'(lambda (z &rest args
)
3860 (declare (dynamic-extent args
))
3861 (flet ((foo (w v
) (list v w
)))
3865 (declare (sb-int:truly-dynamic-extent
#'foo
))
3866 (call #'foo nil
))))))
3868 (with-test (:name
:bug-713626
)
3869 (let ((f (eval '(constantly 42))))
3870 (handler-bind ((warning #'error
))
3871 (assert (= 42 (funcall (compile nil
`(lambda () (funcall ,f
1 2 3)))))))))
3873 (with-test (:name
:known-fun-allows-other-keys
)
3874 (handler-bind ((warning #'error
))
3875 (funcall (compile nil
'(lambda () (directory "." :allow-other-keys t
))))
3876 (funcall (compile nil
`(lambda () (directory "." :bar t
:allow-other-keys t
))))))
3878 (with-test (:name
:bug-551227
)
3879 ;; This function causes constraint analysis to perform a
3880 ;; ref-substitution that alters the A referred to in (G A) at in the
3881 ;; consequent of the IF to refer to be NUMBER, from the
3882 ;; LET-converted inline-expansion of MOD. This leads to attempting
3883 ;; to CLOSE-OVER a variable that simply isn't in scope when it is
3885 (compile nil
'(lambda (a)
3895 (with-test (:name
:funcall-lambda-inlined
)
3897 (ctu:find-code-constants
3900 (+ x
(funcall (lambda (z) z
) y
))))
3903 (with-test (:name
:bug-720382
)
3906 (handler-bind (((and warning
(not style-warning
))
3907 (lambda (c) (incf w
))))
3908 (compile nil
`(lambda (b) ((lambda () b
) 1))))))
3911 (handler-case (funcall f
0)
3912 (error () :error
)))))))
3914 (with-test (:name
:multiple-args-to-function
)
3915 (let ((form `(flet ((foo (&optional
(x 13)) x
))
3916 (funcall (function foo
42))))
3917 #+sb-eval
(*evaluator-mode
* :interpret
))
3920 (handler-case (eval form
)
3921 (error () :error
))))
3922 (multiple-value-bind (fun warn fail
)
3923 (compile nil
`(lambda () ,form
))
3924 (assert (and warn fail
))
3926 (handler-case (funcall fun
)
3927 (error () :error
)))))))
3929 ;;; This doesn't test LVAR-FUN-IS directly, but captures it
3930 ;;; pretty accurately anyways.
3931 (with-test (:name
:lvar-fun-is
)
3933 (lambda (x) (member x x
:test
#'eq
))
3934 (lambda (x) (member x x
:test
'eq
))
3935 (lambda (x) (member x x
:test
#.
#'eq
))))
3936 (assert (equal (list #'sb-kernel
:%member-eq
)
3937 (ctu:find-named-callees fun
))))
3940 (declare (notinline eq
))
3941 (member x x
:test
#'eq
))
3943 (declare (notinline eq
))
3944 (member x x
:test
'eq
))
3946 (declare (notinline eq
))
3947 (member x x
:test
#.
#'eq
))))
3948 (assert (member #'sb-kernel
:%member-test
3949 (ctu:find-named-callees fun
)))))
3951 (with-test (:name
:delete-to-delq-opt
)
3952 (dolist (fun (list (lambda (x y
)
3954 (delete x y
:test
#'eq
))
3956 (declare (fixnum x
) (list y
))
3959 (declare (symbol x
) (list y
))
3960 (delete x y
:test
#'eql
))))
3961 (assert (equal (list #'sb-int
:delq
)
3962 (ctu:find-named-callees fun
)))))
3964 (with-test (:name
:bug-767959
)
3965 ;; This used to signal an error.
3966 (compile nil
`(lambda ()
3967 (declare (optimize sb-c
:store-coverage-data
))
3970 '((:ordinary . ordinary-lambda-list
))))))
3972 ;; This test failed formerly because the source transform of TYPEP would be
3973 ;; disabled when storing coverage data, thus giving no semantics to
3974 ;; expressions such as (TYPEP x 'INTEGER). The compiler could therefore not
3975 ;; prove that the else clause of the IF is unreachable - which it must be
3976 ;; since X is asserted to be fixnum. The conflicting requirement on X
3977 ;; that it be acceptable to LENGTH signaled a full warning.
3978 ;; Nobody on sbcl-devel could remember why the source transform was disabled,
3979 ;; but nobody disagreed with undoing the disabling.
3980 (with-test (:name
:sb-cover-and-typep
)
3981 (multiple-value-bind (fun warnings-p failure-p
)
3982 (compile nil
'(lambda (x)
3983 (declare (fixnum x
) (optimize sb-c
:store-coverage-data
))
3984 (if (typep x
'integer
) x
(length x
))))
3985 (assert (and fun
(not warnings-p
) (not failure-p
)))))
3987 (with-test (:name
:member-on-long-constant-list
)
3988 ;; This used to blow stack with a sufficiently long list.
3989 (let ((cycle (list t
)))
3991 (compile nil
`(lambda (x)
3992 (member x
',cycle
)))))
3994 (with-test (:name
:bug-722734
)
4000 (list unbound-variable-1 unbound-variable-2
)))))))
4002 (with-test (:name
:bug-771673
)
4003 (assert (equal `(the foo bar
) (macroexpand `(truly-the foo bar
))))
4004 ;; Make sure the compiler doesn't use THE, and check that setf-expansions
4006 (let ((f (compile nil
`(lambda (x y
)
4007 (setf (truly-the fixnum
(car x
)) y
)))))
4008 (let* ((cell (cons t t
)))
4009 (funcall f cell
:ok
)
4010 (assert (equal '(:ok . t
) cell
)))))
4012 (with-test (:name
(:bug-793771
+))
4013 (let ((f (compile nil
`(lambda (x y
)
4014 (declare (type (single-float 2.0) x
)
4015 (type (single-float (0.0
)) y
))
4017 (assert (equal `(function ((single-float 2.0) (single-float (0.0
)))
4018 (values (single-float 2.0) &optional
))
4019 (sb-kernel:%simple-fun-type f
)))))
4021 (with-test (:name
(:bug-793771 -
))
4022 (let ((f (compile nil
`(lambda (x y
)
4023 (declare (type (single-float * 2.0) x
)
4024 (type (single-float (0.0
)) y
))
4026 (assert (equal `(function ((single-float * 2.0) (single-float (0.0
)))
4027 (values (single-float * 2.0) &optional
))
4028 (sb-kernel:%simple-fun-type f
)))))
4030 (with-test (:name
(:bug-793771
*))
4031 (let ((f (compile nil
`(lambda (x)
4032 (declare (type (single-float (0.0
)) x
))
4034 (assert (equal `(function ((single-float (0.0
)))
4035 (values (or (member 0.0) (single-float (0.0
))) &optional
))
4036 (sb-kernel:%simple-fun-type f
)))))
4038 (with-test (:name
(:bug-793771
/))
4039 (let ((f (compile nil
`(lambda (x)
4040 (declare (type (single-float (0.0
)) x
))
4042 (assert (equal `(function ((single-float (0.0
)))
4043 (values (or (member 0.0) (single-float (0.0
))) &optional
))
4044 (sb-kernel:%simple-fun-type f
)))))
4046 (with-test (:name
(:bug-486812 single-float
))
4047 (compile nil
`(lambda ()
4048 (sb-kernel:make-single-float -
1))))
4050 (with-test (:name
(:bug-486812 double-float
))
4051 (compile nil
`(lambda ()
4052 (sb-kernel:make-double-float -
1 0))))
4054 (with-test (:name
:bug-729765
)
4055 (compile nil
`(lambda (a b
)
4056 (declare ((integer 1 1) a
)
4059 (lambda () (< b a
)))))
4061 ;; Actually tests the assembly of RIP-relative operands to comparison
4062 ;; functions (one of the few x86 instructions that have extra bytes
4063 ;; *after* the mem operand's effective address, resulting in a wrong
4065 (with-test (:name
:cmpps
)
4066 (let ((foo (compile nil
`(lambda (x)
4067 (= #C
(2.0
3.0) (the (complex single-float
) x
))))))
4068 (assert (funcall foo
#C
(2.0
3.0)))
4069 (assert (not (funcall foo
#C
(1.0
2.0))))))
4071 (with-test (:name
:cmppd
)
4072 (let ((foo (compile nil
`(lambda (x)
4073 (= #C
(2d0 3d0
) (the (complex double-float
) x
))))))
4074 (assert (funcall foo
#C
(2d0 3d0
)))
4075 (assert (not (funcall foo
#C
(1d0 2d0
))))))
4077 (with-test (:name
:lvar-externally-checkable-type-nil
)
4078 ;; Used to signal a BUG during compilation.
4079 (let ((fun (compile nil
`(lambda (a) (parse-integer "12321321" (the (member :start
) a
) 1)))))
4080 (multiple-value-bind (i p
) (funcall fun
:start
)
4081 (assert (= 2321321 i
))
4083 (multiple-value-bind (i e
) (ignore-errors (funcall fun
:end
))
4085 (assert (typep e
'type-error
)))))
4087 (with-test (:name
:simple-type-error-in-bound-propagation-a
)
4088 (compile nil
`(lambda (i)
4089 (declare (unsigned-byte i
))
4090 (expt 10 (expt 7 (- 2 i
))))))
4092 (with-test (:name
:simple-type-error-in-bound-propagation-b
)
4093 (assert (equal `(FUNCTION (UNSIGNED-BYTE)
4094 (VALUES (SINGLE-FLOAT -
1F0
1F0
) &OPTIONAL
))
4095 (sb-kernel:%simple-fun-type
4096 (compile nil
`(lambda (i)
4097 (declare (unsigned-byte i
))
4098 (cos (expt 10 (+ 4096 i
)))))))))
4100 (with-test (:name
:fixed-%more-arg-values
)
4101 (let ((fun (compile nil
`(lambda (&rest rest
)
4102 (declare (optimize (safety 0)))
4103 (apply #'cons rest
)))))
4104 (assert (equal '(car . cdr
) (funcall fun
'car
'cdr
)))))
4106 (with-test (:name
:bug-826970
)
4107 (let ((fun (compile nil
`(lambda (a b c
)
4108 (declare (type (member -
2 1) b
))
4109 (array-in-bounds-p a
4 b c
)))))
4110 (assert (funcall fun
(make-array '(5 2 2)) 1 1))))
4112 (with-test (:name
:bug-826971
)
4114 (fun (compile nil
`(lambda (p1 p2
)
4115 (schar (the (eql ,foo
) p1
) p2
)))))
4116 (assert (eql #\f (funcall fun foo
0)))))
4118 (with-test (:name
:bug-738464
)
4119 (multiple-value-bind (fun warn fail
)
4120 (compile nil
`(lambda ()
4122 (declare (ftype non-function-type foo
))
4124 (assert (eql 42 (funcall fun
)))
4125 (assert (and warn
(not fail
)))))
4127 (with-test (:name
:bug-832005
)
4128 (let ((fun (compile nil
`(lambda (x)
4129 (declare (type (complex single-float
) x
))
4130 (+ #C
(0.0
1.0) x
)))))
4131 (assert (= (funcall fun
#C
(1.0
2.0))
4134 ;; A refactoring 1.0.12.18 caused lossy computation of primitive
4135 ;; types for member types.
4136 (with-test (:name
:member-type-primitive-type
)
4137 (let ((fun (compile nil
`(lambda (p1 p2 p3
)
4139 (the (member #c
(1.2d0
1d0
)) p2
)
4140 (the (eql #c
(1.0
1.0)) p3
))))))
4141 (assert (eql (funcall fun
1 #c
(1.2d0
1d0
) #c
(1.0
1.0))
4144 ;; Fall-through jump elimination made control flow fall through to trampolines.
4145 ;; Reported by Eric Marsden on sbcl-devel@ 2011.10.26, with a test case
4146 ;; reproduced below (triggered a corruption warning and a memory fault).
4147 (with-test (:name
:bug-883500
)
4148 (funcall (compile nil
`(lambda (a)
4149 (declare (type (integer -
50 50) a
))
4150 (declare (optimize (speed 0)))
4151 (mod (mod a
(min -
5 a
)) 5)))
4154 ;; Test for literals too large for the ISA (e.g. (SIGNED-BYTE 13) on SPARC).
4156 (with-test (:name
:bug-883519
)
4157 (compile nil
`(lambda (x)
4158 (declare (type character x
))
4159 (eql x
#\U0010FFFF
))))
4161 ;; Wide fixnum platforms had buggy address computation in atomic-incf/aref
4162 (with-test (:name
:bug-887220
)
4163 (let ((incfer (compile
4165 `(lambda (vector index
)
4166 (declare (type (simple-array sb-ext
:word
(4))
4168 (type (mod 4) index
))
4169 (sb-ext:atomic-incf
(aref vector index
) 1)
4171 (assert (equalp (funcall incfer
4172 (make-array 4 :element-type
'sb-ext
:word
4177 (with-test (:name
:catch-interferes-with-debug-names
)
4183 (throw 'out
(lambda () t
))))
4185 (assert (equal '(lambda () :in foo
) (sb-kernel:%fun-name fun
)))))
4187 (with-test (:name
:interval-div-signed-zero
)
4188 (let ((fun (compile nil
4190 (declare (type (member 0 -
272413371076) a
))
4191 (ffloor (the number a
) -
63243.127451934015d0
)))))
4192 (multiple-value-bind (q r
) (funcall fun
0)
4193 (assert (eql -
0d0 q
))
4194 (assert (eql 0d0 r
)))))
4196 (with-test (:name
:non-constant-keyword-typecheck
)
4197 (let ((fun (compile nil
4199 (declare (type keyword p3
))
4200 (tree-equal p1
(cons 1 2) (the (member :test
) p3
) p4
)))))
4201 (assert (funcall fun
(cons 1.0 2.0) :test
'=))))
4203 (with-test (:name
:truncate-wild-values
)
4204 (multiple-value-bind (q r
)
4205 (handler-bind ((warning #'error
))
4206 (let ((sb-c::*check-consistency
* t
))
4207 (funcall (compile nil
4209 (declare (type (member 1d0
2d0
) a
))
4210 (block return-value-tag
4213 (catch 'debug-catch-tag
4214 (return-from return-value-tag
4215 (progn (truncate a
)))))))))
4218 (assert (eql 0d0 r
))))
4220 (with-test (:name
:boxed-fp-constant-for-full-call
)
4221 (let ((fun (compile nil
4223 (declare (double-float x
))
4224 (unknown-fun 1.0d0
(+ 1.0d0 x
))))))
4225 (assert (equal '(1.0d0
) (ctu:find-code-constants fun
:type
'double-float
)))))
4227 (with-test (:name
:only-one-boxed-constant-for-multiple-uses
)
4228 (let* ((big (1+ most-positive-fixnum
))
4231 (unknown-fun ,big
(+ ,big x
))))))
4232 (assert (= 1 (length (ctu:find-code-constants fun
:type
`(eql ,big
)))))))
4234 (with-test (:name
:fixnum
+float-coerces-fixnum
4236 (let ((fun (compile nil
4241 (assert (not (ctu:find-named-callees fun
)))
4242 (assert (not (search "GENERIC"
4243 (with-output-to-string (s)
4244 (disassemble fun
:stream s
)))))))
4246 (with-test (:name
:bug-803508
)
4247 (compile nil
`(lambda ()
4250 (declare (dynamic-extent bar
))
4253 (with-test (:name
:bug-803508-b
)
4254 (compile nil
`(lambda ()
4257 (declare (dynamic-extent bar
))
4260 (with-test (:name
:bug-803508-c
)
4261 (compile nil
`(lambda ()
4263 (lambda (bar &optional quux
)
4264 (declare (dynamic-extent bar quux
))
4267 (with-test (:name
:cprop-with-constant-but-assigned-to-closure-variable
)
4268 (compile nil
`(lambda (b c d
)
4269 (declare (type (integer -
20545789 207590862) c
))
4270 (declare (type (integer -
1 -
1) d
))
4271 (let ((i (unwind-protect 32 (shiftf d -
1))))
4272 (or (if (= d c
) 2 (= 3 b
)) 4)))))
4274 (with-test (:name
:bug-913232
)
4275 (compile nil
`(lambda (x)
4276 (declare (optimize speed
)
4277 (type (or (and (or (integer -
100 -
50)
4278 (integer 100 200)) (satisfies foo
))
4279 (and (or (integer 0 10) (integer 20 30)) a
)) x
))
4281 (compile nil
`(lambda (x)
4282 (declare (optimize speed
)
4283 (type (and fixnum a
) x
))
4286 (with-test (:name
:bug-959687
)
4287 (multiple-value-bind (fun warn fail
)
4288 (compile nil
`(lambda (x)
4294 (assert (and warn fail
))
4295 (assert (not (ignore-errors (funcall fun t
)))))
4296 (multiple-value-bind (fun warn fail
)
4297 (compile nil
`(lambda (x)
4303 (assert (and warn fail
))
4304 (assert (not (ignore-errors (funcall fun t
))))))
4306 (with-test (:name
:bug-924276
)
4307 (assert (eq :style-warning
4309 (compile nil
`(lambda (a)
4310 (cons a
(symbol-macrolet ((b 1))
4311 (declare (ignorable a
))
4316 (with-test (:name
:bug-974406
)
4317 (let ((fun32 (compile nil
`(lambda (x)
4318 (declare (optimize speed
(safety 0)))
4319 (declare (type (integer 53 86) x
))
4320 (logand (+ x
1032791128) 11007078467))))
4321 (fun64 (compile nil
`(lambda (x)
4322 (declare (optimize speed
(safety 0)))
4323 (declare (type (integer 53 86) x
))
4324 (logand (+ x
1152921504606846975)
4325 38046409652025950207)))))
4326 (assert (= (funcall fun32
61) 268574721))
4327 (assert (= (funcall fun64
61) 60)))
4329 (do ((width 5 (1+ width
)))
4332 (let ((fun (compile nil
`(lambda (x)
4333 (declare (optimize speed
(safety 0)))
4334 (declare (type (integer 1 16) x
))
4336 (+ x
,(1- (ash 1 width
)))
4337 ,(logior (ash 1 (+ width
1 extra
))
4338 (1- (ash 1 width
))))))))
4339 (unless (= (funcall fun
16) (logand 15 (1- (ash 1 width
))))
4340 (push (cons width extra
) result
)))))
4341 (assert (null result
))))
4343 ;; On x86-64 MOVE-IMMEDIATE of fixnum values into memory either directly
4344 ;; uses a MOV into memory or goes through a temporary register if the
4345 ;; value is larger than a certain number of bits. Check that it respects
4346 ;; the limits of immediate arguments to the MOV instruction (if not, the
4347 ;; assembler will fail an assertion) and doesn't have sign-extension
4348 ;; problems. (The test passes fixnum constants through the MOVE VOP
4349 ;; which calls MOVE-IMMEDIATE.)
4350 (with-test (:name
:constant-fixnum-move
)
4351 (let ((f (compile nil
`(lambda (g)
4353 ;; The first three args are
4354 ;; uninteresting as they are
4355 ;; passed in registers.
4357 ,@(loop for i from
27 to
32
4358 collect
(expt 2 i
)))))))
4359 (assert (every #'plusp
(funcall f
#'list
)))))
4361 (with-test (:name
(:malformed-ignore
:lp-1000239
))
4363 (eval '(lambda () (declare (ignore (function . a
)))))
4364 sb-int
:simple-program-error
)
4366 (eval '(lambda () (declare (ignore (function a b
)))))
4367 sb-int
:simple-program-error
)
4369 (eval '(lambda () (declare (ignore (function)))))
4370 sb-int
:simple-program-error
)
4372 (eval '(lambda () (declare (ignore (a)))))
4373 sb-int
:simple-program-error
)
4375 (eval '(lambda () (declare (ignorable (a b
)))))
4376 sb-int
:simple-program-error
))
4378 (with-test (:name
:malformed-type-declaraions
)
4379 (compile nil
'(lambda (a) (declare (type (integer 1 2 .
3) a
)))))
4381 (with-test (:name
:compiled-program-error-escaped-source
)
4384 (funcall (compile nil
`(lambda () (lambda ("foo")))))
4385 (sb-int:compiled-program-error
(e)
4386 (let ((source (read-from-string (sb-kernel::program-error-source e
))))
4387 (equal source
'#'(lambda ("foo"))))))))
4389 (with-test (:name
:escape-analysis-for-nlxs
)
4390 (flet ((test (check lambda
&rest args
)
4391 (let* ((cell-note nil
)
4392 (fun (handler-bind ((compiler-note
4395 "Allocating a value-cell at runtime for"
4396 (princ-to-string note
))
4397 (setf cell-note t
)))))
4398 (compile nil lambda
))))
4399 (assert (eql check cell-note
))
4404 (dolist (arg args nil
)
4405 (setf fun
(funcall fun arg
)))
4406 (sb-int:simple-control-error
(e)
4408 (simple-condition-format-control e
)
4409 "attempt to RETURN-FROM a block or GO to a tag that no longer exists")
4411 (ctu:assert-no-consing
(apply fun args
))))))
4412 (test nil
`(lambda (x)
4413 (declare (optimize speed
))
4415 (flet ((ex () (return-from out
'out
!)))
4417 (cons (or (car x
) (ex)))
4419 (test t
`(lambda (x)
4420 (declare (optimize speed
))
4423 (flet ((oops () (return-from nasty t
)))
4425 (test t
`(lambda (r)
4426 (declare (optimize speed
))
4428 (flet ((ex () (return-from out r
)))
4431 (cons (or (car x
) (ex)))
4433 (test t
`(lambda (x)
4434 (declare (optimize speed
))
4436 (flet ((meh () (return-from eh
'meh
)))
4439 (cons (or (car x
) (meh)))
4441 (funcall (eh x
)))) t t
)))
4443 (with-test (:name
(:bug-1050768
:symptom
))
4444 ;; Used to signal an error.
4446 `(lambda (string position
)
4447 (char string position
)
4448 (array-in-bounds-p string
(1+ position
)))))
4450 (with-test (:name
(:bug-1050768
:cause
))
4451 (let ((types `((string string
)
4452 ((or (simple-array character
24) (vector t
24))
4453 (or (simple-array character
24) (vector t
))))))
4454 (dolist (pair types
)
4455 (destructuring-bind (orig conservative
) pair
4456 (assert sb-c
::(type= (specifier-type cl-user
::conservative
)
4457 (conservative-type (specifier-type cl-user
::orig
))))))))
4459 (with-test (:name
(:smodular64
:wrong-width
))
4460 (let ((fun (compile nil
4462 (declare (type (signed-byte 64) x
))
4463 (sb-c::mask-signed-field
64 (- x
7033717698976965573))))))
4464 (assert (= (funcall fun
10038) -
7033717698976955535))))
4466 (with-test (:name
(:smodular32
:wrong-width
))
4467 (let ((fun (compile nil
'(lambda (x)
4468 (declare (type (signed-byte 31) x
))
4469 (sb-c::mask-signed-field
31 (- x
1055131947))))))
4470 (assert (= (funcall fun
10038) -
1055121909))))
4472 (with-test (:name
:first-open-coded
)
4473 (let ((fun (compile nil
`(lambda (x) (first x
)))))
4474 (assert (not (ctu:find-named-callees fun
)))))
4476 (with-test (:name
:second-open-coded
)
4477 (let ((fun (compile nil
`(lambda (x) (second x
)))))
4478 (assert (not (ctu:find-named-callees fun
)))))
4480 (with-test (:name
:svref-of-symbol-macro
)
4481 (compile nil
`(lambda (x)
4482 (symbol-macrolet ((sv x
))
4483 (values (svref sv
0) (setf (svref sv
0) 99))))))
4485 ;; The compiler used to update the receiving LVAR's type too
4486 ;; aggressively when converting a large constant to a smaller
4487 ;; (potentially signed) one, causing other branches to be
4488 ;; inferred as dead.
4489 (with-test (:name
:modular-cut-constant-to-width
)
4490 (let ((test (compile nil
4495 ((2 2 0 -
2 -
1 2) 9223372036854775803)
4497 (assert (= (funcall test -
10470605025) 26))))
4499 (with-test (:name
:append-type-derivation
)
4501 '((lambda () (append 10)) (integer 10 10)
4502 (lambda () (append nil
10)) (integer 10 10)
4503 (lambda (x) (append x
10)) (or (integer 10 10) cons
)
4504 (lambda (x) (append x
(cons 1 2))) cons
4505 (lambda (x y
) (append x
(cons 1 2) y
)) cons
4506 (lambda (x y
) (nconc x
(the list y
) x
)) t
4507 (lambda (x y
) (nconc (the atom x
) y
)) t
4508 (lambda (x y
) (nconc (the (or null
(eql 10)) x
) y
)) t
4509 (lambda (x y
) (nconc (the (or cons vector
) x
) y
)) cons
4510 (lambda (x y
) (nconc (the sequence x
) y
)) t
4511 (lambda (x y
) (print (length y
)) (append x y
)) sequence
4512 (lambda (x y
) (print (length y
)) (append x y
)) sequence
4513 (lambda (x y
) (append (the (member (a) (b)) x
) y
)) cons
4514 (lambda (x y
) (append (the (member (a) (b) c
) x
) y
)) cons
4515 (lambda (x y
) (append (the (member (a) (b) nil
) x
) y
)) t
)))
4516 (loop for
(function result-type
) on test-cases by
#'cddr
4517 do
(assert (sb-kernel:type
= (sb-kernel:specifier-type
4518 (car (cdaddr (sb-kernel:%simple-fun-type
4519 (compile nil function
)))))
4520 (sb-kernel:specifier-type result-type
))))))
4522 (with-test (:name
:bug-504121
)
4523 (compile nil
`(lambda (s)
4524 (let ((p1 #'upper-case-p
))
4528 (let ((p2 #'(lambda (char) (upper-case-p char
))))
4531 (with-test (:name
(:bug-504121
:optional-missing
))
4532 (compile nil
`(lambda (s)
4533 (let ((p1 #'upper-case-p
))
4535 (lambda (g &optional x
)
4537 (let ((p2 #'(lambda (char) (upper-case-p char
))))
4540 (with-test (:name
(:bug-504121
:optional-superfluous
))
4541 (compile nil
`(lambda (s)
4542 (let ((p1 #'upper-case-p
))
4544 (lambda (g &optional x
)
4547 (let ((p2 #'(lambda (char) (upper-case-p char
))))
4550 (with-test (:name
(:bug-504121
:key-odd
))
4551 (compile nil
`(lambda (s)
4552 (let ((p1 #'upper-case-p
))
4557 (let ((p2 #'(lambda (char) (upper-case-p char
))))
4560 (with-test (:name
(:bug-504121
:key-unknown
))
4561 (compile nil
`(lambda (s)
4562 (let ((p1 #'upper-case-p
))
4567 (let ((p2 #'(lambda (char) (upper-case-p char
))))
4570 (with-test (:name
:bug-1181684
)
4571 (compile nil
`(lambda ()
4572 (let ((hash #xD13CCD13
))
4573 (setf hash
(logand most-positive-word
4576 (with-test (:name
(:local-
&optional-recursive-inline
:bug-1180992
))
4579 (labels ((called (&optional a
))
4580 (recursed (&optional b
)
4583 (declare (inline recursed called
))
4586 (with-test (:name
:constant-fold-logtest
)
4587 (assert (equal (sb-kernel:%simple-fun-type
4588 (compile nil
`(lambda (x)
4589 (declare (type (mod 1024) x
)
4592 '(function ((unsigned-byte 10)) (values null
&optional
)))))
4594 ;; type mismatches on LVARs with multiple potential sources used to
4595 ;; be reported as mismatches with the value NIL. Make sure we get
4596 ;; a warning, but that it doesn't complain about a constant NIL ...
4598 (with-test (:name
(:multiple-use-lvar-interpreted-as-NIL
:cast
))
4600 (handler-bind ((sb-int:type-warning
4603 (not (search "Constant "
4604 (simple-condition-format-control
4607 (compile nil
`(lambda (x y z
)
4608 (declare (type fixnum y z
))
4609 (aref (if x y z
) 0))))
4610 (error "Where's my warning?")))
4612 (with-test (:name
(:multiple-use-lvar-interpreted-as-NIL catch
))
4614 (handler-bind ((style-warning
4619 (simple-condition-format-arguments c
))))
4621 (compile nil
`(lambda (x y z f
)
4622 (declare (type fixnum y z
))
4623 (catch (if x y z
) (funcall f
)))))
4624 (error "Where's my style-warning?")))
4626 ;; Smoke test for rightward shifts
4627 (with-test (:name
(:ash
/right-signed
))
4628 (let* ((f (compile nil
`(lambda (x y
)
4629 (declare (type (mod ,(* 2 sb-vm
:n-word-bits
)) y
)
4630 (type sb-vm
:signed-word x
)
4633 (max (ash most-positive-word -
1))
4636 (assert (= (ash x
(- y
))
4639 (dotimes (y (* 2 sb-vm
:n-word-bits
))
4643 (test (+ min x
) y
))))))
4645 (with-test (:name
(:ash
/right-unsigned
))
4646 (let ((f (compile nil
`(lambda (x y
)
4647 (declare (type (mod ,(* 2 sb-vm
:n-word-bits
)) y
)
4651 (max most-positive-word
))
4653 (assert (= (ash x
(- y
))
4656 (dotimes (y (* 2 sb-vm
:n-word-bits
))
4658 (test (- max x
) y
))))))
4660 (with-test (:name
(:ash
/right-fixnum
))
4661 (let ((f (compile nil
`(lambda (x y
)
4662 (declare (type (mod ,(* 2 sb-vm
:n-word-bits
)) y
)
4667 (assert (= (ash x
(- y
))
4670 (dotimes (y (* 2 sb-vm
:n-word-bits
))
4673 (test (- most-positive-fixnum x
) y
)
4674 (test (+ most-negative-fixnum x
) y
))))))
4677 (with-test (:name
:fold-index-addressing-positive-offset
)
4678 (let ((f (compile nil
`(lambda (i)
4679 (if (typep i
'(integer -
31 31))
4680 (aref #.
(make-array 63) (+ i
31))
4684 ;; 5d3a728 broke something like this in CL-PPCRE
4685 (with-test (:name
:fold-index-addressing-potentially-negative-index
)
4686 (compile nil
`(lambda (index vector
)
4687 (declare (optimize speed
(safety 0))
4688 ((simple-array character
(*)) vector
)
4689 ((unsigned-byte 24) index
))
4690 (aref vector
(1+ (mod index
(1- (length vector
))))))))
4692 (with-test (:name
:constant-fold-ash
/right-fixnum
)
4693 (compile nil
`(lambda (a b
)
4694 (declare (type fixnum a
)
4695 (type (integer * -
84) b
))
4698 (with-test (:name
:constant-fold-ash
/right-word
)
4699 (compile nil
`(lambda (a b
)
4700 (declare (type word a
)
4701 (type (integer * -
84) b
))
4704 (with-test (:name
:nconc-derive-type
)
4705 (let ((function (compile nil
`(lambda (x y
)
4706 (declare (type (or cons fixnum
) x
))
4708 (assert (equal (sb-kernel:%simple-fun-type function
)
4709 '(function ((or cons fixnum
) t
) (values cons
&optional
))))))
4711 ;; make sure that all data-vector-ref-with-offset VOPs are either
4712 ;; specialised on a 0 offset or accept signed indices
4713 (with-test (:name
:data-vector-ref-with-offset-signed-index
)
4714 (let ((dvr (find-symbol "DATA-VECTOR-REF-WITH-OFFSET" "SB-KERNEL")))
4718 (loop for info in
(sb-c::fun-info-templates
4719 (sb-c::fun-info-or-lose dvr
))
4720 for
(nil second-arg third-arg
) = (sb-c::vop-info-arg-types info
)
4721 unless
(or (typep second-arg
'(cons (eql :constant
)))
4722 (find '(integer 0 0) third-arg
:test
'equal
)
4724 `(:or
,(sb-c::primitive-type-or-lose
4725 'sb-vm
::positive-fixnum
)
4726 ,(sb-c::primitive-type-or-lose
4730 (with-test (:name
:data-vector-set-with-offset-signed-index
)
4731 (let ((dvr (find-symbol "DATA-VECTOR-SET-WITH-OFFSET" "SB-KERNEL")))
4735 (loop for info in
(sb-c::fun-info-templates
4736 (sb-c::fun-info-or-lose dvr
))
4737 for
(nil second-arg third-arg
) = (sb-c::vop-info-arg-types info
)
4738 unless
(or (typep second-arg
'(cons (eql :constant
)))
4739 (find '(integer 0 0) third-arg
:test
'equal
)
4741 `(:or
,(sb-c::primitive-type-or-lose
4742 'sb-vm
::positive-fixnum
)
4743 ,(sb-c::primitive-type-or-lose
4747 (with-test (:name
:maybe-inline-ref-to-dead-lambda
)
4748 (compile nil
`(lambda (string)
4749 (declare (optimize speed
(space 0)))
4750 (cond ((every #'digit-char-p string
)
4756 ;; the x87 backend used to sometimes signal FP errors during boxing,
4757 ;; because converting between double and single float values was a
4758 ;; noop (fixed), and no doubt many remaining issues. We now store
4759 ;; the value outside pseudo-atomic, so any SIGFPE should be handled
4762 ;; When it fails, this test lands into ldb.
4763 (with-test (:name
:no-overflow-during-allocation
)
4764 (handler-case (eval '(cosh 90))
4765 (floating-point-overflow ()
4768 ;; unbounded integer types could break integer arithmetic.
4769 (with-test (:name
:bug-1199127
)
4770 (compile nil
`(lambda (b)
4771 (declare (type (integer -
1225923945345 -
832450738898) b
))
4772 (declare (optimize (speed 3) (space 3) (safety 2)
4773 (debug 0) (compilation-speed 1)))
4774 (loop for lv1 below
3
4777 (ash b
(min 25 lv1
))
4781 ;; non-trivial modular arithmetic operations would evaluate to wider results
4782 ;; than expected, and never be cut to the right final bitwidth.
4783 (with-test (:name
:bug-1199428-1
)
4784 (let ((f1 (compile nil
`(lambda (a c
)
4785 (declare (type (integer -
2 1217810089) a
))
4786 (declare (type (integer -
6895591104928 -
561736648588) c
))
4787 (declare (optimize (speed 2) (space 0) (safety 2) (debug 0)
4788 (compilation-speed 3)))
4791 (loop for lv2 below
1 count t
))))))
4792 (f2 (compile nil
`(lambda (a c
)
4793 (declare (notinline -
+ gcd logandc1
))
4794 (declare (optimize (speed 1) (space 1) (safety 0) (debug 1)
4795 (compilation-speed 3)))
4798 (loop for lv2 below
1 count t
)))))))
4801 (assert (eql (funcall f1 a c
)
4802 (funcall f2 a c
))))))
4804 (with-test (:name
:bug-1199428-2
)
4805 (let ((f1 (compile nil
`(lambda (a b
)
4806 (declare (type (integer -
1869232508 -
6939151) a
))
4807 (declare (type (integer -
11466348357 -
2645644006) b
))
4808 (declare (optimize (speed 1) (space 0) (safety 2) (debug 2)
4809 (compilation-speed 2)))
4810 (logand (lognand a -
6) (* b -
502823994)))))
4811 (f2 (compile nil
`(lambda (a b
)
4812 (logand (lognand a -
6) (* b -
502823994))))))
4813 (let ((a -
1491588365)
4815 (assert (eql (funcall f1 a b
)
4816 (funcall f2 a b
))))))
4818 ;; win32 is very specific about the order in which catch blocks
4819 ;; must be allocated on the stack
4820 (with-test (:name
:bug-1072739
)
4821 (let ((f (compile nil
4825 (WITH-OUTPUT-TO-STRING (G13908)
4828 (DECLARE (OPTIMIZE (SB-EXT:INHIBIT-WARNINGS
3)))
4830 (WITH-OUTPUT-TO-STRING (G13909) (PRINC %A%B% G13909
) G13909
)
4831 (UNBOUND-VARIABLE NIL
4833 (WITH-OUTPUT-TO-STRING (G13914)
4834 (PRINC %A%B% G13914
)
4837 (UNBOUND-VARIABLE NIL
4839 (WITH-OUTPUT-TO-STRING (G13913)
4843 (UNBOUND-VARIABLE NIL
4845 (WITH-OUTPUT-TO-STRING (G13912)
4849 (UNBOUND-VARIABLE NIL
4851 (WITH-OUTPUT-TO-STRING (G13911)
4853 (PRINC "%b%" G13911
)
4855 (UNBOUND-VARIABLE NIL
4857 (WITH-OUTPUT-TO-STRING (G13910)
4859 (PRINC "a%b%" G13910
)
4861 (UNBOUND-VARIABLE NIL
4862 (ERROR "Interpolation error in \"%a%b%\"
4866 (assert (funcall f
))))
4868 (with-test (:name
:equal-equalp-transforms
)
4870 (bit-vector #*11001100)
4871 (values `(nil 1 2 "test"
4872 ;; Floats duplicated here to ensure we get newly created instances
4873 (read-from-string "1.1") (read-from-string "1.2d0")
4874 (read-from-string "1.1") (read-from-string "1.2d0")
4875 1.1 1.2d0
'("foo" "bar" "test")
4876 #(1 2 3 4) #*101010 (make-broadcast-stream) #p
"/tmp/file"
4877 ,s
(copy-seq ,s
) ,bit-vector
(copy-seq ,bit-vector
)
4878 ,(make-hash-table) #\a #\b #\A
#\C
4879 ,(make-random-state) 1/2 2/3)))
4880 ;; Test all permutations of different types
4887 (and (eq (funcall (compile nil
`(lambda (x y
)
4888 (equal (the ,(type-of x
) x
)
4889 (the ,(type-of y
) y
))))
4892 (eq (funcall (compile nil
`(lambda (x y
)
4893 (equalp (the ,(type-of x
) x
)
4894 (the ,(type-of y
) y
))))
4901 (equal (the (cons (or simple-bit-vector simple-base-string
))
4903 (the (cons (or (and bit-vector
(not simple-array
))
4904 (simple-array character
(*))))
4906 (list (string 'list
))
4912 (equalp (the (cons (or simple-bit-vector simple-base-string
))
4914 (the (cons (or (and bit-vector
(not simple-array
))
4915 (simple-array character
(*))))
4917 (list (string 'list
))
4920 (with-test (:name
(restart-case optimize speed compiler-note
))
4921 (handler-bind ((compiler-note #'error
))
4922 (compile nil
'(lambda ()
4923 (declare (optimize speed
))
4924 (restart-case () (c ()))))
4925 (compile nil
'(lambda ()
4926 (declare (optimize speed
))
4928 (restart-case (setf x
(car (compute-restarts)))
4932 (with-test (:name
:copy-more-arg
4933 :fails-on
'(not (or :x86
:x86-64
:arm
)))
4934 ;; copy-more-arg might not copy in the right direction
4935 ;; when there are more fixed args than stack frame slots,
4936 ;; and thus end up splatting a single argument everywhere.
4937 ;; Failing platforms still start their stack frames at 8 slots, so
4938 ;; this is less likely to happen.
4941 (loop for i below n collect i
))
4942 (test-function (function skip
)
4943 ;; function should just be (subseq x skip)
4944 (loop for i from skip below
(+ skip limit
) do
4945 (let* ((values (iota i
))
4946 (f (apply function values
))
4947 (subseq (subseq values skip
)))
4948 (assert (equal f subseq
)))))
4950 (let ((gensyms (loop for i below n collect
(gensym))))
4951 (compile nil
`(lambda (,@gensyms
&rest rest
)
4952 (declare (ignore ,@gensyms
))
4955 (test-function (make-function i
) i
)))))
4957 (with-test (:name
:apply-aref
)
4960 (handler-bind ((warning (lambda (c) (setf warning c
))))
4961 (compile nil
`(lambda (x y
) (setf (apply #'sbit x y
) 10))))
4962 (assert (not warning
)))))
4963 (test `(lambda (x y
) (setf (apply #'aref x y
) 21)))
4964 (test `(lambda (x y
) (setf (apply #'bit x y
) 1)))
4965 (test `(lambda (x y
) (setf (apply #'sbit x y
) 0)))))
4967 (with-test (:name
:warn-on-the-values-constant
)
4968 (multiple-value-bind (fun warnings-p failure-p
)
4970 ;; The compiler used to elide this test without
4971 ;; noting that the type demands multiple values.
4972 '(lambda () (the (values fixnum fixnum
) 1)))
4973 (declare (ignore warnings-p
))
4974 (assert (functionp fun
))
4975 (assert failure-p
)))
4977 ;; quantifiers shouldn't cons themselves.
4978 (with-test (:name
:quantifiers-no-consing
)
4979 (let ((constantly-t (lambda (x) x t
))
4980 (constantly-nil (lambda (x) x nil
))
4981 (list (make-list 1000 :initial-element nil
))
4982 (vector (make-array 1000 :initial-element nil
)))
4983 (macrolet ((test (quantifier)
4984 (let ((function (make-symbol (format nil
"TEST-~A" quantifier
))))
4985 `(flet ((,function
(function sequence
)
4986 (,quantifier function sequence
)))
4987 (ctu:assert-no-consing
(,function constantly-t list
))
4988 (ctu:assert-no-consing
(,function constantly-nil vector
))))))
4994 (with-test (:name
:propagate-complex-type-tests
)
4995 (flet ((test (type value
)
4996 (let ((ftype (sb-kernel:%simple-fun-type
4997 (compile nil
`(lambda (x)
4998 (if (typep x
',type
)
5001 (assert (typep ftype
`(cons (eql function
))))
5002 (assert (= 3 (length ftype
)))
5003 (let* ((return (third ftype
))
5004 (rtype (second return
)))
5005 (assert (typep return
`(cons (eql values
)
5007 (cons (eql &optional
)
5009 (assert (and (subtypep rtype type
)
5010 (subtypep type rtype
)))))))
5011 (mapc (lambda (params)
5012 (apply #'test params
))
5013 `(((unsigned-byte 17) 0)
5014 ((member 1 3 5 7) 5)
5015 ((or symbol
(eql 42)) t
)))))
5017 (with-test (:name
:constant-fold-complex-type-tests
)
5018 (assert (equal (sb-kernel:%simple-fun-type
5019 (compile nil
`(lambda (x)
5020 (if (typep x
'(member 1 3))
5021 (typep x
'(member 1 3 15))
5023 `(function (t) (values (member t
) &optional
))))
5024 (assert (equal (sb-kernel:%simple-fun-type
5025 (compile nil
`(lambda (x)
5026 (declare (type (member 1 3) x
))
5027 (typep x
'(member 1 3 15)))))
5028 `(function ((or (integer 1 1) (integer 3 3)))
5029 (values (member t
) &optional
)))))
5031 (with-test (:name
:quietly-row-major-index-no-dimensions
)
5032 (assert (handler-case
5033 (compile nil
`(lambda (x) (array-row-major-index x
)))
5036 (with-test (:name
:array-rank-transform
)
5037 (compile nil
`(lambda (a) (array-rank (the an-imaginary-type a
)))))
5039 (with-test (:name
(:array-rank-fold
:bug-1252108
))
5041 (handler-bind ((sb-ext::code-deletion-note
5048 (when (= (array-rank a
) 3)
5049 (array-dimension a
2)))))))
5052 (assert-error (upgraded-array-element-type 'an-undefined-type
))
5054 (with-test (:name
:xchg-misencoding
)
5055 (assert (eql (funcall (compile nil
'(lambda (a b
)
5056 (declare (optimize (speed 3) (safety 2))
5057 (type single-float a
))
5063 (with-test (:name
:malformed-declare
)
5064 (multiple-value-bind (fun warnings-p failure-p
)
5065 (compile nil
'(lambda (x)
5066 (declare (unsigned-byte (x)))
5068 (assert (and fun warnings-p failure-p
))))
5070 (with-test (:name
:no-dubious-asterisk-warning
)
5071 (multiple-value-bind (fun warnings-p failure-p
)
5075 (macrolet ((frob-some-stuff (&rest exprs
)
5079 (if (symbolp x
) (copy-symbol x
) (gensym)))
5081 `(let ,(mapcar #'list temps exprs
)
5083 (format t
"Got~@{ ~S~^ and~}~%" ,@temps
))))))
5084 (frob-some-stuff *print-base
* (car foo
)))))
5085 (assert (and fun
(not warnings-p
) (not failure-p
)))))
5087 (with-test (:name
:interr-type-specifier-hashing
)
5093 (sb-c::type-specifier
5094 (sb-c::specifier-type
5095 `(simple-array ,(sb-vm:saetp-specifier saetp
) (*)))))
5096 sb-vm
:*specialized-array-element-type-properties
*))))
5097 (assert (sb-c::%interr-symbol-for-type-spec
`(or ,@specifiers
)))
5098 (assert (sb-c::%interr-symbol-for-type-spec
5099 `(or ,@specifiers system-area-pointer
)))))
5101 (with-test (:name
:simple-rank-1-array-
*-p-works
)
5102 (assert (funcall (compile nil
5103 '(lambda () (typep #() '(simple-array * (*)))))))
5104 (loop for saetp across sb-vm
:*specialized-array-element-type-properties
*
5106 (dotimes (n-dimensions 3) ; test ranks 0, 1, and 2.
5107 (let ((dims (make-list n-dimensions
:initial-element
2)))
5108 (dolist (adjustable-p '(nil t
))
5109 (let ((a (make-array dims
:element-type
(sb-vm:saetp-specifier saetp
)
5110 :adjustable adjustable-p
)))
5111 (assert (eq (and (= n-dimensions
1) (not adjustable-p
))
5112 (typep a
'(simple-array * (*)))))))))))
5114 (with-test (:name
:array-subtype-tests
5115 :skipped-on
'(:not
(:or
:x86
:x86-64
)))
5116 (assert (funcall (compile nil
5118 (typep #() '(or simple-vector simple-string
))))))
5119 (flet ((approx-lines-of-assembly-code (type-expr)
5121 (with-output-to-string (s)
5124 (declare (optimize (sb-c::verify-arg-count
0)))
5125 (typep x
',type-expr
))
5127 ;; These are fragile, but less bad than the possibility of messing up
5128 ;; any vops, especially since the generic code in 'vm-type' checks for
5129 ;; a vop by its name in a place that would otherwise be agnostic of the
5130 ;; backend were it not for my inability to test all platforms.
5131 (assert (< (approx-lines-of-assembly-code
5132 '(simple-array * (*))) 25))
5133 ;; this tested all possible widetags one at a time, e.g. in VECTOR-SAP
5134 (assert (< (approx-lines-of-assembly-code
5135 '(sb-kernel:simple-unboxed-array
(*))) 25))
5136 ;; This is actually a strange type but it's what ANSI-STREAM-READ-N-BYTES
5137 ;; declares as its buffer, which would choke in %BYTE-BLT if you gave it
5138 ;; (simple-array t (*)). But that's a different problem.
5139 (assert (< (approx-lines-of-assembly-code
5140 '(or system-area-pointer
(simple-array * (*)))) 29))
5141 ;; And this was used by %BYTE-BLT which tested widetags one-at-a-time.
5142 (assert (< (approx-lines-of-assembly-code
5143 '(or system-area-pointer
(sb-kernel:simple-unboxed-array
(*))))
5146 (with-test (:name
:local-argument-mismatch-error-string
)
5147 (let ((f (compile nil
`(lambda (x)
5150 (multiple-value-bind (ok err
) (ignore-errors (funcall f
42))
5152 (assert (search "FLET FOO" (princ-to-string err
))))))
5154 (with-test (:name
:bug-1310574-0
)
5155 (multiple-value-bind (function warning failure
)
5156 (compile nil
`(lambda (a)
5158 ((or (array * (* * 3)) (array * (* * 4)))
5159 (case (array-rank a
)
5160 (2 (aref a
1 2)))))))
5161 (declare (ignore function
))
5162 (assert (not warning
))
5163 (assert (not failure
))))
5165 (with-test (:name
:bug-1310574-1
)
5166 (multiple-value-bind (function warning failure
)
5167 (compile nil
`(lambda (a)
5169 ((or (array * ()) (array * (1)) (array * (1 2)))
5170 (case (array-rank a
)
5171 (3 (aref a
1 2 3)))))))
5172 (declare (ignore function
))
5173 (assert (not warning
))
5174 (assert (not failure
))))
5176 (with-test (:name
:bug-573747
)
5177 (multiple-value-bind (function warnings-p failure-p
)
5178 (compile nil
'(lambda (x) (progn (declare (integer x
)) (* x
6))))
5180 (assert failure-p
)))
5182 ;; Something in this function used to confuse lifetime analysis into
5183 ;; recording multiple conflicts for a single TNs in the dolist block.
5184 (with-test (:name
:bug-1327008
)
5185 (handler-bind (((or style-warning compiler-note
)
5187 (muffle-warning c
))))
5189 `(lambda (scheduler-spec
5190 schedule-generation-method
5191 utc-earliest-time utc-latest-time
5192 utc-other-earliest-time utc-other-latest-time
5197 maximum-connection-time
5200 permitted-route-locations prohibited-route-locations
5201 preferred-connection-locations disfavored-connection-locations
5202 origins destinations
5203 permitted-carriers prohibited-carriers
5204 permitted-operating-carriers prohibited-operating-carriers
5205 start-airports end-airports
5207 specified-circuity-limit-extra-miles
5208 (preferred-carriers :unspecified
)
5210 (declare (optimize speed
))
5211 (let ((table1 (list nil
))
5213 (skip-flifo-checks (getf scheduler-spec
:skip-flifo-checks
))
5214 (construct-gaps-p (getf scheduler-spec
:construct-gaps-p
))
5215 (gap-locations (getf scheduler-spec
:gap-locations
))
5216 (result-array (make-array 100))
5221 (prev-start-airports origins
)
5222 (prev-end-airports destinations
)
5223 (prev-permitted-carriers permitted-carriers
))
5224 (flet ((run-with-hint (hint random-magic other-randomness
5227 preferred-destinations
5229 (let* ((hint-permitted-carriers (first hint
))
5230 (preferred-end-airports
5231 (ecase schedule-generation-method
5232 (:DEPARTURE preferred-destinations
)
5233 (:ARRIVAL preferred-origins
)))
5234 (revised-permitted-carriers
5235 (cond ((and hint-permitted-carriers
5236 (not (eq permitted-carriers
:ANY
)))
5237 (intersection permitted-carriers
5238 hint-permitted-carriers
))
5239 (hint-permitted-carriers)
5240 (permitted-carriers)))
5241 (revised-maximum-mileage
5242 (min (let ((maximum-mileage 0))
5243 (dolist (o start-airports
)
5244 (dolist (d end-airports
)
5245 (setf maximum-mileage
5246 (max maximum-mileage
(mileage o d
)))))
5247 (round (+ (* circuity-limit maximum-mileage
)
5248 (or specified-circuity-limit-extra-miles
5249 (hairy-calculation slice-number
)))))
5251 (when (or (not (equal start-airports prev-start-airports
))
5252 (not (equal end-airports prev-end-airports
))
5253 (and (not (equal revised-permitted-carriers
5254 prev-permitted-carriers
))))
5258 permitted-operating-carriers
5259 prohibited-operating-carriers
5260 permitted-route-locations
5261 prohibited-route-locations
5265 (setf prev-permitted-carriers revised-permitted-carriers
))
5266 (multiple-value-bind (this-number-dequeued
5269 (apply #'schedule-loop
5270 utc-earliest-time utc-other-earliest-time
5271 utc-latest-time utc-other-latest-time
5272 scheduler-spec schedule-generation-method
5274 :maximum-mileage revised-maximum-mileage
5275 :maximum-extra-legs maximum-extra-legs
5276 :maximum-connection-time maximum-connection-time
5277 :same-pass-p same-pass-p
5278 :preferred-end-airports preferred-end-airports
5279 :maximum-blah random-magic
5280 :skip-flifo-checks skip-flifo-checks
5283 :preferred-connection-locations preferred-connection-locations
5284 :disfavored-connection-locations disfavored-connection-locations
5286 (when other-randomness
5287 (loop for i fixnum from n-new to
(+ n-new
(1- this-n-new
))
5288 do
(hairy-calculation i result-array
)))
5289 (incf number-dequeued this-number-dequeued
)
5290 (incf n-new this-n-new
)
5291 (setq exit-reason
(logior exit-reason this-exit-reason
))))))
5292 (let ((n-hints-processed 0))
5293 (dolist (hint scheduler-hints
)
5294 (run-with-hint hint n-hints-processed t
0
5296 (incf n-hints-processed
)))
5297 (run-with-hint nil
42 nil maximum-extra-legs
5301 (with-test (:name
:dead-code-in-optional-dispatch
)
5302 (multiple-value-bind (f warningp
)
5303 ;; the translation of each optional entry is
5304 ;; (let ((#:g (error "nope"))) (funcall #<clambda> ...))
5305 ;; but the funcall is unreachable. Since this is an artifact of how the
5306 ;; lambda is converted, it should not generate a note as if in user code.
5307 (compile nil
'(lambda (a &optional
(b (error "nope")) (c (error "nope")))
5309 (assert (and f
(not warningp
)))))
5311 (with-test (:name
:nth-value-of-non-constant-N
)
5312 (labels ((foo (n f
) (nth-value n
(funcall f
)))
5313 (bar () (values 0 1 2 3 4 5 6 7 8 9)))
5314 (assert (= (foo 5 #'bar
) 5)) ; basic correctness
5315 (assert (eq (foo 12 #'bar
) nil
))
5316 (ctu:assert-no-consing
(eql (foo 953 #'bar
) 953))))
5318 (with-test (:name
:position-derive-type-optimizer
)
5319 (assert-code-deletion-note
5320 '(lambda (x) ; the call to POSITION can't return 4
5321 (let ((i (position x
#(a b c d
) :test
'eq
)))
5322 (case i
(4 'nope
) (t 'okeydokey
))))))
5324 ;; Assert that DO-PACKED-TNS has unsurprising behavior if the body RETURNs.
5325 ;; This isn't a test in the problem domain of CL - it's of an internal macro,
5326 ;; and x86-64-specific not because of broken-ness, but because it uses
5327 ;; known random TNs to play with. Printing "skipped on" for other backends
5328 ;; would be somewhat misleading in as much as it means nothing about
5329 ;; the correctness of the test on other architectures.
5331 (with-test (:name
:do-packed-tn-iterator
)
5332 (dotimes (i (ash 1 6))
5333 (labels ((make-tns (n)
5334 (mapcar 'copy-structure
5335 (subseq `sb-vm
::(,rax-tn
,rbx-tn
,rcx-tn
) 0 n
)))
5338 (setf (sb-c::tn-next
(car list
)) (link (cdr list
)))
5340 (let* ((normal (make-tns (ldb (byte 2 0) i
)))
5341 (restricted (make-tns (ldb (byte 2 2) i
)))
5342 (wired (make-tns (ldb (byte 2 4) i
)))
5343 (expect (append normal restricted wired
))
5344 (comp (sb-c::make-empty-component
))
5345 (ir2-comp (sb-c::make-ir2-component
)))
5346 (setf (sb-c::component-info comp
) ir2-comp
5347 (sb-c::ir2-component-normal-tns ir2-comp
) (link normal
)
5348 (sb-c::ir2-component-restricted-tns ir2-comp
) (link restricted
)
5349 (sb-c::ir2-component-wired-tns ir2-comp
) (link wired
))
5351 (result (sb-c::do-packed-tns
(tn comp
42) (push tn list
))))
5352 (assert (eq result
42))
5353 (assert (equal expect
(nreverse list
))))
5355 (result (sb-c::do-packed-tns
(tn comp
'bar
)
5357 (if (= (incf n
) 4) (return 'foo
)))))
5358 (assert (eq result
(if (>= (length expect
) 4) 'foo
'bar
)))
5359 (assert (equal (subseq expect
0 (min 4 (length expect
)))
5360 (nreverse list
))))))))
5363 (with-test (:name
:optimize-quality-multiply-specified
)
5364 (let ((*error-output
* (make-broadcast-stream)))
5365 (let ((sb-c::*policy
* sb-c
::*policy
*)) ; to keep this test pure
5366 (assert-signal (proclaim '(optimize space debug
(space 0)))
5369 (compile nil
'(lambda () (declare (optimize speed
(speed 0))) 5))
5372 (compile nil
'(lambda () (declare (optimize speed
) (optimize (speed 0))) 5))
5375 (compile nil
'(lambda ()
5376 (declare (optimize speed
)) (declare (optimize (speed 0)))
5381 (assert-no-signal (proclaim '(optimize (space 3) space
)))
5383 (compile nil
'(lambda () (declare (optimize speed
(speed 3))) 5)))
5385 (compile nil
'(lambda () (declare (optimize speed
) (optimize (speed 3))) 5)))
5387 (compile nil
'(lambda ()
5388 (declare (optimize speed
)) (declare (optimize (speed 3)))
5391 (with-test (:name
:truncate-type-derivation
)
5398 (the (rational (1) (3)) b
))))
5401 (with-test (:name
:constantp-on-a-literal-function-works
)
5402 (assert (constantp `(the (function (list) t
) ,#'car
))))
5404 (with-test (:name
:arg-count-error
)
5405 (assert (eq :win
(handler-case (funcall (intern "CONS") 1 2 3)
5406 (sb-int:simple-program-error
() :win
)
5407 (condition () :lose
)))))
5409 (with-test (:name
:mv-conversion
)
5410 (compile nil
'(lambda (a)
5412 (list (unwind-protect a
))
5413 (multiple-value-call #'list
5414 (values (catch 'ct5
(go 0))))
5417 (with-test (:name
(:null-cleanups-1
:bug-1416704
:bug-404441
))
5419 (compile nil
`(lambda ()
5421 (declare (optimize speed
))
5423 (funcall (flet ((bar () 10)) #'bar
))
5424 (funcall (flet ((fez ()
5425 (funcall (flet ((foo () 20)) #'foo
))))
5427 (assert (= (funcall x t
) 10))
5428 (assert (= (funcall x nil
) 20))))
5430 (with-test (:name
(:null-cleanups-2
:bug-1416704
:bug-404441
))
5432 (compile nil
`(lambda ()
5434 (declare (optimize speed
))
5435 (let* ((a2 (lambda () 20))
5437 (a0 (flet ((f () (funcall a2
)))
5443 (let ((a5 (lambda () (funcall a4
))))
5447 (assert (= (catch 'x
(funcall fun t
)) 10))
5448 (assert (= (catch 'x
(funcall fun nil
)) 20))))
5451 (with-test (:name
:locall-already-let-converted
)
5452 (assert (eq (funcall
5458 (flet ((f () (return-from f ff
)))
5459 (declare (inline f
))
5462 (declare (inline call
))
5464 (call (lambda () 'result
)))))))
5467 (with-test (:name
:debug-dump-elsewhere
)
5474 (declare (optimize debug
))