1 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
2 (load "assertoid.lisp")
3 (load "compiler-test-util.lisp")
4 (load "test-util.lisp")
5 (use-package "ASSERTOID"))
7 ;;; bug 254: compiler falure
8 (defpackage :bug254
(:use
:cl
))
10 (declaim (optimize (safety 3) (debug 2) (speed 2) (space 1)))
12 (uhw2 nil
:type
(or package null
)))
13 (macrolet ((defprojection (variant &key lexpr eexpr
)
15 `(defmethod uu ((foo foo
))
16 (let ((uhw2 (foo.uhw2 bar
)))
19 (baz (funcall ,lexpr south east
1)))))))))
21 :lexpr
(lambda (south east sched
)
22 (flet ((bd (x) (bref x sched
)))
23 (let ((avecname (gafp)))
24 (declare (type (vector t
) avecname
))
27 (setf (avec.count avecname
) (length rest
))
28 (setf (aref avecname
0) (bd (h south
)))
29 (setf (aref avecname
1) (bd (h east
)))
32 :eexpr
(lambda (south east
))))
34 (delete-package :bug254
)
37 (defpackage :bug255
(:use
:cl
))
39 (declaim (optimize (safety 3) (debug 2) (speed 2) (space 1)))
44 (defstruct yam
(v nil
:type
(or v null
)))
46 (defstruct (bod (:include un
)) bo
)
47 (defstruct (bad (:include bod
)) ba
)
48 (declaim (ftype (function ((or w bad
) (or w bad
)) (values)) %ufm
))
49 (defun %ufm
(base bound
) (froj base bound
*1*) (values))
50 (declaim (ftype (function ((vector t
)) (or w bad
)) %pu
))
55 (flet ((project (x) (frob x
0)))
58 (progn (%pu avecname
))
61 (delete-package :bug255
)
64 (defpackage :bug148
(:use
:cl
))
69 (defstruct foo bar bletch
)
71 (labels ((kidify1 (kid)
79 (declare (inline kid-frob
))
82 (the simple-vector
(foo-bar perd
)))))
84 (declaim (optimize (safety 3) (speed 2) (space 1)))
87 (defun u-b-sra (x r ad0
&optional ad1
&rest ad-list
)
91 (vector-push-extend c0
*bar
*))))
94 (map nil
#'ad.frob
(the (vector t
) *bar
*))
97 (declare (inline c.frob ad.frob
)) ; 'til DYNAMIC-EXTENT
100 (defun bug148-3 (ad0)
101 (declare (special *foo
* *bar
*))
102 (declare (optimize (safety 3) (speed 2) (space 1)))
106 (mapc #'ad.frob
*bar
*)
109 (declare (inline c.frob ad.frob
))
112 (defun bug148-4 (ad0)
113 (declare (optimize (safety 3) (speed 2) (space 1) (debug 1)))
118 collect
(c.frob b
))))
119 (declare (inline c.frob ad.frob
))
121 (funcall (if (listp ad0
) #'ad.frob
#'print
) ad0
)
122 (funcall (if (listp ad0
) #'ad.frob
#'print
) (reverse ad0
)))))
124 (assert (equal (eval '(bug148-4 '(1 2 3)))
125 '((1 2 3) (7 14 21) (21 14 7))))
127 (in-package :cl-user
)
128 (delete-package :bug148
)
131 (defpackage :bug258
(:use
:cl
))
135 (declare (special *foo
* *bar
*))
136 (declare (optimize (safety 3) (speed 2) (space 1) (debug 1)))
140 (mapcar #'c.frob ad
)))
141 (declare (inline c.frob ad.frob
))
143 (funcall (if (listp ad0
) #'ad.frob
#'print
) ad0
)
144 (funcall (if (listp ad0
) #'ad.frob
#'print
) (reverse ad0
)))))
146 (assert (equal (u-b-sra '(4 9 7))
147 '((4 9 7) (3 8 6) (6 8 3))))
149 (in-package :cl-user
)
150 (delete-package :bug258
)
154 (declare (optimize (speed 2) (safety 3)))
160 (funcall (eval ''list
) y
(+ y
2d0
) (* y
3d0
)))))
161 (assert-error (bug233a 4) type-error
)
165 (declare (type (double-float -
0d0
) x
))
166 (declare (optimize speed
))
167 (+ x
(sqrt (log (random 1d0
)))))
169 ;;; compiler failures reported by Paul Dietz: inaccurate dealing with
170 ;;; BLOCK-LAST in CONSTANT-FOLD-CALL and DO-NODES
171 (defun #:foo
(a b c d
)
172 (declare (type (integer -
1 1000655) b
)
173 (optimize (speed 3) (safety 1) (debug 1)))
175 (abs (- (+ b
(logandc1 -
473949 (max 5165 (abs (logandc1 a
250775)))))))
176 (logcount (logeqv (max (logxor (abs c
) -
1) 0) -
4)))
180 (declare (type (integer -
8507 26755) a
)
181 (type (integer -
393314538 2084485) d
)
182 (optimize (speed 3) (safety 1) (debug 1)))
184 (if (= 0 a
) 10 (abs -
1))
187 (max (logand a
31365125) d
)))))
189 ;;; compiler failure "NIL is not of type LVAR"
191 (progn (truly-the integer x
)
195 (declare (type (integer -
5498929 389890) a
)
196 (type (integer -
5029571274946 48793670) b
)
197 (type (integer 9221496 260169518304) c
)
199 (optimize (speed 3) (safety 1) (debug 1)))
200 (- (mod 1020122 (min -
49 -
420))
202 (block b2
(mod c
(min -
49 (if t
(return-from b2
1582) b
))))
207 ;;; bug 291 reported by Nikodemus Siivola (modified version)
210 (defun update-window-imag (line)
217 (unless (eq current the-sentinel
)
218 (let* ((cc (car current
))
219 (old-line (dis-line-line cc
)))
220 (if (eq old-line line
)
221 (do ((chars (line-%chars line
) nil
))
225 #'(lambda (&optional g2740 g2741
&rest g2742
)
226 (declare (ignore g2742
))
228 (values (setq string g2740
) (setq underhang g2741
))))
230 (setf (dis-line-old-chars cc
) chars
)))))))
232 ;;; and similar cases found by Paul Dietz
234 (declare (optimize (speed 0) (safety 3) (debug 3)))
238 (IF (LDB-TEST (BYTE 27 14) V2
)
247 (declare (optimize (speed 0) (safety 3) (debug 3)))
251 (MIN A
(RETURN-FROM B8 C
))))))
254 ;;; bug 292, reported by Paul Dietz
256 (DECLARE (TYPE (INTEGER -
5945502333 12668542) C
)
257 (OPTIMIZE (SPEED 3)))
259 (- (MAX (IF (/= 109335113 V2
) -
26479 V2
)
262 (MIN (MAX 521326 C
) -
51))))))
264 ;;; zombie variables, arising from constraints
266 (DECLARE (TYPE (INTEGER -
40945116 24028306) B
)
267 (OPTIMIZE (SPEED 3)))
268 (LET ((V5 (MIN 31883 (LOGCOUNT A
))))
269 (IF (/= B V5
) (IF (EQL 122911784 V5
) -
43765 1487) B
)))
271 ;;; let-conversion of a function into deleted one
273 (declare (type (integer -
883 1566) a
)
274 (type (integer -
1 0) c
)
275 (optimize (speed 3) (safety 1) (debug 1)))
279 (return-from %f5
(if (= -
4857 a
) (%f8
) (%f8
)))
281 (if (<= 11 c
) (%f5
) c
))))
283 ;;; two bugs: "aggressive" deletion of optional entries and problems
284 ;;; of FIND-RESULT-TYPE in dealing with deleted code; reported by
285 ;;; Nikodemus Siivola (simplified version)
286 (defun lisp-error-error-handler (condition)
287 (invoke-debugger condition
)
291 (continue "return to hemlock's debug loop.")
292 (invoke-debugger condition
))
300 (labels ((bar (x &optional
(y (return-from u
)))
301 (list x y
(apply #'bar
(fee)))))
302 (list (bar 1) (bar 1 2))))
307 (declare (type (integer 0 1) b
) (optimize (speed 3)))
308 (flet ((%f2
() (lognor (block b5
138) c
)))
309 (if (not (or (= -
67399 b
) b
))
310 (deposit-field (%f2
) (byte 11 8) -
3)
313 ;;; bug 214: compiler failure
315 (declare (optimize (sb-ext:inhibit-warnings
0) (compilation-speed 2)))
316 (flet ((foo (&key
(x :vx x-p
)) (list x x-p
)))
320 (declare (optimize (sb-ext:inhibit-warnings
0) (compilation-speed 2)))
321 (lambda (x) (declare (fixnum x
)) (if (< x
0) 0 (1- x
))))
323 ;;; this one was reported by rydis on #lisp
326 (declare (optimize (speed 2) (space 3)))
330 ;;; bug reported by Brian Downing: incorrect detection of MV-LET
331 (DEFUN #:failure-testcase
(SESSION)
332 (LABELS ((CONTINUATION-1 ()
334 (IF (foobar-1 SESSION
)
336 (LET ((CONTINUATION-3
338 (MULTIPLE-VALUE-CALL #'CONTINUATION-2
340 (foobar-2 CONTINUATION-3
))))
341 (CONTINUATION-2 (&REST OTHER-1
)
342 (DECLARE (IGNORE OTHER-1
))))
345 ;;; reported by antifuchs/bdowning/etc on #lisp: ITERATE failure on
346 ;;; (iter (for i in '(1 2 3)) (+ i 50))
347 (defun values-producer () (values 1 2 3 4 5 6 7))
349 (defun values-consumer (fn)
350 (let (a b c d e f g h
)
351 (multiple-value-bind (aa bb cc dd ee ff gg hh
) (funcall fn
)
360 (values a b c d e f g h
))))
362 (let ((list (multiple-value-list (values-consumer #'values-producer
))))
363 (assert (= (length list
) 8))
364 (assert (null (nth 7 list
))))
366 ;;; failed on Alpha prior to sbcl-0.8.10.30
367 (defun lotso-values ()
368 (values 0 1 2 3 4 5 6 7 8 9
377 0 1 2 3 4 5 6 7 8 9))
379 ;;; bug 313: source transforms were "lisp-1"
380 (defun srctran-lisp1-1 (cadr) (if (functionp cadr
) (funcall cadr
1) nil
))
381 (assert (eql (funcall (eval #'srctran-lisp1-1
) #'identity
) 1))
382 (without-package-locks
383 ;; this be a nasal demon, but test anyways
385 (defun srctran-lisp1-2 (caar) (funcall (sb-ext:truly-the function caar
) 1))
386 (assert (eql (funcall (eval #'srctran-lisp1-2
) #'identity
) 1))
388 ;;; partial bug 262: reference of deleted CTRAN (in RETURN-FROM)
389 ;;; during inline expansion. Bug report by Peter Denno, simplified
390 ;;; test case by David Wragg.
391 (defun bug262-return-from (x &aux
(y nil
))
392 (labels ((foo-a (z) (return-from bug262-return-from z
))
393 (foo-b (z) (foo-a z
)))
394 (declare (inline foo-a
))
397 ;;; broken inference of an upper bound of an iteration variable,
398 ;;; reported by Rajat Datta.
400 (let ((vec (make-array num
:initial-element
0))
404 (when (= (svref vec i
) 0)
405 (do ((j (* i i
) (+ j i
)))
407 (setf (svref vec j
) 1))
411 (assert (= (isieve 46349) 4792))
413 ;;; COERCE should not be constant-folded (reported by Nikodemus
416 (setf (fdefinition f
) (lambda (x) x
))
417 (let ((g (compile nil
`(lambda () (coerce ',f
'function
)))))
418 (setf (fdefinition f
) (lambda (x) (1+ x
)))
419 (assert (eq (funcall g
) (fdefinition f
)))))
421 (let ((x (coerce '(1 11) 'vector
)))
423 (assert (equalp x
#(2 11))))
425 ;;; and BIT-* too (reported by Paul F. Dietz)
426 (loop with v1
= #*0011
428 for f in
'(bit-and bit-andc1 bit-andc2 bit-eqv
429 bit-ior bit-nand bit-nor bit-not
430 bit-orc1 bit-orc2 bit-xor
432 for form
= `(lambda ()
433 (let ((v (,f
,v1
,v2
)))
434 (setf (aref v
0) (- 1 (aref v
0)))
436 for compiled-res
= (funcall (compile nil form
))
437 for real-res
= (- 1 (aref (funcall f v1 v2
) 0))
438 do
(assert (equal compiled-res real-res
)))
441 (let ((v (bit-not ,v
)))
442 (setf (aref v
0) (- 1 (aref v
0)))
444 (compiled-res (funcall (compile nil form
)))
445 (real-res (- 1 (aref (funcall (eval #'bit-not
) v
) 0))))
446 (assert (equal compiled-res real-res
)))
448 ;; bug reported on sbcl-devel by Hannu Koivisto on 2005-08-10
449 (defvar *hannu-trap
* nil
)
450 (progv '(*hannu-trap
*) '()
451 (setq *hannu-trap
* t
))
452 (assert (not *hannu-trap
*))
454 ;;; bug reported on sbcl-help by Vasile Rotaru
455 (let* ((initial-size (expt 2 16))
456 (prime-table (make-array initial-size
457 :element-type
'integer
))
458 (first-primes #(5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
460 79 83 89 97 101 103 107 109 113 127 131 137 139 149
461 151 157 163 167 173 179 181 191 193 197 199 211 223
462 227 229 233 239 241 251 257 263 269 271 277 281))
466 (defun largest-prime-so-far ()
467 (aref prime-table
(1- count
)))
468 (defun add-prime (prime)
469 (setf (aref prime-table count
) prime
) (incf count
))
471 (map 'nil
#'add-prime first-primes
))
472 (defun next-candidate (candidate)
473 (prog1 (+ candidate increment
)
475 (2 (setf increment
4))
476 (4 (setf increment
2)))))
478 (let ((sqrt-n (truncate (sqrt n
))))
480 (let ((prime (aref prime-table i
)))
481 (when (> prime sqrt-n
)
482 (return-from prime-p t
))
483 (when (zerop (mod n prime
))
484 (return-from prime-p nil
))))
485 (error "~&prime-table too small: ~A ~A~%" n
486 (largest-prime-so-far))))
487 (defun generate-primes (required)
488 (do ((candidate (next-candidate (largest-prime-so-far))
489 (next-candidate candidate
)))
490 ((> candidate required
))
491 (when (prime-p candidate
)
492 (add-prime candidate
))))
496 ;;; Bug in the fopcompiler's handling of LOCALLY pre-0.9.14.8
505 ;;; Bug in the interaction of BIND-SENTINEL and UNBIND-TO-HERE, as
512 (declare (optimize (debug 2)))
517 (write-line "foo-2"))
518 (write-line "foo-1"))
519 (write-line "foo-0"))
523 ;;; LOAD-TIME-VALUE smartness
524 (defun load-time-value-type-derivation-test-1 ()
525 (ctu:compiler-derived-type
(load-time-value (cons 'foo
0))))
526 (defun load-time-value-type-derivation-test-2 ()
527 (ctu:compiler-derived-type
(load-time-value (+ (or *print-length
* 0) 10))))
528 (defun load-time-value-auto-read-only-p ()
529 (load-time-value (random most-positive-fixnum
)))
530 (defun load-time-value-boring ()
531 (load-time-value (cons t t
)))
532 (test-util:with-test
(:name
(load-time-value :type-smartness
/cload
))
533 (assert (eq 'cons
(load-time-value-type-derivation-test-1)))
534 (assert (equal '(integer 10) (load-time-value-type-derivation-test-2)))
535 (assert (not (ctu:find-value-cell-values
#'load-time-value-auto-read-only-p
)))
536 (assert (ctu:find-value-cell-values
#'load-time-value-boring
)))
538 (defun regression-1.0
.29.54 ()
539 (logior (1+ most-positive-fixnum
)
540 (load-time-value (the fixnum
(eval 1)) t
)))
542 (test-util:with-test
(:name
:regression-1.0
.29.54)
543 (assert (= (+ most-positive-fixnum
2) (regression-1.0
.29.54)))
545 (funcall (compile nil
547 (load-time-value (values 42))))))))
549 (defun mv-call-regression-1.0
.43.57-foo
(a c d x y
)
551 (defun mv-call-regression-1.0
.43.57-bar
(a b c d
)
552 (declare (number a b c d
))
554 (defun mv-call-regression-1.0
.43.57-quux
(a sxx sxy syy
)
555 (multiple-value-call #'mv-call-regression-1.0
.43.57-foo
556 (mv-call-regression-1.0
.43.57-bar sxx sxy sxy syy
)
558 (test-util:with-test
(:name
:mv-call-regression-1.0
.43.57)
559 ;; This used to signal a bogus argument-count error.
560 (mv-call-regression-1.0
.43.57-quux
1s0
10s0
1s0
10s0
))
562 (defun etypecase-failure-test (x)
566 ((or fixnum float
) 'f
)))
568 (declare (muffle-conditions style-warning
))
569 (defun ecase-failure-test (x)
570 (ecase x
((a b c
) 1) ((b c d
) 2) ((e d f
) 3) ((c g h i
) 4))))
572 (test-util:with-test
(:name
:case-failures
)
573 (assert (equal (handler-case (etypecase-failure-test 'hi
)
574 (sb-kernel:case-failure
(c)
575 (sb-kernel::case-failure-possibilities c
)))
576 ;; In order as originally written
577 '(bignum character
(or fixnum float
))))
578 (assert (equal (handler-case (ecase-failure-test 'hi
)
579 (sb-kernel:case-failure
(c)
580 (sb-kernel::case-failure-possibilities c
)))
581 ;; In order as originally written, and no dups.
582 '(a b c d e f g h i
))))