1 ;;;; This file is for compiler tests which have side effects (e.g.
2 ;;;; executing DEFUN) but which don't need any special side-effecting
3 ;;;; environmental stuff (e.g. DECLAIM of particular optimization
4 ;;;; settings). Similar tests which *do* expect special settings may
5 ;;;; be in files compiler-1.impure.lisp, compiler-2.impure.lisp, etc.
7 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; While most of SBCL is derived from the CMU CL system, the test
11 ;;;; files (like this one) were written from scratch after the fork
14 ;;;; This software is in the public domain and is provided with
15 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
16 ;;;; more information.
18 (load "assertoid.lisp")
19 (use-package "ASSERTOID")
21 ;;; Old CMU CL code assumed that the names of "keyword" arguments are
22 ;;; necessarily self-evaluating symbols, but ANSI Common Lisp allows
23 ;;; them to be any symbols, not necessarily keywords, and thus not
24 ;;; necessarily self-evaluating. Make sure that this works.
25 (defun newfangled-cons (&key ((left-thing x)) ((right-thing y)))
27 (assert (equal (cons 1 2) (newfangled-cons 'right-thing 2 'left-thing 1)))
29 ;;; ANSI specifically says that duplicate keys are OK in lambda lists,
30 ;;; with no special exception for macro lambda lists. (As reported by
31 ;;; Pierre Mai on cmucl-imp 2001-03-30, Python didn't think so. The
32 ;;; rest of the thread had some entertainment value, at least for me
33 ;;; (WHN). The unbelievers were besmote and now even CMU CL will
34 ;;; conform to the spec in this regard. Who needs diplomacy when you
35 ;;; have brimstone?:-)
36 (defmacro ayup-duplicate-keys-are-ok-i-see-the-lite (&key k)
38 (assert (equal (ayup-duplicate-keys-are-ok-i-see-the-lite :k 112) 112))
39 (assert (equal (ayup-duplicate-keys-are-ok-i-see-the-lite :k 'x :k 'y) 'x))
41 ;;; As reported by Alexey Dejneka (sbcl-devel 2002-01-30), in
42 ;;; sbcl-0.7.1 plus his patch (i.e. essentially sbcl-0.7.1.2), the
43 ;;; compiler barfed on this, blowing up in FIND-IN-PHYSENV looking for
44 ;;; the LAMBDA-VAR named NUM. That was fixed in sbcl-0.7.1.3.
45 (defun parse-num (index)
52 (when (and (digs) (digs)) x))))
54 ;;; Bug 132: The compiler used to fail to compile INTEGER-valued CATCH
55 ;;; tags. This was fixed by Alexey Dejneka in sbcl-0.7.1.14. (INTEGER
56 ;;; catch tags are still a bad idea because EQ is used to compare
57 ;;; tags, and EQ comparison on INTEGERs is unportable; but now it's a
58 ;;; compiler warning instead of a failure to compile.)
60 (catch 0 (print 1331)))
62 ;;; Bug 150: In sbcl-0.7.1.15, compiling this code caused a failure in
63 ;;; SB-C::ADD-TEST-CONSTRAINTS:
64 ;;; The value NIL is not of type SB-C::CONTINUATION.
65 ;;; This bug was fixed by APD in sbcl-0.7.1.30.
66 (defun bug150-test1 ()
68 (flet ((wufn () (glorp table1 4.9)))
69 (gleep *uustk* #'wufn "#1" (list)))
70 (if (eql (lo foomax 3.2))
72 (error "not ~S" '(eql (lo foomax 3.2))))
74 ;;; A simpler test case for bug 150: The compiler died with the
75 ;;; same type error when trying to compile this.
76 (defun bug150-test2 ()
80 ;;; bug 147, fixed by APD 2002-04-28
82 ;;; This test case used to crash the compiler, e.g. with
83 ;;; failed AVER: "(= (LENGTH (BLOCK-SUCC CALL-BLOCK)) 1)"
84 (defun bug147 (string ind)
88 (typep (char string ind) '(member #\1)))
91 ;;; bug reported and fixed by Matthias Hoelzl sbcl-devel 2002-05-13
92 (defmacro foo-2002-05-13 () ''x)
93 (eval '(foo-2002-05-13))
94 (compile 'foo-2002-05-13)
95 (foo-2002-05-13) ; (The bug caused UNDEFINED-FUNCTION to be signalled here.)
97 ;;; floating point pain on the PPC.
99 ;;; This test case used to fail to compile on most powerpcs prior to
100 ;;; sbcl-0.7.4.2x, as floating point traps were being incorrectly
102 (defun floating-point-pain (x)
103 (declare (single-float x))
106 ;;; bug found and fixed ca. sbcl-0.7.5.12: The INTERSECTION-TYPE
107 ;;; here satisfies "is a subtype of ARRAY-TYPE", but can't be
108 ;;; accessed with ARRAY-TYPE accessors like
109 ;;; ARRAY-TYPE-SPECIALIZED-ELEMENT-TYPE, so ARRAY-related
110 ;;; DEFTRANSFORMs died with TYPE-ERROR at compile time when
111 ;;; compiling the DEFUN here.
112 (defun stupid-input-to-smart-array-deftransforms-0-7-5-12 (v)
113 (declare (type (and simple-vector fwd-type-ref) v))
116 ;;; Ca. sbcl-0.7.5.15 the compiler would fail an internal consistency
117 ;;; check on this code because it expected all calls to %INSTANCE-REF
118 ;;; to be transformed away, but its expectations were dashed by perverse
119 ;;; code containing app programmer errors like this.
120 (defstruct something-known-to-be-a-struct x y)
121 (multiple-value-bind (fun warnings-p failure-p)
125 (cond (t (a4 a2 a3))))
127 (declare (type (or simple-vector null) a5 a6))
128 (something-known-to-be-a-struct-x a5))
132 (cond ((and (funcall a12 a2)
137 (let ((a15 (a1 a2 a3)))
140 (values #'a17 #'a11))))
141 ;; Python sees the structure accessor on the known-not-to-be-a-struct
142 ;; A5 value and is very, very disappointed in you. (But it doesn't
143 ;; signal BUG any more.)
146 ;;; On the SPARC, there was an erroneous definition of some VOPs used
147 ;;; to compile LOGANDs, which would lead to compilation of the
148 ;;; following function giving rise to a compile-time error (bug
149 ;;; spotted and fixed by Raymond Toy for CMUCL)
150 (defun logand-sparc-bogons (a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10)
151 (declare (type (unsigned-byte 32) a0)
152 (type (signed-byte 32) a1 a2 a3 a4 a5 a6 a7 a8 a9 a10)
153 ;; to ensure that the call is a candidate for
155 (optimize (speed 3) (safety 0) (compilation-speed 0) (debug 0)))
157 ;; the call that fails compilation
159 ;; a call to prevent the other arguments from being optimized away
160 (logand a1 a2 a3 a4 a5 a6 a7 a8 a9)))
162 ;;; bug 192, reported by Einar Floystad Dorum sbcl-devel 2002-08-14,
163 ;;; fixed in sbcl-0.7.6.26: Compiling this function in 0.7.6 caused
164 ;;; the compiler to try to constant-fold DATA-VECTOR-REF, which is OK,
165 ;;; except that there was no non-VOP definition of DATA-VECTOR-REF, so
177 (DECLARE (IGNORABLE S E))
187 (DECLARE (IGNORABLE S E))
188 (WHEN (EQL #\b E) (G910 (1+ I)))))))
195 (DECLARE (IGNORABLE S))
198 (G908 I))) "abcdefg" 0 (length "abcdefg")))
200 ;;; bugs #65, #70, and #109, closed by APD's patch sbcl-devel 2002-08-17
202 ;;; This was "YA code deletion bug" whose symptom was the failure of
204 ;;; (EQ (C::LAMBDA-TAIL-SET C::CALLER)
205 ;;; (C::LAMBDA-TAIL-SET (C::LAMBDA-HOME C::CALLEE)))
207 (defun bug65-1 (termx termy) ; from Carl Witty on submit bugs list, debian.org
209 ((alpha-equal-bound-term-lists (listx listy)
210 (or (and (null listx) (null listy))
212 (let ((bindings-x (bindings-of-bound-term (car listx)))
213 (bindings-y (bindings-of-bound-term (car listy))))
214 (if (and (null bindings-x) (null bindings-y))
215 (alpha-equal-terms (term-of-bound-term (car listx))
216 (term-of-bound-term (car listy)))
217 (and (= (length bindings-x) (length bindings-y))
219 (enter-binding-pairs (bindings-of-bound-term (car listx))
220 (bindings-of-bound-term (car listy)))
221 (alpha-equal-terms (term-of-bound-term (car listx))
222 (term-of-bound-term (car listy)))
223 (exit-binding-pairs (bindings-of-bound-term (car listx))
224 (bindings-of-bound-term (car listy)))))))
225 (alpha-equal-bound-term-lists (cdr listx) (cdr listy)))))
227 (alpha-equal-terms (termx termy)
228 (if (and (variable-p termx)
230 (equal-bindings (id-of-variable-term termx)
231 (id-of-variable-term termy))
232 (and (equal-operators-p (operator-of-term termx) (operator-of-term termy))
233 (alpha-equal-bound-term-lists (bound-terms-of-term termx)
234 (bound-terms-of-term termy))))))
238 (with-variable-invocation (alpha-equal-terms termx termy))))))
239 (defun bug65-2 () ; from Bob Rogers cmucl-imp 1999-07-28
240 ;; Given an FSSP alignment file named by the argument . . .
241 (labels ((get-fssp-char ()
245 ;; Stub body, enough to tickle the bug.
246 (list (read-fssp-char)
248 (defun bug70 ; from David Young cmucl-help 30 Nov 2000
249 (item sequence &key (test #'eql))
250 (labels ((find-item (obj seq test &optional (val nil))
251 (let ((item (first seq)))
254 ((funcall test obj item)
260 (nconc val `(,item))))))))
261 (find-item item sequence test)))
262 (defun bug109 () ; originally from CMU CL bugs collection, reported as
263 ; SBCL bug by MNA 2001-06-25
268 ;; Uncomment and it works
272 ;;; bug 192a, fixed by APD "more strict type checking" patch
273 ;;; (sbcl-devel 2002-08-07)
275 (declare (optimize (speed 0) (safety 3)))
276 ;; Even with bug 192a, this declaration was checked as an assertion.
280 ;; Because of bug 192a, this declaration was trusted without checking.
281 (declare (single-float x))
283 (assert (null (ignore-errors (bug192a nil))))
284 (multiple-value-bind (result error) (ignore-errors (bug192a 100))
285 (assert (null result))
286 (assert (equal (type-error-expected-type error) 'single-float)))
288 ;;; bug 194, fixed in part by APD "more strict type checking" patch
289 ;;; (sbcl-devel 2002-08-07)
291 (multiple-value-bind (result error)
292 (ignore-errors (multiple-value-prog1 (progn (the real '(1 2 3)))))
293 (assert (null result))
294 (assert (typep error 'type-error)))
295 (multiple-value-bind (result error)
296 (ignore-errors (the real '(1 2 3)))
297 (assert (null result))
298 (assert (typep error 'type-error))))
303 (arg2 (identity (the real #(1 2 3)))))
304 (if (< arg1 arg2) arg1 arg2)))))
305 (assert (eq (bug194d) t))
308 ;;; BUG 48a. and b. (symbol-macrolet handling), fixed by Eric Marsden
309 ;;; and Raymond Toy for CMUCL, fix ported for sbcl-0.7.6.18.
310 (multiple-value-bind (function warnings-p failure-p)
311 (compile nil '(lambda () (symbol-macrolet ((t nil)) t)))
313 (assert (raises-error? (funcall function) program-error)))
314 (multiple-value-bind (function warnings-p failure-p)
317 (symbol-macrolet ((*standard-input* nil))
320 (assert (raises-error? (funcall function) program-error)))
321 (multiple-value-bind (function warnings-p failure-p)
322 (compile nil '(lambda () (symbol-macrolet ((s nil)) (declare (special s)) s)))
324 (assert (raises-error? (funcall function) program-error)))
326 ;;; bug 120a: Turned out to be constraining code looking like (if foo
327 ;;; <X> <X>) where <X> was optimized by the compiler to be the exact
328 ;;; same block in both cases, but not turned into (PROGN FOO <X>).
329 ;;; Fixed by APD in sbcl-0.7.7.2, who provided this test:
330 (declaim (inline dont-constrain-if-too-much))
331 (defun dont-constrain-if-too-much (frame up-frame)
332 (declare (optimize (speed 3) (safety 1) (debug 1)))
333 (if (or (not frame) t)
336 (defun dont-constrain-if-too-much-aux (x y)
337 (declare (optimize (speed 3) (safety 1) (debug 1)))
338 (if x t (if y t (dont-constrain-if-too-much x y))))
340 (assert (null (dont-constrain-if-too-much-aux nil nil)))
342 ;;; TYPE-ERROR confusion ca. sbcl-0.7.7.24, reported and fixed by
343 ;;; APD sbcl-devel 2002-09-14
344 (defun exercise-0-7-7-24-bug (x)
345 (declare (integer x))
347 (setf y (the single-float (if (> x 0) x 3f0)))
349 (multiple-value-bind (v e) (ignore-errors (exercise-0-7-7-24-bug 4))
351 (assert (typep e 'type-error)))
352 (assert (equal (exercise-0-7-7-24-bug -4) '(3f0 3f0)))
354 ;;; non-intersecting type declarations were DWIMing in a confusing
355 ;;; fashion until sbcl-0.7.7.28, when APD reported and fixed the
357 (defun non-intersecting-the (x)
359 (setf y (the single-float (the integer x)))
362 (raises-error? (foo 3) type-error)
363 (raises-error? (foo 3f0) type-error)
365 ;;; until 0.8.2 SBCL did not check THEs in arguments
366 (defun the-in-arguments-aux (x)
368 (defun the-in-arguments-1 (x)
369 (list x (the-in-arguments-aux (the (single-float 0s0) x))))
370 (defun the-in-arguments-2 (x)
371 (list x (the-in-arguments-aux (the single-float x))))
373 (multiple-value-bind (result condition)
374 (ignore-errors (the-in-arguments-1 1))
375 (assert (null result))
376 (assert (typep condition 'type-error)))
377 (multiple-value-bind (result condition)
378 (ignore-errors (the-in-arguments-2 1))
379 (assert (null result))
380 (assert (typep condition 'type-error)))
382 ;;; bug 153: a hole in a structure slot type checking
383 (declaim (optimize safety))
385 (bla 0 :type fixnum))
387 (let ((foo (make-foo153)))
388 (setf (foo153-bla foo) '(1 . 1))
389 (format t "Is ~a of type ~a a cons? => ~a~%"
391 (type-of (foo153-bla foo))
392 (consp (foo153-bla foo)))))
394 (let ((foo (make-foo153)))
395 (setf (foo153-bla foo) x)
396 (format t "Is ~a of type ~a a cons? => ~a~%"
398 (type-of (foo153-bla foo))
399 (consp (foo153-bla foo)))))
401 (multiple-value-bind (result condition)
402 (ignore-errors (bug153-1))
403 (declare (ignore result))
404 (assert (typep condition 'type-error)))
405 (multiple-value-bind (result condition)
406 (ignore-errors (bug153-2 '(1 . 1)))
407 (declare (ignore result))
408 (assert (typep condition 'type-error)))
410 ;;;; bug 110: the compiler flushed the argument type test and the default
411 ;;;; case in the cond.
413 ;(locally (declare (optimize (safety 3) (speed 2)))
415 ; (declare (optimize (safety 2) (speed 3)))
416 ; (declare (type (or string stream) x))
417 ; (cond ((typep x 'string) 'string)
418 ; ((typep x 'stream) 'stream)
422 ;(multiple-value-bind (result condition)
423 ; (ignore-errors (bug110 0))
424 ; (declare (ignore result))
425 ; (assert (typep condition 'type-error)))
427 ;;; bug 202: the compiler failed to compile a function, which derived
428 ;;; type contradicted declared.
429 (declaim (ftype (function () null) bug202))
433 ;;; bugs 178, 199: compiler failed to compile a call of a function
434 ;;; with a hairy type
436 (funcall (the function (the standard-object x))))
438 (defun bug199-aux (f)
439 (eq nil (funcall f)))
442 (declare (type (and function (satisfies bug199-aux)) f))
445 ;;; check non-toplevel DEFMACRO
446 (defvar *defmacro-test-status* nil)
448 (defun defmacro-test ()
449 (fmakunbound 'defmacro-test-aux)
450 (let* ((src "defmacro-test.lisp")
451 (obj (compile-file-pathname src)))
455 (assert (equal *defmacro-test-status* '(function a)))
456 (setq *defmacro-test-status* nil)
458 (assert (equal *defmacro-test-status* nil))
459 (macroexpand '(defmacro-test-aux 'a))
460 (assert (equal *defmacro-test-status* '(macro 'a z-value)))
461 (eval '(defmacro-test-aux 'a))
462 (assert (equal *defmacro-test-status* '(expanded 'a z-value))))
463 (ignore-errors (delete-file obj)))))
467 ;;; bug 204: EVAL-WHEN inside a local environment
468 (defvar *bug204-test-status*)
470 (defun bug204-test ()
471 (let* ((src "bug204-test.lisp")
472 (obj (compile-file-pathname src)))
475 (setq *bug204-test-status* nil)
477 (assert (equal *bug204-test-status* '((:expanded :load-toplevel)
478 (:called :compile-toplevel)
479 (:expanded :compile-toplevel))))
480 (setq *bug204-test-status* nil)
482 (assert (equal *bug204-test-status* '((:called :load-toplevel)))))
483 (ignore-errors (delete-file obj)))))
487 ;;; toplevel SYMBOL-MACROLET
488 (defvar *symbol-macrolet-test-status*)
490 (defun symbol-macrolet-test ()
491 (let* ((src "symbol-macrolet-test.lisp")
492 (obj (compile-file-pathname src)))
495 (setq *symbol-macrolet-test-status* nil)
497 (assert (equal *symbol-macrolet-test-status*
499 (setq *symbol-macrolet-test-status* nil)
501 (assert (equal *symbol-macrolet-test-status* '(2))))
502 (ignore-errors (delete-file obj)))))
504 (symbol-macrolet-test)
506 ;;; On the x86, this code failed to compile until sbcl-0.7.8.37:
507 (defun x86-assembler-failure (x)
508 (declare (optimize (speed 3) (safety 0)))
509 (eq (setf (car x) 'a) nil))
511 ;;; bug 211: :ALLOW-OTHER-KEYS
512 (defun bug211d (&key (x :x x-p) ((:allow-other-keys y) :y y-p))
515 (assert (equal (bug211d) '(:x nil :y nil)))
516 (assert (equal (bug211d :x 1) '(1 t :y nil)))
517 (assert (raises-error? (bug211d :y 2) program-error))
518 (assert (equal (bug211d :y 2 :allow-other-keys t :allow-other-keys nil)
520 (assert (raises-error? (bug211d :y 2 :allow-other-keys nil) program-error))
527 (flet ((test (&key (x :x x-p) ((:allow-other-keys y) :y y-p))
529 (assert (equal (test) '(:x nil :y nil)))
530 (assert (equal (test :x 1) '(1 t :y nil)))
531 (assert (equal (test :y 2 :allow-other-keys 11 :allow-other-keys nil)
532 '(:x nil 11 t)))))))))
533 (assert (not failure-p))
541 (flet ((test (&key (x :x x-p))
543 (assert (equal (test) '(:x nil)))
544 (assert (equal (test :x 1) '(1 t)))
545 (assert (equal (test :y 2 :allow-other-keys 11 :allow-other-keys nil)
547 (assert (not failure-p))
550 (dolist (form '((test :y 2)
551 (test :y 2 :allow-other-keys nil)
552 (test :y 2 :allow-other-keys nil :allow-other-keys t)))
553 (multiple-value-bind (result warnings-p failure-p)
554 (compile nil `(lambda ()
555 (flet ((test (&key (x :x x-p) ((:allow-other-keys y) :y y-p))
559 (assert (raises-error? (funcall result) program-error))))
561 ;;; bug 217: wrong type inference
562 (defun bug217-1 (x s)
563 (let ((f (etypecase x
564 (character #'write-char)
565 (integer #'write-byte))))
568 (character (write-char x s))
569 (integer (write-byte x s)))))
570 (bug217-1 #\1 *standard-output*)
573 ;;; bug 221: tried and died on CSUBTYPEP (not VALUES-SUBTYPEP) of the
574 ;;; function return types when inferring the type of the IF expression
575 (declaim (ftype (function (fixnum) (values package boolean)) bug221f1))
576 (declaim (ftype (function (t) (values package boolean)) bug221f2))
578 (funcall (if b #'bug221f1 #'bug221f2) x))
580 ;;; bug 172: macro lambda lists were too permissive until 0.7.9.28
581 ;;; (fix provided by Matthew Danish) on sbcl-devel
582 (assert (null (ignore-errors
583 (defmacro bug172 (&rest rest foo) `(list ,rest ,foo)))))
586 (defun check-embedded-thes (policy1 policy2 x y)
588 (funcall (compile nil
590 (declare (optimize (speed 2) (safety ,policy1)))
592 (the (values (integer 2 3) t &optional)
593 (locally (declare (optimize (safety ,policy2)))
594 (the (values t (single-float 2f0 3f0) &optional)
596 (lambda () (values x y)))
600 (assert (equal (check-embedded-thes 0 0 :a :b) '(:a :b)))
602 (assert (equal (check-embedded-thes 0 3 :a 2.5f0) '(:a 2.5f0)))
603 (assert (typep (check-embedded-thes 0 3 2 3.5f0) 'type-error))
605 (assert (equal (check-embedded-thes 0 1 :a 3.5f0) '(:a 3.5f0)))
606 (assert (typep (check-embedded-thes 0 1 2 2.5d0) 'type-error))
608 (assert (equal (check-embedded-thes 3 0 2 :a) '(2 :a)))
609 (assert (typep (check-embedded-thes 3 0 4 2.5f0) 'type-error))
611 (assert (equal (check-embedded-thes 1 0 4 :b) '(4 :b)))
612 (assert (typep (check-embedded-thes 1 0 1.0 2.5f0) 'type-error))
615 (assert (equal (check-embedded-thes 3 3 2 2.5f0) '(2 2.5f0)))
616 (assert (typep (check-embedded-thes 3 3 0 2.5f0) 'type-error))
617 (assert (typep (check-embedded-thes 3 3 2 3.5f0) 'type-error))
619 ;;; INLINE inside MACROLET
620 (declaim (inline to-be-inlined))
621 (macrolet ((def (x) `(defun ,x (y) (+ y 1))))
623 (defun call-inlined (z)
625 (assert (= (call-inlined 3) 4))
626 (macrolet ((frob (x) `(+ ,x 3)))
627 (defun to-be-inlined (y)
629 (assert (= (call-inlined 3)
630 ;; we should have inlined the previous definition, so the
631 ;; new one won't show up yet.
633 (defun call-inlined (z)
635 (assert (= (call-inlined 3) 6))
636 (defun to-be-inlined (y)
638 (assert (= (call-inlined 3) 6))
640 ;;; DEFINE-COMPILER-MACRO to work as expected, not via weird magical
641 ;;; IR1 pseudo-:COMPILE-TOPLEVEL handling
642 (defvar *bug219-a-expanded-p* nil)
645 (define-compiler-macro bug219-a (&whole form y)
646 (setf *bug219-a-expanded-p* t)
650 (defun bug219-a-aux ()
652 (assert (= (bug219-a-aux)
653 (if *bug219-a-expanded-p* 4 3)))
654 (defvar *bug219-a-temp* 3)
655 (assert (= (bug219-a *bug219-a-temp*) 4))
657 (defvar *bug219-b-expanded-p* nil)
658 (defun bug219-b-aux1 (x)
660 (define-compiler-macro bug219-b (y)
661 (setf *bug219-b-expanded-p* t)
663 (defun bug219-b-aux2 (z)
665 (assert (not *bug219-b-expanded-p*))
666 (assert (raises-error? (bug219-b-aux2 1) undefined-function))
668 (defun bug219-b-aux2 (z)
672 (assert (= (bug219-b-aux2 1)
673 (if *bug219-b-expanded-p* 3 1)))
675 ;;; bug 224: failure in unreachable code deletion
676 (defmacro do-optimizations (&body body)
677 `(dotimes (.speed. 4)
680 (dotimes (.compilation-speed. 4)
681 (proclaim `(optimize (speed , .speed.) (space , .space.)
683 (compilation-speed , .compilation-speed.)))
689 "(lambda () (#:localy (declare (optimize (safety 3)))
690 (ignore-errors (progn (values-list (car (list '(1 . 2)))) t))))")))
693 (compile nil '(lambda ()
696 (labels ((i1 () (list (i2) (i2)))
697 (i2 () (list (int) (i1)))
699 (list (i1) (i1) (i1)))
700 :exit (return-from ext)
702 (list (error "nih") (ext) (ext))))))
705 (compile nil '(lambda (x) (let ((y (error ""))) (list x y)))))
707 ;;; bug 223: invalid moving of global function name referencing
708 (defun bug223-int (n)
711 (defun bug223-wrap ()
712 (let ((old #'bug223-int))
713 (setf (fdefinition 'bug223-int)
716 `(ext ,@(funcall old (1- n)))))))
717 (compile 'bug223-wrap)
719 (assert (equal (bug223-int 4) '(int 4)))
721 (assert (equal (bug223-int 4) '(ext int 3)))
723 (assert (equal (bug223-int 4) '(ext ext int 2)))
725 ;;; COERCE got its own DEFOPTIMIZER which has to reimplement most of
726 ;;; SPECIFIER-TYPE-NTH-ARG. For a while, an illegal type would throw
727 ;;; you into the debugger on compilation.
728 (defun coerce-defopt1 (x)
729 ;; illegal, but should be compilable.
730 (coerce x '(values t)))
731 (defun coerce-defopt2 (x)
732 ;; illegal, but should be compilable.
733 (coerce x '(values t &optional)))
734 (assert (null (ignore-errors (coerce-defopt1 3))))
735 (assert (null (ignore-errors (coerce-defopt2 3))))
737 ;;; Oops. In part of the (CATCH ..) implementation of DEBUG-RETURN,
738 ;;; it was possible to confuse the type deriver of the compiler
739 ;;; sufficiently that compiler invariants were broken (explained by
740 ;;; APD sbcl-devel 2003-01-11).
742 ;;; WHN's original report
743 (defun debug-return-catch-break1 ()
744 (with-open-file (s "/tmp/foo"
749 (integer-length most-positive-fixnum))))
755 ;;; APD's simplified test case
756 (defun debug-return-catch-break2 (x)
757 (declare (type (vector (unsigned-byte 8)) x))
758 (setq *y* (the (unsigned-byte 8) (aref x 4))))
760 ;;; FUNCTION-LAMBDA-EXPRESSION should return something that's COMPILE
761 ;;; can understand. Here's a simple test for that on a function
762 ;;; that's likely to return a hairier list than just a lambda:
763 (macrolet ((def (fn) `(progn
764 (declaim (inline ,fn))
765 (defun ,fn (x) (1+ x)))))
767 (let ((x (function-lambda-expression #'bug228)))
769 (assert (= (funcall (compile nil x) 1) 2))))
774 (declare (type (mod 4) i))
777 (assert (raises-error? (bug192b 6) type-error))
780 (locally (declare (type fixnum x y))
782 (assert (raises-error? (bug192c 1.1 2) type-error))
784 (assert (raises-error? (progn (the real (list 1)) t) type-error))
787 (declare (optimize (speed 2) (safety 0)))
790 (multiple-value-prog1
792 (unless f (return-from bug236 0))))))
793 (assert (eql (bug236 #(4) nil) 0))
795 ;;; Bug reported by reported by rif on c.l.l 2003-03-05
796 (defun test-type-of-special-1 (x)
799 (optimize (safety 3)))
801 (defun test-type-of-special-2 (x)
804 (optimize (safety 3)))
805 (list x (setq x (/ x 2)) x))
806 (assert (raises-error? (test-type-of-special-1 3/2) type-error))
807 (assert (raises-error? (test-type-of-special-2 3) type-error))
808 (assert (equal (test-type-of-special-2 8) '(8 4 4)))
810 ;;; bug which existed in 0.8alpha.0.4 for several milliseconds before
811 ;;; APD fixed it in 0.8alpha.0.5
812 (defun frob8alpha04 (x y)
814 (defun baz8alpha04 (this kids)
815 (flet ((n-i (&rest rest)
816 ;; Removing the #+NIL here makes the bug go away.
817 #+nil (format t "~&in N-I REST=~S~%" rest)
818 (apply #'frob8alpha04 this rest)))
820 ;;; failed in 0.8alpha.0.4 with "The value 13 is not of type LIST."
821 (assert (= (baz8alpha04 12 13) 25))
823 ;;; evaluation order in structure slot writers
827 (s (make-sswo :a (incf i) :b (incf i)))
829 (assert (= (sswo-a s) 1))
830 (assert (= (sswo-b s) 2))
831 (setf (sswo-a (pop l)) (pop l))
833 (assert (eq (sswo-a s) :v)))
839 (list (bar x) (bar x) (bar x))))
841 (assert (raises-error? (bug249 1.0) type-error))
843 ;;; bug reported by ohler on #lisp 2003-07-10
844 (defun bug-ohler-2003-07-10 (a b)
845 (declare (optimize (speed 0) (safety 3) (space 0)
846 (debug 1) (compilation-speed 0)))
849 ;;; bug reported by Doug McNaught on sbcl-devel 2003-09-14:
850 ;;; COMPILE-FILE did not bind *READTABLE*
851 (let* ((source "bug-doug-mcnaught-20030914.lisp")
852 (fasl (compile-file-pathname source)))
854 (assert (null (get-macro-character #\]))))
857 (assert (typep *bug-doug-mcnaught-20030914*
858 '(simple-array (unsigned-byte 4) (*))))
859 (assert (equalp *bug-doug-mcnaught-20030914* #(1 2 3)))
860 (makunbound '*bug-doug-mcnaught-20030914*)))
861 (compile-file source)
869 (defun expt-derive-type-bug (a b)
871 (truncate (expt a b))))
872 (assert (equal (multiple-value-list (expt-derive-type-bug 1 1))
875 ;;; Problems with type checking in functions with EXPLICIT-CHECK
876 ;;; attribute (reported by Peter Graves)
877 (loop for (fun . args) in '((= a) (/= a)
878 (< a) (<= a) (> a) (>= a))
879 do (assert (raises-error? (apply fun args) type-error)))
881 (defclass broken-input-stream (sb-gray:fundamental-input-stream) ())
882 (defmethod sb-gray:stream-read-char ((stream broken-input-stream))
883 (throw 'break :broken))
884 (assert (eql (block return
887 (funcall (eval ''peek-char)
888 1 (make-instance 'broken-input-stream))
891 (return-from return :good))))
894 ;;;; MUFFLE-CONDITIONS test (corresponds to the test in the manual)
895 (defvar *compiler-note-count* 0)
896 #-alpha ; FIXME: make a better test!
897 (handler-bind ((sb-ext:compiler-note (lambda (c)
899 (incf *compiler-note-count*))))
903 (declare (optimize speed) (fixnum x))
904 (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
905 (values (* x 5) ; no compiler note from this
907 (declare (sb-ext:unmuffle-conditions sb-ext:compiler-note))
908 ;; this one gives a compiler note
910 (assert (= *compiler-note-count* 1))
911 (assert (equal (multiple-value-list (funcall fun 1)) '(5 -5)))))
914 (eval '(flet ((%f (&key) nil)) (%f nil nil)))
916 (:no-error (val) (error "no error: ~S" val)))
918 (eval '(labels ((%f (&key x) x)) (%f nil nil)))
920 (:no-error (val) (error "no error: ~S" val)))
922 ;;;; tests not in the problem domain, but of the consistency of the
923 ;;;; compiler machinery itself
927 ;;; Hunt for wrong-looking things in fundamental compiler definitions,
928 ;;; and gripe about them.
930 ;;; FIXME: It should be possible to (1) repair the things that this
931 ;;; code gripes about, and then (2) make the code signal errors
932 ;;; instead of just printing complaints to standard output, in order
933 ;;; to prevent the code from later falling back into disrepair.
934 (defun grovel-results (function)
935 (dolist (template (fun-info-templates (info :function :info function)))
936 (when (template-more-results-type template)
937 (format t "~&Template ~A has :MORE results, and translates ~A.~%"
938 (template-name template)
941 (when (eq (template-result-types template) :conditional)
944 (let ((types (template-result-types template))
945 (result-type (fun-type-returns (info :function :type function))))
947 ((values-type-p result-type)
948 (do ((ltypes (append (args-type-required result-type)
949 (args-type-optional result-type))
951 (types types (rest types)))
954 (format t "~&More types than ltypes in ~A, translating ~A.~%"
955 (template-name template)
959 (unless (null ltypes)
960 (format t "~&More ltypes than types in ~A, translating ~A.~%"
961 (template-name template)
964 ((eq result-type (specifier-type nil))
966 (format t "~&Template ~A returns values for function ~A with RESULT-TYPE NIL.~%"
967 (template-name template)
970 ((/= (length types) 1)
971 (format t "~&Template ~A isn't returning 1 value for ~A.~%"
972 (template-name template)
976 (defun identify-suspect-vops (&optional (env (first
977 (last *info-environment*))))
978 (do-info (env :class class :type type :name name :value value)
979 (when (and (eq class :function) (eq type :type))
980 ;; OK, so we have an entry in the INFO database. Now, if ...
981 (let* ((info (info :function :info name))
982 (templates (and info (fun-info-templates info))))
984 ;; ... it has translators
985 (grovel-results name))))))
986 (identify-suspect-vops)
989 (quit :unix-status 104)