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.
20 ;; The tests in this file do not work under the legacy interpreter.
21 ;; They mostly do work in the fast interpreter, and are either harmless
22 ;; or actually reasonable things to test.
23 (when (and (eq sb-ext
:*evaluator-mode
* :interpret
)
24 (not (member :sb-fasteval
*features
*)))
25 (sb-ext:exit
:code
104))
27 (load "compiler-test-util.lisp")
28 (use-package "TEST-UTIL")
29 (use-package "ASSERTOID")
31 ;;; Old CMU CL code assumed that the names of "keyword" arguments are
32 ;;; necessarily self-evaluating symbols, but ANSI Common Lisp allows
33 ;;; them to be any symbols, not necessarily keywords, and thus not
34 ;;; necessarily self-evaluating. Make sure that this works.
35 (defun newfangled-cons (&key
((left-thing x
)) ((right-thing y
)))
37 (with-test (:name
(:lambda-list
&key
:self-evaluating
))
38 (assert (equal (cons 1 2) (newfangled-cons 'right-thing
2 'left-thing
1))))
40 ;;; ANSI specifically says that duplicate keys are OK in lambda lists,
41 ;;; with no special exception for macro lambda lists. (As reported by
42 ;;; Pierre Mai on cmucl-imp 2001-03-30, Python didn't think so. The
43 ;;; rest of the thread had some entertainment value, at least for me
44 ;;; (WHN). The unbelievers were besmote and now even CMU CL will
45 ;;; conform to the spec in this regard. Who needs diplomacy when you
46 ;;; have brimstone?:-)
47 (defmacro ayup-duplicate-keys-are-ok-i-see-the-lite
(&key k
)
49 (with-test (:name
(:macro
:lambda-list
:duplicate
&key
:arguments
))
50 (assert (equal (funcall (checked-compile
52 (ayup-duplicate-keys-are-ok-i-see-the-lite
55 (assert (equal (funcall (checked-compile
57 (ayup-duplicate-keys-are-ok-i-see-the-lite
61 ;;; As reported by Alexey Dejneka (sbcl-devel 2002-01-30), in
62 ;;; sbcl-0.7.1 plus his patch (i.e. essentially sbcl-0.7.1.2), the
63 ;;; compiler barfed on this, blowing up in FIND-IN-PHYSENV looking for
64 ;;; the LAMBDA-VAR named NUM. That was fixed in sbcl-0.7.1.3.
65 (defun parse-num (index)
72 (when (and (digs) (digs)) x
))))
74 ;;; Bug 132: The compiler used to fail to compile INTEGER-valued CATCH
75 ;;; tags. This was fixed by Alexey Dejneka in sbcl-0.7.1.14. (INTEGER
76 ;;; catch tags are still a bad idea because EQ is used to compare
77 ;;; tags, and EQ comparison on INTEGERs is unportable; but now it's a
78 ;;; compiler warning instead of a failure to compile.)
80 (catch 0 (print 1331)))
82 ;;; Bug 150: In sbcl-0.7.1.15, compiling this code caused a failure in
83 ;;; SB-C::ADD-TEST-CONSTRAINTS:
84 ;;; The value NIL is not of type SB-C::CONTINUATION.
85 ;;; This bug was fixed by APD in sbcl-0.7.1.30.
86 (defun bug150-test1 ()
88 (flet ((wufn () (glorp table1
4.9)))
89 (gleep *uustk
* #'wufn
"#1" (list)))
90 (if (eql (lo foomax
3.2))
92 (error "not ~S" '(eql (lo foomax
3.2))))
94 ;;; A simpler test case for bug 150: The compiler died with the
95 ;;; same type error when trying to compile this.
96 (defun bug150-test2 ()
100 ;;; bug 147, fixed by APD 2002-04-28
102 ;;; This test case used to crash the compiler, e.g. with
103 ;;; failed AVER: "(= (LENGTH (BLOCK-SUCC CALL-BLOCK)) 1)"
104 (defun bug147 (string ind
)
108 (typep (char string ind
) '(member #\
1)))
111 ;;; bug reported and fixed by Matthias Hoelzl sbcl-devel 2002-05-13
112 (defmacro foo-2002-05-13
() ''x
)
113 (eval '(foo-2002-05-13))
114 (compile 'foo-2002-05-13
)
115 (foo-2002-05-13) ; (The bug caused UNDEFINED-FUNCTION to be signalled here.)
117 ;;; floating point pain on the PPC.
119 ;;; This test case used to fail to compile on most powerpcs prior to
120 ;;; sbcl-0.7.4.2x, as floating point traps were being incorrectly
122 (defun floating-point-pain (x)
123 (declare (single-float x
))
126 ;;; bug found and fixed ca. sbcl-0.7.5.12: The INTERSECTION-TYPE
127 ;;; here satisfies "is a subtype of ARRAY-TYPE", but can't be
128 ;;; accessed with ARRAY-TYPE accessors like
129 ;;; ARRAY-TYPE-SPECIALIZED-ELEMENT-TYPE, so ARRAY-related
130 ;;; DEFTRANSFORMs died with TYPE-ERROR at compile time when
131 ;;; compiling the DEFUN here.
132 (defun stupid-input-to-smart-array-deftransforms-0-7-5-12 (v)
133 (declare (type (and simple-vector fwd-type-ref
) v
))
136 ;;; Ca. sbcl-0.7.5.15 the compiler would fail an internal consistency
137 ;;; check on this code because it expected all calls to %INSTANCE-REF
138 ;;; to be transformed away, but its expectations were dashed by perverse
139 ;;; code containing app programmer errors like this.
140 (defstruct something-known-to-be-a-struct x y
)
141 (with-test (:name
(compile defstruct
:instance-ref
))
144 ;; Python sees the structure accessor on the
145 ;; known-not-to-be-a-struct A5 value and is very, very
146 ;; disappointed in you. (But it doesn't signal BUG any
150 (cond (t (a4 a2 a3
))))
152 (declare (type (or simple-vector null
) a5 a6
))
153 (something-known-to-be-a-struct-x a5
))
157 (cond ((and (funcall a12 a2
)
162 (let ((a15 (a1 a2 a3
)))
165 (values #'a17
#'a11
)))
166 :allow-failure t
:allow-warnings t
:allow-style-warnings t
))))
168 ;;; On the SPARC, there was an erroneous definition of some VOPs used
169 ;;; to compile LOGANDs, which would lead to compilation of the
170 ;;; following function giving rise to a compile-time error (bug
171 ;;; spotted and fixed by Raymond Toy for CMUCL)
172 (defun logand-sparc-bogons (a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
)
173 (declare (type (unsigned-byte 32) a0
)
174 (type (signed-byte 32) a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
)
175 ;; to ensure that the call is a candidate for
177 (optimize (speed 3) (safety 0) (compilation-speed 0) (debug 0)))
179 ;; the call that fails compilation
181 ;; a call to prevent the other arguments from being optimized away
182 (logand a1 a2 a3 a4 a5 a6 a7 a8 a9
)))
184 ;;; bug 192, reported by Einar Floystad Dorum sbcl-devel 2002-08-14,
185 ;;; fixed in sbcl-0.7.6.26: Compiling this function in 0.7.6 caused
186 ;;; the compiler to try to constant-fold DATA-VECTOR-REF, which is OK,
187 ;;; except that there was no non-VOP definition of DATA-VECTOR-REF, so
199 (DECLARE (IGNORABLE S E
))
209 (DECLARE (IGNORABLE S E
))
210 (WHEN (EQL #\b E
) (G910 (1+ I
)))))))
217 (DECLARE (IGNORABLE S
))
220 (G908 I
))) "abcdefg" 0 (length "abcdefg")))
222 ;;; bugs #65, #70, and #109, closed by APD's patch sbcl-devel 2002-08-17
224 ;;; This was "YA code deletion bug" whose symptom was the failure of
226 ;;; (EQ (C::LAMBDA-TAIL-SET C::CALLER)
227 ;;; (C::LAMBDA-TAIL-SET (C::LAMBDA-HOME C::CALLEE)))
229 (defun bug65-1 (termx termy
) ; from Carl Witty on submit bugs list, debian.org
231 ((alpha-equal-bound-term-lists (listx listy
)
232 (or (and (null listx
) (null listy
))
234 (let ((bindings-x (bindings-of-bound-term (car listx
)))
235 (bindings-y (bindings-of-bound-term (car listy
))))
236 (if (and (null bindings-x
) (null bindings-y
))
237 (alpha-equal-terms (term-of-bound-term (car listx
))
238 (term-of-bound-term (car listy
)))
239 (and (= (length bindings-x
) (length bindings-y
))
241 (enter-binding-pairs (bindings-of-bound-term (car listx
))
242 (bindings-of-bound-term (car listy
)))
243 (alpha-equal-terms (term-of-bound-term (car listx
))
244 (term-of-bound-term (car listy
)))
245 (exit-binding-pairs (bindings-of-bound-term (car listx
))
246 (bindings-of-bound-term (car listy
)))))))
247 (alpha-equal-bound-term-lists (cdr listx
) (cdr listy
)))))
249 (alpha-equal-terms (termx termy
)
250 (if (and (variable-p termx
)
252 (equal-bindings (id-of-variable-term termx
)
253 (id-of-variable-term termy
))
254 (and (equal-operators-p (operator-of-term termx
) (operator-of-term termy
))
255 (alpha-equal-bound-term-lists (bound-terms-of-term termx
)
256 (bound-terms-of-term termy
))))))
260 (with-variable-invocation (alpha-equal-terms termx termy
))))))
261 (defun bug65-2 () ; from Bob Rogers cmucl-imp 1999-07-28
262 ;; Given an FSSP alignment file named by the argument . . .
263 (labels ((get-fssp-char ()
267 ;; Stub body, enough to tickle the bug.
268 (list (read-fssp-char)
270 (defun bug70 ; from David Young cmucl-help 30 Nov 2000
271 (item sequence
&key
(test #'eql
))
272 (labels ((find-item (obj seq test
&optional
(val nil
))
273 (let ((item (first seq
)))
276 ((funcall test obj item
)
282 (nconc val
`(,item
))))))))
283 (find-item item sequence test
)))
284 (defun bug109 () ; originally from CMU CL bugs collection, reported as
285 ; SBCL bug by MNA 2001-06-25
290 ;; Uncomment and it works
294 ;;; bug 192a, fixed by APD "more strict type checking" patch
295 ;;; (sbcl-devel 2002-08-07)
297 (declare (optimize (speed 0) (safety 3)))
298 ;; Even with bug 192a, this declaration was checked as an assertion.
302 ;; Because of bug 192a, this declaration was trusted without checking.
303 (declare (single-float x
))
305 (with-test (:name
(declare type
:bug-192a
))
306 (assert-error (bug192a nil
) type-error
)
307 (multiple-value-bind (result error
) (ignore-errors (bug192a 100))
308 (assert (null result
))
309 (assert (equal (type-error-expected-type error
) 'single-float
))))
311 ;;; bug 194, fixed in part by APD "more strict type checking" patch
312 ;;; (sbcl-devel 2002-08-07)
313 (with-test (:name
(the :bug-194
))
314 (assert-error (multiple-value-prog1 (progn (the real
'(1 2 3)))) type-error
)
315 (assert-error (the real
'(1 2 3)) type-error
))
320 (arg2 (identity (the real
#(1 2 3)))))
321 (if (< arg1 arg2
) arg1 arg2
)))))
322 (with-test (:name
(the :bug-194d
))
323 (assert (eq (bug194d) t
)))
326 ;;; BUG 48a. and b. (symbol-macrolet handling), fixed by Eric Marsden
327 ;;; and Raymond Toy for CMUCL, fix ported for sbcl-0.7.6.18.
329 (multiple-value-bind (function failure-p
)
330 (checked-compile form
:allow-failure t
)
332 (assert-error (funcall function
) program-error
))))
334 (with-test (:name
(compile symbol-macrolet
:bug-48a
))
336 ;; not interested in the package lock violation here
337 (declare (sb-ext:disable-package-locks t
))
338 (symbol-macrolet ((t nil
)) t
))))
340 (with-test (:name
(compile symbol-macrolet
:bug-48b
))
342 ;; not interested in the package lock violation here
343 (declare (sb-ext:disable-package-locks
*standard-input
*))
344 (symbol-macrolet ((*standard-input
* nil
))
347 (with-test (:name
(compile symbol-macrolet
:bug-48c
))
349 (symbol-macrolet ((s nil
)) (declare (special s
)) s
)))))
352 ;;; bug 120a: Turned out to be constraining code looking like (if foo
353 ;;; <X> <X>) where <X> was optimized by the compiler to be the exact
354 ;;; same block in both cases, but not turned into (PROGN FOO <X>).
355 ;;; Fixed by APD in sbcl-0.7.7.2, who provided this test:
356 (declaim (inline dont-constrain-if-too-much
))
357 (defun dont-constrain-if-too-much (frame up-frame
)
358 (declare (optimize (speed 3) (safety 1) (debug 1)))
359 (if (or (not frame
) t
)
362 (defun dont-constrain-if-too-much-aux (x y
)
363 (declare (optimize (speed 3) (safety 1) (debug 1)))
364 (if x t
(if y t
(dont-constrain-if-too-much x y
))))
366 (with-test (:name
(if :constraint-propagation
:bug-120a
))
367 (assert (null (dont-constrain-if-too-much-aux nil nil
))))
369 ;;; TYPE-ERROR confusion ca. sbcl-0.7.7.24, reported and fixed by
370 ;;; APD sbcl-devel 2002-09-14
371 (defun exercise-0-7-7-24-bug (x)
372 (declare (integer x
))
374 (setf y
(the single-float
(if (> x
0) x
3f0
)))
376 (with-test (:name
(type-error :0.7.7.24))
377 (assert-error (exercise-0-7-7-24-bug 4) type-error
)
378 (assert (equal (exercise-0-7-7-24-bug -
4) '(3f0 3f0
))))
380 ;;; non-intersecting type declarations were DWIMing in a confusing
381 ;;; fashion until sbcl-0.7.7.28, when APD reported and fixed the
383 (defun non-intersecting-the (x)
385 (setf y
(the single-float
(the integer x
)))
388 (with-test (:name
:non-intersecting-the
)
389 (assert-error (non-intersecting-the 3) type-error
)
390 (assert-error (non-intersecting-the 3f0
) type-error
))
392 ;;; until 0.8.2 SBCL did not check THEs in arguments
393 (defun the-in-arguments-aux (x)
395 (defun the-in-arguments-1 (x)
396 (list x
(the-in-arguments-aux (the (single-float 0s0
) x
))))
397 (defun the-in-arguments-2 (x)
398 (list x
(the-in-arguments-aux (the single-float x
))))
400 (with-test (:name
(the :argument
))
401 (assert-error (the-in-arguments-1 1) type-error
)
402 (assert-error (the-in-arguments-2 1) type-error
))
404 ;;; bug 153: a hole in a structure slot type checking
405 (declaim (optimize safety
))
407 (bla 0 :type fixnum
))
409 (let ((foo (make-foo153)))
410 (setf (foo153-bla foo
) '(1 .
1))
411 (format t
"Is ~a of type ~a a cons? => ~a~%"
413 (type-of (foo153-bla foo
))
414 (consp (foo153-bla foo
)))))
416 (let ((foo (make-foo153)))
417 (setf (foo153-bla foo
) x
)
418 (format t
"Is ~a of type ~a a cons? => ~a~%"
420 (type-of (foo153-bla foo
))
421 (consp (foo153-bla foo
)))))
423 (with-test (:name
(:name defstruct
:slot
:type
:bug-153
))
424 (assert-error (bug153-1) type-error
)
425 (assert-error (bug153-2 '(1 .
1)) type-error
))
427 ;;;; bug 110: the compiler flushed the argument type test and the default
428 ;;;; case in the cond.
430 ;(locally (declare (optimize (safety 3) (speed 2)))
432 ; (declare (optimize (safety 2) (speed 3)))
433 ; (declare (type (or string stream) x))
434 ; (cond ((typep x 'string) 'string)
435 ; ((typep x 'stream) 'stream)
439 ;(multiple-value-bind (result condition)
440 ; (ignore-errors (bug110 0))
441 ; (declare (ignore result))
442 ; (assert (typep condition 'type-error)))
444 ;;; bug 202: the compiler failed to compile a function, which derived
445 ;;; type contradicted declared.
446 (declaim (ftype (function () null
) bug202
))
450 ;;; bugs 178, 199: compiler failed to compile a call of a function
451 ;;; with a hairy type
453 (funcall (the function
(the standard-object x
))))
455 (defun bug199-aux (f)
456 (eq nil
(funcall f
)))
459 (declare (type (and function
(satisfies bug199-aux
)) f
))
462 (with-test (:name
(declaim &optional
&rest
:bogus style-warning
))
465 "(declaim (ftype (function (symbol &optional t &rest t)) foo))
466 (defun foo (x &optional y &rest z)
467 (declare (ignore x y z)))"
471 ;;; check non-toplevel DEFMACRO
472 (defvar *defmacro-test-status
* nil
)
474 (with-test (:name
(compile-file defmacro
))
475 (fmakunbound 'defmacro-test-aux
)
476 (let* ((src "defmacro-test.lisp")
477 (obj (compile-file-pathname src
)))
481 (assert (equal *defmacro-test-status
* '(function a
)))
482 (setq *defmacro-test-status
* nil
)
484 (assert (equal *defmacro-test-status
* nil
))
485 (macroexpand '(defmacro-test-aux 'a
))
486 (assert (equal *defmacro-test-status
* '(macro 'a z-value
)))
487 (eval '(defmacro-test-aux 'a
))
488 (assert (equal *defmacro-test-status
* '(expanded 'a z-value
))))
489 (ignore-errors (delete-file obj
)))))
491 ;;; bug 204: EVAL-WHEN inside a local environment
492 (defvar *bug204-test-status
*)
494 (with-test (:name
(compile-file eval-when
:local-environment
:bug-204
))
495 (let* ((src "bug204-test.lisp")
496 (obj (compile-file-pathname src
)))
499 (setq *bug204-test-status
* nil
)
501 (assert (equal *bug204-test-status
* '((:expanded
:load-toplevel
)
502 (:called
:compile-toplevel
)
503 (:expanded
:compile-toplevel
))))
504 (setq *bug204-test-status
* nil
)
506 (assert (equal *bug204-test-status
* '((:called
:load-toplevel
)))))
507 (ignore-errors (delete-file obj
)))))
509 ;;; toplevel SYMBOL-MACROLET
510 ;;; FIXME: I didn't look into why this fails in the interpreter, but it does.
511 (defvar *symbol-macrolet-test-status
*)
513 (with-test (:name
(compile-file symbol-macrolet
) :skipped-on
:interpreter
)
514 (let* ((src "symbol-macrolet-test.lisp")
515 (obj (compile-file-pathname src
)))
518 (setq *symbol-macrolet-test-status
* nil
)
520 (assert (equal *symbol-macrolet-test-status
*
522 (setq *symbol-macrolet-test-status
* nil
)
524 (assert (equal *symbol-macrolet-test-status
* '(2))))
525 (ignore-errors (delete-file obj
)))))
527 ;;; On the x86, this code failed to compile until sbcl-0.7.8.37:
528 (defun x86-assembler-failure (x)
529 (declare (optimize (speed 3) (safety 0)))
530 (eq (setf (car x
) 'a
) nil
))
532 ;;; bug 211: :ALLOW-OTHER-KEYS
533 (defun bug211d (&key
(x :x x-p
) ((:allow-other-keys y
) :y y-p
))
536 (with-test (:name
(:allow-other-keys
:bug-211d
))
537 (assert (equal (bug211d) '(:x nil
:y nil
)))
538 (assert (equal (bug211d :x
1) '(1 t
:y nil
)))
539 (assert-error (bug211d :y
2) program-error
)
540 (assert (equal (bug211d :y
2 :allow-other-keys t
:allow-other-keys nil
)
542 (assert-error (bug211d :y
2 :allow-other-keys nil
) program-error
))
546 (flet ((test (&key
(x :x x-p
) ((:allow-other-keys y
) :y y-p
))
548 (assert (equal (test) '(:x nil
:y nil
)))
549 (assert (equal (test :x
1) '(1 t
:y nil
)))
550 (assert (equal (test :y
2 :allow-other-keys
11 :allow-other-keys nil
)
553 (with-test (:name
(compile :lambda-list
:bug-211b
))
556 (with-test (:name
(compile :lambda-list
:bug-211c
))
557 (let ((fun (checked-compile
559 (flet ((test (&key
(x :x x-p
))
561 (assert (equal (test) '(:x nil
)))
562 (assert (equal (test :x
1) '(1 t
)))
563 (assert (equal (test :y
2 :allow-other-keys
11 :allow-other-keys nil
)
567 (with-test (:name
(compile :lambda-list
:allow-other-keys
568 :bug-211
:do-not-allow
))
569 (dolist (form '((test :y
2)
570 (test :y
2 :allow-other-keys nil
)
571 (test :y
2 :allow-other-keys nil
:allow-other-keys t
)))
572 (multiple-value-bind (result failure-p
)
575 (flet ((test (&key
(x :x x-p
) ((:allow-other-keys y
) :y y-p
))
578 :allow-failure t
:allow-warnings t
)
580 (assert-error (funcall result
) program-error
))))
582 ;;; bug 217: wrong type inference
583 (defun bug217-1 (x s
)
584 (let ((f (etypecase x
585 (character #'write-char
)
586 (integer #'write-byte
))))
589 (character (write-char x s
))
590 (integer (write-byte x s
)))))
591 (with-test (:name
(:bug-217
))
592 (bug217-1 #\
1 (make-broadcast-stream)))
594 ;;; bug 221: tried and died on CSUBTYPEP (not VALUES-SUBTYPEP) of the
595 ;;; function return types when inferring the type of the IF expression
596 (declaim (ftype (function (fixnum) (values package boolean
)) bug221f1
))
597 (declaim (ftype (function (t) (values package boolean
)) bug221f2
))
599 (funcall (if b
#'bug221f1
#'bug221f2
) x
))
601 ;;; bug 172: macro lambda lists were too permissive until 0.7.9.28
602 ;;; (fix provided by Matthew Danish) on sbcl-devel
603 (with-test (:name
(defmacro :lambda-list
:bug-172
))
604 (assert-error (defmacro bug172
(&rest rest foo
) `(list ,rest
,foo
))))
606 (with-test (:name
(compile :embedded the
))
607 (flet ((check-embedded-thes (policy1 policy2 x y
)
609 (funcall (checked-compile
611 (declare (optimize (speed 2) (safety ,policy1
)))
613 (the (values (integer 2 3) t
&optional
)
614 (locally (declare (optimize (safety ,policy2
)))
615 (the (values t
(single-float 2f0
3f0
) &optional
)
617 (lambda () (values x y
)))
621 (assert (equal (check-embedded-thes 0 0 :a
:b
) '(:a
:b
)))
623 (assert (equal (check-embedded-thes 0 3 :a
2.5f0
) '(:a
2.5f0
)))
624 (assert (typep (check-embedded-thes 0 3 2 3.5f0
) 'type-error
))
626 (assert (equal (check-embedded-thes 0 1 :a
3.5f0
) '(:a
3.5f0
)))
627 (assert (typep (check-embedded-thes 0 1 2 2.5d0
) 'type-error
))
629 (assert (equal (check-embedded-thes 3 0 2 :a
) '(2 :a
)))
630 (assert (typep (check-embedded-thes 3 0 4 2.5f0
) 'type-error
))
632 (assert (equal (check-embedded-thes 1 0 3 :b
) '(3 :b
)))
633 (assert (typep (check-embedded-thes 1 0 1.0 2.5f0
) 'type-error
))
636 (assert (equal (check-embedded-thes 3 3 2 2.5f0
) '(2 2.5f0
)))
637 (assert (typep (check-embedded-thes 3 3 0 2.5f0
) 'type-error
))
638 (assert (typep (check-embedded-thes 3 3 2 3.5f0
) 'type-error
))))
641 ;;; INLINE inside MACROLET
642 (declaim (inline to-be-inlined
))
643 (macrolet ((def (x) `(defun ,x
(y) (+ y
1))))
645 (defun call-inlined (z)
647 (assert (= (call-inlined 3) 4))
648 (macrolet ((frob (x) `(+ ,x
3)))
649 (defun to-be-inlined (y)
652 (assert (= (call-inlined 3)
653 ;; we should have inlined the previous definition, so the
654 ;; new one won't show up yet.
656 (defun call-inlined (z)
658 #-interpreter
(assert (= (call-inlined 3) 6))
659 (defun to-be-inlined (y)
661 #-interpreter
(assert (= (call-inlined 3) 6))
663 ;;; DEFINE-COMPILER-MACRO to work as expected, not via weird magical
664 ;;; IR1 pseudo-:COMPILE-TOPLEVEL handling
665 (defvar *bug219-a-expanded-p
* nil
)
668 (define-compiler-macro bug219-a
(&whole form y
)
669 (setf *bug219-a-expanded-p
* t
)
673 (defun bug219-a-aux ()
675 (defvar *bug219-a-temp
* 3)
676 (with-test (:name
(define-compiler-macro :bug-219a
))
677 (assert (= (bug219-a-aux) (if *bug219-a-expanded-p
* 4 3)))
678 (assert (= (bug219-a *bug219-a-temp
*) 4)))
680 (defvar *bug219-b-expanded-p
* nil
)
681 (defun bug219-b-aux1 (x)
683 (define-compiler-macro bug219-b
(y)
684 (setf *bug219-b-expanded-p
* t
)
686 (defun bug219-b-aux2 (z)
688 (assert (not *bug219-b-expanded-p
*))
689 (assert-error (bug219-b-aux2 1) undefined-function
)
691 (defun bug219-b-aux2 (z)
695 (assert (= (bug219-b-aux2 1)
696 (if *bug219-b-expanded-p
* 3 1)))
698 ;;; bug 224: failure in unreachable code deletion
699 (defmacro do-optimizations
(&body body
)
700 `(dotimes (.speed.
4)
703 (dotimes (.compilation-speed.
4)
704 (proclaim `(optimize (speed , .speed.
) (space , .space.
)
706 (compilation-speed , .compilation-speed.
)))
709 (with-test (:name
(:unreachable-code locally declare
:bug-224
))
714 (#:localy (declare (optimize (safety 3)))
715 (ignore-errors (progn (values-list (car (list '(1 . 2)))) t))))")
716 :allow-failure t
:allow-style-warnings t
)))
718 (with-test (:name
(:unreachable-code error labels
:bug-224
))
724 (labels ((i1 () (list (i2) (i2)))
725 (i2 () (list (int) (i1)))
727 (list (i1) (i1) (i1)))
728 :exit
(return-from ext
))))
729 (list (error "nih") (ext) (ext)))))))
731 (with-test (:name
(:unreachable-code error let
:bug-224
))
733 (checked-compile '(lambda (x) (let ((y (error ""))) (list x y
))))))
735 ;;; bug 223: invalid moving of global function name referencing
736 (defun bug223-int (n)
739 (defun bug223-wrap ()
740 (let ((old #'bug223-int
))
741 (setf (fdefinition 'bug223-int
)
744 `(ext ,@(funcall old
(1- n
)))))))
746 (with-test (:name
(compile setf fdefinition
:bug-223
))
747 (compile 'bug223-wrap
)
748 (assert (equal (bug223-int 4) '(int 4)))
750 (assert (equal (bug223-int 4) '(ext int
3)))
752 (assert (equal (bug223-int 4) '(ext ext int
2))))
754 ;;; COERCE got its own DEFOPTIMIZER which has to reimplement most of
755 ;;; SPECIFIER-TYPE-NTH-ARG. For a while, an illegal type would throw
756 ;;; you into the debugger on compilation.
757 (defun coerce-defopt1 (x)
758 ;; illegal, but should be compilable.
759 (coerce x
'(values t
)))
760 (defun coerce-defopt2 (x)
761 ;; illegal, but should be compilable.
762 (coerce x
'(values t
&optional
)))
763 (with-test (:name
(coerce :optimizer
))
764 (assert-error (coerce-defopt1 3))
765 (assert-error (coerce-defopt2 3)))
767 ;;; Oops. In part of the (CATCH ..) implementation of DEBUG-RETURN,
768 ;;; it was possible to confuse the type deriver of the compiler
769 ;;; sufficiently that compiler invariants were broken (explained by
770 ;;; APD sbcl-devel 2003-01-11).
772 ;;; WHN's original report
773 (defun debug-return-catch-break1 ()
774 (with-open-file (s "/tmp/foo"
779 (integer-length most-positive-fixnum
))))
785 ;;; APD's simplified test case
786 (defun debug-return-catch-break2 (x)
787 (declare (type (vector (unsigned-byte 8)) x
))
788 (setq *y
* (the (unsigned-byte 8) (aref x
4))))
790 ;;; FUNCTION-LAMBDA-EXPRESSION should return something that COMPILE
791 ;;; can understand. Here's a simple test for that on a function
792 ;;; that's likely to return a hairier list than just a lambda:
793 (macrolet ((def (fn) `(progn
794 (declaim (inline ,fn
))
795 (defun ,fn
(x) (1+ x
)))))
797 (with-test (:name
(function-lambda-expression compile
:bug-228
))
798 (let ((x (function-lambda-expression #'bug228
)))
800 (assert (= (funcall (checked-compile x
) 1) 2)))))
805 (declare (type (mod 4) i
))
808 (with-test (:name
:bug-192b
)
809 (assert-error (bug192b 6) type-error
))
812 (locally (declare (type fixnum x y
))
814 (with-test (:name
:bug-192c
)
815 (assert-error (bug192c 1.1 2) type-error
)
816 (assert-error (progn (the real
(list 1)) t
) type-error
))
819 (declare (optimize (speed 2) (safety 0)))
822 (multiple-value-prog1
824 (unless f
(return-from bug236
0))))))
825 (with-test (:name
:bug-236
)
826 (assert (eql (bug236 #(4) nil
) 0)))
828 ;;; Bug reported by reported by rif on c.l.l 2003-03-05
829 (defun test-type-of-special-1 (x)
832 (optimize (safety 3)))
834 (defun test-type-of-special-2 (x)
837 (optimize (safety 3)))
838 (list x
(setq x
(/ x
2)) x
))
839 (with-test (:name
(declare special type
))
840 (assert-error (test-type-of-special-1 3/2) type-error
)
841 (assert-error (test-type-of-special-2 3) type-error
)
842 (assert (equal (test-type-of-special-2 8) '(8 4 4))))
844 ;;; bug which existed in 0.8alpha.0.4 for several milliseconds before
845 ;;; APD fixed it in 0.8alpha.0.5
846 (defun frob8alpha04 (x y
)
848 (defun baz8alpha04 (this kids
)
849 (flet ((n-i (&rest rest
)
850 ;; Removing the #+NIL here makes the bug go away.
851 #+nil
(format t
"~&in N-I REST=~S~%" rest
)
852 (apply #'frob8alpha04 this rest
)))
854 ;;; failed in 0.8alpha.0.4 with "The value 13 is not of type LIST."
855 (with-test (:name
(&rest type-error
))
856 (assert (= (baz8alpha04 12 13) 25)))
858 ;;; evaluation order in structure slot writers
861 (with-test (:name
(:evaluation-order structure
:slot-writer
))
863 (s (make-sswo :a
(incf i
) :b
(incf i
)))
865 (assert (= (sswo-a s
) 1))
866 (assert (= (sswo-b s
) 2))
867 (setf (sswo-a (pop l
)) (pop l
))
869 (assert (eq (sswo-a s
) :v
))))
875 (list (bar x
) (bar x
) (bar x
))))
877 (with-test (:name
(flet declare type
:bug-249
))
878 (assert-error (bug249 1.0) type-error
))
880 ;;; bug reported by ohler on #lisp 2003-07-10
881 (defun bug-ohler-2003-07-10 (a b
)
882 (declare (optimize (speed 0) (safety 3) (space 0)
883 (debug 1) (compilation-speed 0)))
886 ;;; bug reported by Doug McNaught on sbcl-devel 2003-09-14:
887 ;;; COMPILE-FILE did not bind *READTABLE*
888 (with-test (:name
(compile-file *readtable
*))
889 (let* ((source "bug-doug-mcnaught-20030914.lisp")
890 (fasl (compile-file-pathname source
)))
892 (assert (null (get-macro-character #\
]))))
895 (assert (typep *bug-doug-mcnaught-20030914
*
896 '(simple-array (unsigned-byte 4) (*))))
897 (assert (equalp *bug-doug-mcnaught-20030914
* #(1 2 3)))
898 (makunbound '*bug-doug-mcnaught-20030914
*)))
899 (compile-file source
)
905 (delete-file fasl
))))
907 (defun expt-derive-type-bug (a b
)
909 (truncate (expt a b
))))
910 (with-test (:name
(expt :derive-type
))
911 (assert (equal (multiple-value-list (expt-derive-type-bug 1 1))
914 ;;; Problems with type checking in functions with EXPLICIT-CHECK
915 ;;; attribute (reported by Peter Graves)
916 (with-test (:name
(:type-checking
:explicit-check
))
917 (loop for
(fun . args
) in
'((= a
) (/= a
)
918 (< a
) (<= a
) (> a
) (>= a
))
919 do
(assert-error (apply fun args
) type-error
)))
921 (defclass broken-input-stream
(sb-gray:fundamental-input-stream
) ())
922 (defmethod sb-gray:stream-read-char
((stream broken-input-stream
))
923 (throw 'break
:broken
))
924 (with-test (:name
:explicit-check
)
925 (assert (eql (block return
928 (funcall (eval ''peek-char
)
929 1 (make-instance 'broken-input-stream
))
932 (return-from return
:good
))))
935 ;;;; MUFFLE-CONDITIONS test (corresponds to the test in the manual)
936 ; FIXME: make a better test!
937 (with-test (:name muffle-conditions
:skipped-on
'(or :alpha
:x86-64
))
938 (multiple-value-bind (fun failure-p warnings style-warnings notes
)
941 (declare (optimize speed
) (fixnum x
))
942 (declare (sb-ext:muffle-conditions sb-ext
:compiler-note
))
943 (values (* x
5) ; no compiler note from this
945 (declare (sb-ext:unmuffle-conditions sb-ext
:compiler-note
))
946 ;; this one gives a compiler note
948 (declare (ignore failure-p warnings
))
949 (assert (= (length notes
) 1))
950 (assert (equal (multiple-value-list (funcall fun
1)) '(5 -
5)))))
952 (with-test (:name
(flet labels
&key
))
953 (assert-error (eval '(flet ((%f
(&key
) nil
)) (%f nil nil
))))
954 (assert-error (eval '(labels ((%f
(&key x
) x
)) (%f nil nil
)))))
956 ;;; PROGV must not bind constants, or violate declared types -- ditto for SET.
957 (assert-error (set pi
3))
958 (assert-error (progv '(pi s
) '(3 pi
) (symbol-value x
)))
959 (declaim (cons *special-cons
*))
960 (assert-error (set '*special-cons
* "nope") type-error
)
961 (assert-error (progv '(*special-cons
*) '("no hope") (car *special-cons
*)) type-error
)
963 ;;; No bogus warnings for calls to functions with complex lambda-lists.
964 (defun complex-function-signature (&optional x
&rest y
&key z1 z2
)
966 (with-test (:name
:complex-call-doesnt-warn
)
967 (checked-compile '(lambda (x) (complex-function-signature x
:z1
1 :z2
2))))
969 (with-test (:name
:non-required-args-update-info
)
970 (let ((name (gensym "NON-REQUIRE-ARGS-TEST"))
971 (*evaluator-mode
* :compile
))
972 (eval `(defun ,name
(x) x
))
973 (assert (equal '(function (t) (values t
&optional
))
974 (sb-kernel:type-specifier
(sb-int:proclaimed-ftype name
))))
975 (eval `(defun ,name
(x &optional y
) (or x y
)))
976 (assert (equal '(function (t &optional t
) (values t
&optional
))
977 (sb-kernel:type-specifier
(sb-int:proclaimed-ftype name
))))))
979 ;;;; inline & maybe inline nested calls
981 (defun quux-marker (x) x
)
982 (declaim (inline foo-inline
))
983 (defun foo-inline (x) (quux-marker x
))
984 (declaim (maybe-inline foo-maybe-inline
))
985 (defun foo-maybe-inline (x) (quux-marker x
))
987 (with-test (:name
:nested-inline-calls
)
988 (let ((fun (checked-compile `(lambda (x)
989 (foo-inline (foo-inline (foo-inline x
)))))))
990 (assert (= 0 (ctu:count-full-calls
"FOO-INLINE" fun
)))
991 (assert (= 3 (ctu:count-full-calls
"QUUX-MARKER" fun
)))))
993 (with-test (:name
:nested-maybe-inline-calls
)
994 (let ((fun (checked-compile
996 (declare (optimize (space 0)))
997 (foo-maybe-inline (foo-maybe-inline (foo-maybe-inline x
)))))))
998 (assert (= 0 (ctu:count-full-calls
"FOO-MAYBE-INLINE" fun
)))
999 (assert (= 1 (ctu:count-full-calls
"QUUX-MARKER" fun
)))))
1001 (with-test (:name
:inline-calls
)
1002 (let ((fun (checked-compile `(lambda (x)
1003 (list (foo-inline x
)
1006 (assert (= 0 (ctu:count-full-calls
"FOO-INLINE" fun
)))
1007 (assert (= 3 (ctu:count-full-calls
"QUUX-MARKER" fun
)))))
1009 (with-test (:name
:maybe-inline-calls
)
1010 (let ((fun (checked-compile `(lambda (x)
1011 (declare (optimize (space 0)))
1012 (list (foo-maybe-inline x
)
1013 (foo-maybe-inline x
)
1014 (foo-maybe-inline x
))))))
1015 (assert (= 0 (ctu:count-full-calls
"FOO-MAYBE-INLINE" fun
)))
1016 (assert (= 1 (ctu:count-full-calls
"QUUX-MARKER" fun
)))))
1018 (with-test (:name
:bug-405
)
1019 ;; These used to break with a TYPE-ERROR
1020 ;; The value NIL is not of type SB-C::PHYSENV.
1023 '((LET (outer-let-var)
1025 (print outer-let-var
)
1026 (MULTIPLE-VALUE-CALL 'some-function
1027 (MULTIPLE-VALUE-CALL (LAMBDA (a) 'foo
)
1030 '((declaim (optimize (debug 3)))
1031 (defstruct bug-405-foo bar
)
1033 (flet ((i (x) (frob x
(bug-405-foo-bar foo
))))
1037 (declaim (ftype (function (cons) number
) bug-235a-aux
))
1038 (declaim (inline bug-235a-aux
))
1039 (defun bug-235a-aux (c)
1040 (the number
(car c
)))
1041 (with-test (:name
:bug-235a
)
1042 (let ((fun (checked-compile
1044 (values (locally (declare (optimize (safety 0)))
1046 (locally (declare (optimize (safety 3)))
1047 (bug-235a-aux y
)))))))
1051 (funcall fun
'(:one
) '(:two
))
1053 (assert (eq :two
(type-error-datum e
)))
1054 (assert (eq 'number
(type-error-expected-type e
)))
1057 (with-test (:name
:compiled-debug-funs-leak
)
1059 (let ((usage-before (sb-kernel::dynamic-usage
)))
1061 (let ((f (checked-compile '(lambda () (error "X")))))
1066 (let ((usage-after (sb-kernel::dynamic-usage
)))
1067 (when (< (+ usage-before
2000000) usage-after
)
1070 ;;; PROGV compilation and type checking when the declared type
1071 ;;; includes a FUNCTION subtype.
1072 (declaim (type (or (function (t) (values boolean
&optional
)) string
)
1074 (defvar *hairy-progv-var
* #'null
)
1075 (with-test (:name
:hairy-progv-type-checking
)
1078 (progv '(*hairy-progv-var
*) (list (eval 42))
1080 (type-error () :error
))))
1081 (assert (equal "GOOD!"
1082 (progv '(*hairy-progv-var
*) (list (eval "GOOD!"))
1083 *hairy-progv-var
*))))
1085 (with-test (:name
:fill-complex-single-float
)
1086 (assert (every (lambda (x) (eql x
#c
(-1.0 -
2.0)))
1090 :element-type
'(complex single-float
)
1091 :initial-element
#c
(-1.0 -
2.0)))))))
1093 (with-test (:name
:make-array-symbol-as-initial-element
)
1094 (assert (every (lambda (x) (eq x
'a
))
1095 (funcall (checked-compile
1097 (make-array 12 :initial-element
'a
)))))))
1099 ;;; This non-minimal test-case catches a nasty error when loading
1100 ;;; inline constants.
1102 `(simple-array single-float
(16)))
1103 (declaim (ftype (sb-int:sfunction
(single-float single-float single-float single-float
1104 single-float single-float single-float single-float
1105 single-float single-float single-float single-float
1106 single-float single-float single-float single-float
)
1110 (defun matrix (m11 m12 m13 m14
1115 :element-type
'single-float
1116 :initial-contents
(list m11 m21 m31 m41
1120 (declaim (ftype (sb-int:sfunction
((simple-array single-float
(3)) single-float
) matrix
)
1122 (defun rotate-around (a radians
)
1123 (let ((c (cos radians
))
1125 ;; The 1.0 here was misloaded on x86-64.
1126 (g (- 1.0 (cos radians
))))
1127 (let* ((x (aref a
0))
1130 (gxx (* g x x
)) (gxy (* g x y
)) (gxz (* g x z
))
1131 (gyy (* g y y
)) (gyz (* g y z
)) (gzz (* g z z
)))
1133 (+ gxx c
) (- gxy
(* s z
)) (+ gxz
(* s y
)) 0.0
1134 (+ gxy
(* s z
)) (+ gyy c
) (- gyz
(* s x
)) 0.0
1135 (- gxz
(* s y
)) (+ gyz
(* s x
)) (+ gzz c
) 0.0
1137 (with-test (:name
:regression-1.0
.29.54)
1139 '(-1.0
0.0 0.0 0.0 0.0 -
1.0 0.0 0.0 0.0 0.0 -
1.0 0.0 0.0 0.0 0.0 1.0)
1141 (make-array 3 :element-type
'single-float
) (coerce pi
'single-float
))))
1142 ;; Same bug manifests in COMPLEX-ATANH as well.
1143 (assert (= (atanh #C
(-0.7d0
1.1d0
)) #C
(-0.28715567731069275d0
0.9394245539093365d0
))))
1145 (with-test (:name
:slot-value-on-structure
)
1146 (let ((f (checked-compile `(lambda (x a b
)
1147 (declare (something-known-to-be-a-struct x
))
1148 (setf (slot-value x
'x
) a
1149 (slot-value x
'y
) b
)
1150 (list (slot-value x
'x
)
1151 (slot-value x
'y
))))))
1152 (assert (equal '(#\x
#\y
)
1154 (make-something-known-to-be-a-struct :x
"X" :y
"Y")
1156 (assert (not (ctu:find-named-callees f
)))))
1158 (defclass some-slot-thing
()
1159 ((slot :initarg
:slot
)))
1160 (with-test (:name
:with-slots-the
)
1161 (let ((x (make-instance 'some-slot-thing
:slot
"foo")))
1162 (with-slots (slot) (the some-slot-thing x
)
1163 (assert (equal "foo" slot
)))))
1165 ;;; Missing &REST type in proclamation causing a miscompile.
1168 (sequence unsigned-byte
1169 &key
(:initial-element t
) (:initial-contents sequence
))
1170 (values sequence
&optional
))
1175 &key
(initial-element nil iep
) (initial-contents nil icp
))
1176 (declare (sb-ext:unmuffle-conditions style-warning
))
1177 (declare (ignorable keys initial-element iep initial-contents icp
))
1178 (apply #'sb-sequence
:make-sequence-like sequence length keys
))
1179 (with-test (:name
:bug-458354
)
1180 (assert (equalp #((a b
) (a b
)) (bug-458354 #(1 2) 2 :initial-element
'(a b
)))))
1182 (with-test (:name
:bug-542807
)
1183 (handler-bind ((style-warning #'error
))
1184 (eval '(defstruct bug-542807 slot
)))
1186 (handler-bind ((style-warning (lambda (c)
1188 (eval '(defstruct bug-542807 slot
)))
1190 (every (lambda (x) (typep x
'sb-kernel
:redefinition-with-defun
))
1193 (with-test (:name
:defmacro-not-list-lambda-list
)
1194 (assert-error (eval `(defmacro ,(gensym) "foo"))
1197 (with-test (:name
:bug-308951
)
1201 (when (funcall (eval #'(lambda (x) (eql x
2))) y
)
1202 (defun bug-308951-foo (z)
1203 (incf x
(incf y z
))))))
1204 (defun bug-308951-bar (z)
1207 (assert (= 4 (bug-308951-bar 1))))
1209 (declaim (inline bug-308914-storage
))
1210 (defun bug-308914-storage (x)
1211 (the (simple-array flt
(*)) (bug-308914-unknown x
)))
1213 (with-test (:name
:bug-308914-workaround
)
1214 ;; This used to hang in ORDER-UVL-SETS.
1218 `(lambda (lumps &key cg
)
1219 (let ((nodes (map 'list
(lambda (lump)
1220 (bug-308914-storage lump
))
1222 (setf (aref nodes
0) 2)
1223 (assert (every #'~
= (apply #'concatenate
'list nodes
) '(2 3 6 9)))))
1224 :allow-warnings t
:allow-style-warnings t
))
1226 (error "Hang in ORDER-UVL-SETS?"))))
1228 (declaim (inline inlined-function-in-source-path
))
1229 (defun inlined-function-in-source-path (x)
1232 (with-test (:name
:inlined-function-in-source-path
)
1234 (with-output-to-string (*error-output
*)
1235 (compile nil
`(lambda (x)
1236 (declare (optimize speed
))
1237 (funcall #'inlined-function-in-source-path x
))))))
1239 (assert (search "INLINED-FUNCTION-IN-SOURCE-PATH" output
))
1241 (assert (not (search "DEFINED-FUN" output
)))))
1243 (defmacro bug-795705
()
1246 (with-test (:name
:bug-795705
)
1247 (assert (macro-function 'bug-795705
))
1248 (fmakunbound 'bug-795705
)
1249 (assert (not (macro-function 'bug-795705
))))
1251 (with-test (:name
(load-time-value :type-derivation
))
1252 (let ((name 'load-time-value-type-derivation-test
))
1253 (labels ((funtype (fun)
1254 (sb-kernel:type-specifier
1255 (sb-kernel:single-value-type
1256 (sb-kernel:fun-type-returns
1257 (sb-kernel:specifier-type
1258 (sb-kernel:%simple-fun-type fun
))))))
1259 (test (type1 type2 form value-cell-p
)
1260 (let* ((lambda-form `(lambda ()
1261 (load-time-value ,form
)))
1262 (core-fun (checked-compile lambda-form
))
1263 (core-type (funtype core-fun
))
1264 (defun-form `(defun ,name
()
1265 (load-time-value ,form
)))
1267 (ctu:file-compile
(list defun-form
) :load t
)
1268 (symbol-function name
)))
1269 (file-type (funtype file-fun
)))
1270 (unless (subtypep core-type type1
)
1271 (error "core: wanted ~S, got ~S" type1 core-type
))
1272 (unless (subtypep file-type type2
)
1273 (error "file: wanted ~S, got ~S" type2 file-type
)))))
1275 (test '(integer 11 11) 'number
1278 (test '(integer 4 4) 'unsigned-byte
1280 (test '(integer 10 10) '(integer 10 10) 10 nil
)
1281 (test 'cons
'cons
'(cons t t
) t
))))
1283 (with-test (:name
(load-time-value :errors
))
1284 (multiple-value-bind (warn fail
)
1286 `((defvar *load-time-value-error-value
* 10)
1287 (declaim (fixnum *load-time-value-error-value
*))
1288 (defun load-time-value-error-test-1 ()
1289 (the list
(load-time-value *load-time-value-error-value
*))))
1293 (handler-case (load-time-value-error-test-1)
1295 (and (eql 10 (type-error-datum e
))
1296 (eql 'list
(type-error-expected-type e
)))))
1297 (multiple-value-bind (warn2 fail2
)
1299 `((defun load-time-value-error-test-2 ()
1300 (the list
(load-time-value 10))))
1304 (handler-case (load-time-value-error-test-2)
1306 (and (eql 10 (type-error-datum e
))
1307 (eql 'list
(type-error-expected-type e
))))))
1309 ;;;; tests for compiler output
1310 (with-test (:name
:unexpected-compiler-output
)
1311 (let* ((*error-output
* (make-string-output-stream))
1312 (output (with-output-to-string (*standard-output
*)
1313 (compile-file "compiler-output-test.lisp"
1314 :print nil
:verbose nil
))))
1315 (unless (zerop (length output
))
1316 (error "Unexpected output: ~S" output
))))
1318 (with-test (:name
:bug-493380
)
1319 (flet ((test (forms)
1321 (let ((*debugger-hook
* (lambda (condition if
)
1323 (if (typep condition
'serious-condition
)
1326 (multiple-value-bind (warned failed
) (ctu:file-compile forms
)
1327 (when (and warned failed
)
1329 (assert (eq :failed
(test "(defun")))
1330 (assert (eq :failed
(test "(defun no-pkg::foo ())")))
1331 (assert (eq :failed
(test "(cl:no-such-sym)")))
1332 (assert (eq :failed
(test "...")))))
1334 (defun cmacro-signals-error () :fun
)
1335 (define-compiler-macro cmacro-signals-error
() (error "oops"))
1337 (with-test (:name
:cmacro-signals-error
)
1338 (multiple-value-bind (fun failure-p warnings
)
1339 (checked-compile `(lambda () (cmacro-signals-error))
1340 :allow-failure t
:allow-warnings t
)
1341 (assert (and fun failure-p warnings
))
1342 (assert (eq :fun
(funcall fun
)))))
1344 (defun cmacro-with-simple-key (&key a
)
1345 (format nil
"fun=~A" a
))
1346 (define-compiler-macro cmacro-with-simple-key
(&whole form
&key a
)
1348 (format nil
"cmacro=~A" (eval a
))
1351 (with-test (:name
(:cmacro-with-simple-key
:no-key
))
1352 (let ((fun (checked-compile `(lambda () (cmacro-with-simple-key)))))
1353 (assert (string= "cmacro=NIL" (funcall fun
)))))
1355 (with-test (:name
(:cmacro-with-simple-key
:constant-key
))
1356 (let ((fun (checked-compile `(lambda () (cmacro-with-simple-key :a
42)))))
1357 (assert (string= "cmacro=42" (funcall fun
)))))
1359 (with-test (:name
(:cmacro-with-simple-key
:variable-key
))
1360 (let ((fun (checked-compile `(lambda (x) (cmacro-with-simple-key x
42)))))
1361 (assert (string= "fun=42" (funcall fun
:a
)))))
1363 (defun cmacro-with-nasty-key (&key
((nasty-key var
)))
1364 (format nil
"fun=~A" var
))
1365 (define-compiler-macro cmacro-with-nasty-key
(&whole form
&key
((nasty-key var
)))
1367 (format nil
"cmacro=~A" (eval var
))
1370 (with-test (:name
(:cmacro-with-nasty-key
:no-key
))
1371 (let ((fun (checked-compile `(lambda () (cmacro-with-nasty-key)))))
1372 (assert (string= "cmacro=NIL" (funcall fun
)))))
1374 (with-test (:name
(:cmacro-with-nasty-key
:constant-key
))
1375 ;; This bogosity is thanks to cmacro lambda lists being /macro/ lambda
1377 (let ((fun (checked-compile
1378 `(lambda () (cmacro-with-nasty-key 'nasty-key
42)))))
1379 (assert (string= "fun=42" (funcall fun
)))))
1381 (with-test (:name
(:cmacro-with-nasty-key
:variable-key
))
1382 (let ((fun (checked-compile
1383 `(lambda (nasty-key) (cmacro-with-nasty-key nasty-key
42)))))
1384 (assert (string= "fun=42" (funcall fun
'nasty-key
)))))
1386 (defconstant tricky-key
'tricky-key
)
1387 (defun cmacro-with-tricky-key (&key
((tricky-key var
)))
1388 (format nil
"fun=~A" var
))
1389 (define-compiler-macro cmacro-with-tricky-key
(&whole form
&key
((tricky-key var
)))
1391 (format nil
"cmacro=~A" (eval var
))
1394 (with-test (:name
(:cmacro-with-tricky-key
:no-key
))
1395 (let ((fun (checked-compile
1396 `(lambda () (cmacro-with-tricky-key)))))
1397 (assert (string= "cmacro=NIL" (funcall fun
)))))
1399 (with-test (:name
(:cmacro-with-tricky-key
:constant-quoted-key
))
1400 ;; This bogosity is thanks to cmacro lambda lists being /macro/ lambda
1402 (let ((fun (checked-compile
1403 `(lambda () (cmacro-with-tricky-key 'tricky-key
42)))))
1404 (assert (string= "fun=42" (funcall fun
)))))
1406 (with-test (:name
(:cmacro-with-tricky-key
:constant-unquoted-key
))
1407 (let ((fun (checked-compile
1408 `(lambda () (cmacro-with-tricky-key tricky-key
42)))))
1409 (assert (string= "cmacro=42" (funcall fun
)))))
1411 (with-test (:name
(:cmacro-with-tricky-key
:variable-key
))
1412 (let ((fun (checked-compile
1413 `(lambda (x) (cmacro-with-tricky-key x
42)))))
1414 (assert (string= "fun=42" (funcall fun
'tricky-key
)))))
1416 (defun test-function-983 (x) x
)
1417 (define-compiler-macro test-function-983
(x) x
)
1419 (with-test (:name
:funcall-compiler-macro
)
1424 (funcall (function test-function-983 junk
) 1)))
1426 (sb-c:compiler-error
() t
))))
1428 (defsetf test-984 %test-984
)
1430 (with-test (:name
:setf-function-with-setf-expander
)
1433 (and (defun (setf test-984
) ())
1435 (style-warning () t
)))
1436 (checked-compile `(lambda () #'(setf test-984
))
1437 :allow-style-warnings t
))
1439 (with-test (:name
:compile-setf-function
)
1440 (defun (setf compile-setf
) ())
1441 (assert (equal (compile '(setf compile-setf
))
1442 '(setf compile-setf
))))
1444 (declaim (inline cut-test
))
1446 (cond ((integerp b
) b
)
1450 (with-test (:name
:cut-to-width-bad-constant
)
1451 (assert (= (funcall (checked-compile
1453 (multiple-value-bind (a b
) (values t t
)
1454 (declare (ignore b
))
1455 (mask-field (byte 10 0) (cut-test a
))))))
1458 ;; META: there's a test in compiler.pure.lisp that also tests
1459 ;; interaction of PROGV with (debug 3). These tests should be together.
1460 (with-test (:name
:progv-debug-3
)
1462 (sb-ext:restrict-compiler-policy
'debug
3)
1463 (assert (funcall (checked-compile
1465 (declare (special *v
*))
1469 (sb-ext:restrict-compiler-policy
'debug
0)))
1471 (with-test (:name
:restrict-compiler-policy-result
)
1472 (let ((sb-c::*policy-min
* sb-c
::*policy-min
*)
1473 (sb-c::*policy-max
* sb-c
::*policy-max
*))
1474 (sb-ext:restrict-compiler-policy
'safety
2)
1475 (checked-compile '(lambda () (declare (optimize (safety 0))))))
1476 (let ((sb-c::*policy-min
* sb-c
::*policy-min
*)
1477 (sb-c::*policy-max
* sb-c
::*policy-max
*))
1478 ;; Passing no arguments returns the current quality/value pairs.
1479 (assert (null (sb-ext:restrict-compiler-policy
)))
1480 (let ((res (sb-ext:restrict-compiler-policy
'safety
2)))
1482 (assert (equal res
'((safety .
2)))))
1483 (let ((res (sb-ext:restrict-compiler-policy
'debug
3)))
1484 ;; returns an alist, indeterminate order
1485 (assert (or (equal res
'((safety .
2) (debug .
3)))
1486 (equal res
'((debug .
3) (safety .
2))))))
1487 ;; remove the SAFETY restriction
1488 (let ((res (sb-ext:restrict-compiler-policy
'safety
0)))
1489 (assert (equal res
'((debug .
3)))))
1490 ;; remove the DEBUG restriction
1491 (let ((res (sb-ext:restrict-compiler-policy
'debug
0)))
1492 (assert (null res
)))))
1494 ;;;; tests not in the problem domain, but of the consistency of the
1495 ;;;; compiler machinery itself
1499 ;;; Hunt for wrong-looking things in fundamental compiler definitions,
1500 ;;; and gripe about them.
1502 ;;; FIXME: It should be possible to (1) repair the things that this
1503 ;;; code gripes about, and then (2) make the code signal errors
1504 ;;; instead of just printing complaints to standard output, in order
1505 ;;; to prevent the code from later falling back into disrepair.
1506 (defun grovel-results (function)
1507 (dolist (template (fun-info-templates (info :function
:info function
)))
1508 (when (template-more-results-type template
)
1509 (format t
"~&Template ~A has :MORE results, and translates ~A.~%"
1510 (template-name template
)
1513 (when (eq (template-result-types template
) :conditional
)
1516 (let ((types (template-result-types template
))
1517 (result-type (fun-type-returns (proclaimed-ftype function
))))
1519 ((values-type-p result-type
)
1520 (do ((ltypes (append (args-type-required result-type
)
1521 (args-type-optional result-type
))
1523 (types types
(rest types
)))
1525 (unless (null types
)
1526 (format t
"~&More types than ltypes in ~A, translating ~A.~%"
1527 (template-name template
)
1531 (unless (null ltypes
)
1532 (format t
"~&More ltypes than types in ~A, translating ~A.~%"
1533 (template-name template
)
1536 ((eq result-type
(specifier-type nil
))
1537 (unless (null types
)
1538 (format t
"~&Template ~A returns values for function ~A with RESULT-TYPE NIL.~%"
1539 (template-name template
)
1542 ((/= (length types
) 1)
1543 (format t
"~&Template ~A isn't returning 1 value for ~A.~%"
1544 (template-name template
)
1548 (test-util:with-test
(:name
:identify-suspect-vops
)
1549 (sb-c::call-with-each-globaldb-name
1551 ;; LEGAL-FUN-NAME-P test is necessary, since (INFO :FUNCTION :TYPE)
1552 ;; has a defaulting expression that involves calling FDEFINITION.
1553 (when (and (legal-fun-name-p name
) (proclaimed-ftype name
))
1554 ;; OK, so we have an entry in the INFO database. Now, if ...
1555 (binding* ((info (info :function
:info name
) :exit-if-null
)
1556 (nil (fun-info-templates info
) :exit-if-null
))
1557 ;; ... it has translators
1558 (grovel-results name
))))))
1560 ;;;; bug 305: INLINE/NOTINLINE causing local ftype to be lost
1562 (test-util:with-test
(:name
(compile inline notinline
))
1563 (labels ((compile-lambda (type sense allow-notes
)
1565 4 (test-util:checked-compile
1568 ,@(when type
'((ftype (function () (integer 0 10)) bug-305
)))
1572 :allow-style-warnings t
:allow-notes allow-notes
))))
1573 (assert (compile-lambda nil
'inline t
))
1574 (assert (compile-lambda nil
'notinline t
))
1575 (compile-lambda t
'inline nil
)
1576 (compile-lambda t
'notinline nil
)))
1578 ;;; bug 211e: bogus style warning from duplicated keyword argument to
1579 ;;; a local function.
1580 (test-util:with-test
(:name
(compile flet
:duplicate
&key
:bug-211e
))
1581 (let ((f (test-util:checked-compile
1583 (flet ((foo (&key y
) (list y
)))
1584 (list (foo :y
1 :y
2)))))))
1585 (assert (equal '((1)) (funcall f
)))))
1587 ;;; check that EQL is optimized when other argument is (OR SYMBOL FIXNUM).
1588 (test-util:with-test
(:name
(compile :optimize eql
))
1589 (let ((f1 (test-util:checked-compile
1591 (declare (type (or symbol fixnum
) x1
)
1595 (f2 (test-util:checked-compile
1597 (declare (type (or symbol fixnum
) y2
)
1601 (let ((fix (random most-positive-fixnum
))
1604 (assert (funcall f1 fix fix
))
1605 (assert (funcall f2 fix fix
))
1606 (assert (funcall f1 sym sym
))
1607 (assert (funcall f2 sym sym
))
1608 (handler-bind ((type-error (lambda (c)
1611 (flet ((test (f x y
)
1612 (with-simple-restart (continue "continue with next test")
1614 (error "fell through with (~S ~S ~S)" f x y
))))
1616 (test f1
(1+ most-positive-fixnum
) 42)
1618 (test f2
42 (1+ most-positive-fixnum
))))
1619 (assert (= e-count
4)))))
1621 ;;; bug #389 (Rick Taube sbcl-devel)
1622 (defun bes-jn (unn ux
)
1623 (let ((nn unn
) (x ux
))
1624 (let* ((n (floor (abs nn
)))
1637 (do ((tox (/ 2.0 (abs x
)))
1638 (bjm (bes-j0 (abs x
)))
1639 (bj (bes-j1 (abs x
)))
1642 ((= j n
) (setf ans bj
))
1643 (setf bjp
(- (* j tox bj
) bjm
))
1646 (let ((tox (/ 2.0 (abs x
)))
1650 (/ (+ n
(sqrt (* iacc n
)))
1659 (setf bjm
(- (* j tox bj
) bjp
))
1662 (when (> (abs bj
) bigno
)
1663 (setf bj
(* bj bigni
))
1664 (setf bjp
(* bjp bigni
))
1665 (setf ans
(* ans bigni
))
1666 (setf sum
(* sum bigni
)))
1667 (if (not (= 0 jsum
)) (incf sum bj
))
1668 (setf jsum
(- 1 jsum
))
1669 (if (= j n
) (setf ans bjp
)))
1670 (setf sum
(- (* 2.0 sum
) bj
))
1671 (setf ans
(/ ans sum
))))
1672 (if (and (minusp x
) (oddp n
))
1675 (if (and (minusp nn
) (oddp nn
)) (- besn
) besn
))))
1678 ;;; bug 233b: lvar lambda-var equality in constraint propagation
1680 ;; Put this in a separate function.
1681 (defun test-constraint-propagation/ref
()
1683 (if (multiple-value-prog1 x
(setq x t
))
1687 (test-util:with-test
(:name
(:compiler
:constraint-propagation
:ref
))
1688 (assert (eq t
(test-constraint-propagation/ref
))))
1690 ;; Put this in a separate function.
1691 (defun test-constraint-propagation/typep
(x y
)
1692 (if (typep (multiple-value-prog1 x
(setq x y
))
1697 (test-util:with-test
(:name
(:compiler
:constraint-propagation
:typep
))
1698 (assert (= 6.0d0
(test-constraint-propagation/typep
1d0
5))))
1700 (test-util:with-test
(:name
(:compiler
:constraint-propagation
:eq
/eql
))
1701 (assert (eq :right
(let ((c :wrong
))
1702 (if (eq (let ((x c
))
1709 ;;; Put this in a separate function.
1710 (defun test-constraint-propagation/cast
(x)
1711 (when (the double-float
(multiple-value-prog1
1716 (test-util:with-test
(:name
(:compiler
:constraint-propagation
:cast
))
1717 (assertoid:assert-error
1718 (test-constraint-propagation/cast
1) type-error
))
1721 (let ((result (make-array 50000 :fill-pointer
0 :adjustable t
)))
1722 (defun string->html
(string &optional
(max-length nil
))
1723 (when (and (numberp max-length
)
1724 (> max-length
(array-dimension result
0)))
1725 (setf result
(make-array max-length
:fill-pointer
0 :adjustable t
)))
1728 (labels ((add-char (it)
1729 (setf (aref result index
) it
)
1732 (loop for ch across it do
1734 (loop for char across string do
1735 (cond ((char= char
#\
<)
1736 (add-string "<"))
1738 (add-string ">"))
1740 (add-string "&"))
1742 (add-string "'"))
1743 ((char= char
#\newline
)
1744 (add-string "<br>"))
1746 (if left-quote?
(add-string "“") (add-string "”"))
1747 (setf left-quote?
(not left-quote?
)))
1750 (setf (fill-pointer result
) index
)
1751 (coerce result
'string
)))))
1753 ;;; Calling thru constant symbols
1754 (require :sb-introspect
)
1756 (declaim (inline target-fun
))
1757 (defun target-fun (arg0 arg1
)
1759 (declaim (notinline target-fun
))
1761 ;; FIXME: should use compiler-test-util, not sb-introspect here.
1762 ;; That issue aside, neither sb-introspect nor ctu:find-named-callees
1763 ;; can examine an interpreted function for its callees,
1764 ;; so we can't actually use this function.
1765 (defun test-target-fun-called (fun res
)
1766 (assert (member #'target-fun
1767 (sb-introspect:find-function-callees
#'caller-fun-1
)))
1768 (assert (equal (funcall fun
) res
)))
1770 (defun caller-fun-1 ()
1771 (funcall 'target-fun
1 2))
1772 #-interpreter
(test-target-fun-called #'caller-fun-1
3)
1774 (defun caller-fun-2 ()
1775 (declare (inline target-fun
))
1776 (apply 'target-fun
1 '(3)))
1777 #-interpreter
(test-target-fun-called #'caller-fun-2
4)
1779 (defun caller-fun-3 ()
1780 (flet ((target-fun (a b
)
1782 (list (funcall #'target-fun
1 4) (funcall 'target-fun
1 4))))
1783 #-interpreter
(test-target-fun-called #'caller-fun-3
(list -
3 5))
1785 ;;; Reported by NIIMI Satoshi
1786 ;;; Subject: [Sbcl-devel] compilation error with optimization
1787 ;;; Date: Sun, 09 Apr 2006 17:36:05 +0900
1788 (defun test-minimal-debug-info-for-unstored-but-used-parameter (n a
)
1789 (declare (optimize (speed 3)
1793 (test-minimal-debug-info-for-unstored-but-used-parameter (1- n
) a
)))
1795 ;;; &KEY arguments with non-constant defaults.
1796 (declaim (notinline opaque-identity
))
1797 (defun opaque-identity (x) x
)
1798 (defstruct tricky-defaults
1799 (fun #'identity
:type function
)
1800 (num (opaque-identity 3) :type fixnum
))
1801 (macrolet ((frob (form expected-expected-type
)
1802 `(handler-case ,form
1803 (type-error (c) (assert (eq (type-error-expected-type c
)
1804 ',expected-expected-type
)))
1805 (:no-error
(&rest vals
) (error "~S returned values: ~S" ',form vals
)))))
1806 (frob (make-tricky-defaults :fun
3) function
)
1807 (frob (make-tricky-defaults :num
#'identity
) fixnum
))
1809 (test-util:with-test
(:name
(compile &key
:non-constant
:default
))
1810 (let ((fun (test-util:checked-compile
1811 '(lambda (&key
(key (opaque-identity 3)))
1812 (declare (optimize safety
) (type integer key
))
1814 (assert (= (funcall fun
) 3))
1815 (assert (= (funcall fun
:key
17) 17))
1816 (handler-case (funcall fun
:key t
)
1817 (type-error (c) (assert (eq (type-error-expected-type c
) 'integer
)))
1818 (:no-error
(&rest vals
) (declare (ignore vals
)) (error "no error")))))
1820 ;;; Basic compiler-macro expansion
1821 (define-compiler-macro test-cmacro-0
() ''expanded
)
1823 ;; The interpreter is not required to expand compiler-macros.
1824 ;; (Actually neither is the compiler!)
1825 #-interpreter
(assert (eq 'expanded
(funcall (lambda () (test-cmacro-0)))))
1827 ;;; FUNCALL forms in compiler macros, lambda-list parsing
1828 (define-compiler-macro test-cmacro-1
1829 (&whole whole a
(a2) &optional b
&rest c
&key d
)
1830 (list whole a a2 b c d
))
1832 (macrolet ((test (form a a2 b c d
)
1833 `(let ((form ',form
))
1834 (destructuring-bind (whole a a2 b c d
)
1835 (funcall (compiler-macro-function 'test-cmacro-1
) form nil
)
1836 (assert (equal whole form
))
1838 (assert (eql a2
,a2
))
1840 (assert (equal c
,c
))
1841 (assert (eql d
,d
))))) )
1842 (test (funcall 'test-cmacro-1
1 (x) 2 :d
3) 1 'x
2 '(:d
3) 3)
1843 (test (test-cmacro-1 11 (y) 12 :d
13) 11 'y
12 '(:d
13) 13))
1845 ;;; FUNCALL forms in compiler macros, expansions
1846 (define-compiler-macro test-cmacro-2
() ''ok
)
1848 #-interpreter
(assert (eq 'ok
(funcall (lambda () (funcall 'test-cmacro-2
)))))
1849 #-interpreter
(assert (eq 'ok
(funcall (lambda () (funcall #'test-cmacro-2
)))))
1851 ;;; Shadowing of compiler-macros by local functions
1852 (define-compiler-macro test-cmacro-3
() ''global
)
1854 (defmacro find-cmacro-3
(&environment env
)
1855 (compiler-macro-function 'test-cmacro-3 env
))
1857 (assert (funcall (lambda () (find-cmacro-3))))
1858 (assert (not (funcall (lambda () (flet ((test-cmacro-3 ()))
1859 (find-cmacro-3))))))
1860 (assert (eq 'local
(funcall (lambda () (flet ((test-cmacro-3 () 'local
))
1861 (test-cmacro-3))))))
1862 (assert (eq 'local
(funcall (lambda () (flet ((test-cmacro-3 () 'local
))
1863 (funcall #'test-cmacro-3
))))))
1865 (assert (eq 'global
(funcall (lambda () (flet ((test-cmacro-3 () 'local
))
1866 (funcall 'test-cmacro-3
))))))
1868 ;;; Local NOTINLINE & INLINE
1869 (defun test-cmacro-4 () 'fun
)
1870 (define-compiler-macro test-cmacro-4
() ''macro
)
1872 (assert (eq 'fun
(funcall (lambda ()
1873 (declare (notinline test-cmacro-4
))
1877 (assert (eq 'macro
(funcall (lambda ()
1878 (declare (inline test-cmacro-4
))
1881 ;;; SETF function compiler macros
1882 (define-compiler-macro (setf test-cmacro-4
) (&whole form value
) ''ok
)
1885 (assert (eq 'ok
(funcall (lambda () (setf (test-cmacro-4) 'zot
)))))
1887 (assert (eq 'ok
(funcall (lambda () (funcall #'(setf test-cmacro-4
) 'zot
)))))
1889 ;;; Step instrumentation breaking type-inference
1890 (test-util:with-test
(:name
(compile :insert-step-conditions
:type-inference
))
1891 (assert (= 42 (funcall (test-util:checked-compile
1893 (declare (optimize sb-c
:insert-step-conditions
))
1894 (if (typep (the function x
) 'fixnum
)
1895 (svref v
(the function x
))
1897 nil
(constantly 42)))))
1899 ;;; bug 368: array type intersections in the compiler
1903 (i368s (make-array 0 :fill-pointer t
) :type
(or (vector i368
) null
)))
1905 (g368 (error "missing :G368") :type g368
:read-only t
))
1906 (declaim (ftype (function (fixnum (vector i368
) e368
) t
) r368
))
1907 (declaim (ftype (function (fixnum (vector e368
)) t
) h368
))
1908 (defparameter *h368-was-called-p
* nil
)
1909 (defun nsu (vertices e368
)
1910 (let ((i368s (g368-i368s (make-g368))))
1911 (let ((fuis (r368 0 i368s e368
)))
1912 (format t
"~&FUIS=~S~%" fuis
)
1913 (or fuis
(h368 0 i368s
)))))
1915 (declare (ignore w x y
))
1918 (declare (ignore w x
))
1919 (setf *h368-was-called-p
* t
)
1920 (make-s368 :g368
(make-g368)))
1921 (let ((nsu (nsu #() (make-e368))))
1922 (format t
"~&NSU returned ~S~%" nsu
)
1923 (format t
"~&*H368-WAS-CALLED-P*=~S~%" *h368-was-called-p
*)
1924 (assert (s368-p nsu
))
1925 (assert *h368-was-called-p
*))
1927 ;;; bug 367: array type intersections in the compiler
1931 (i367s (make-array 0 :fill-pointer t
) :type
(or (vector i367
) null
)))
1933 (g367 (error "missing :G367") :type g367
:read-only t
))
1934 (declaim (ftype (function ((vector i367
) e367
) (or s367 null
)) r367
))
1935 (declaim (ftype (function ((vector e367
)) (values)) h367
))
1936 (defun frob-367 (v w
)
1937 (let ((x (g367-i367s (make-g367))))
1938 (let* ((y (or (r367 x w
)
1941 (format t
"~&Y=~S Z=~S~%" y z
)
1943 (defun r367 (x y
) (declare (ignore x y
)) nil
)
1944 (defun h367 (x) (declare (ignore x
)) (values))
1945 (assertoid:assert-error
(frob-367 0 (make-e367)) type-error
)
1948 (delete-file (compile-file "circ-tree-test.lisp"))
1949 (storage-condition (e)
1952 ;;; warnings due to step-instrumentation
1953 (defclass debug-test-class
() ())
1954 (test-util:checked-compile
1956 (declare (optimize (debug 3)))
1957 (defmethod print-object ((x debug-test-class
) s
)
1958 (call-next-method))))
1960 ;;; program-error from bad lambda-list keyword
1961 (test-util:with-test
(:name
(compile :bad lambda-list keyword program-error
))
1962 (multiple-value-bind (fun failure-p
)
1963 (test-util:checked-compile
'(lambda (&whole x
)
1967 (assertoid:assert-error
(funcall fun
) program-error
)))
1969 (test-util:with-test
(:name
(eval :bad lambda-list keyword program-error
)
1970 :skipped-on
(not :sb-eval
))
1971 (assertoid:assert-error
(let ((*evaluator-mode
* :interpret
))
1972 (funcall (eval '(lambda (&whole x
)
1976 ;;; ignore &environment
1977 (test-util:with-test
(:name
(defmacro ignore
&environment
))
1978 (test-util:checked-compile
1980 (defmacro macro-ignore-env
(&environment env
)
1981 (declare (ignore env
))
1984 (test-util:with-test
(:name
(defmacro :no
&environment
))
1985 (test-util:checked-compile
1987 (defmacro macro-no-env
()
1990 (test-util:with-test
(:name
(disassemble :source-form
))
1991 (dolist (*evaluator-mode
* '(#+sb-eval
:interpret
:compile
))
1992 (disassemble (eval '(defun disassemble-source-form-bug (x y z
)
1993 (declare (optimize debug
))
1995 :stream
(make-broadcast-stream))))
1997 ;;; long-standing bug in defaulting unknown values on the x86-64,
1998 ;;; since changing the calling convention (test case by Christopher
1999 ;;; Laux sbcl-help 30-06-2007)
2001 (defun default-values-bug-demo-sub ()
2004 (compile 'default-values-bug-demo-sub
)
2006 (defun default-values-bug-demo-main ()
2007 (multiple-value-bind (a b c d e f g h
)
2008 (default-values-bug-demo-sub)
2009 (if a
(+ a b c d e f g h
) t
)))
2010 (compile 'default-values-bug-demo-main
)
2012 (test-util:with-test
(:name
(multiple-value-bind :default-values
))
2013 (assert (default-values-bug-demo-main)))
2015 ;;; copy propagation bug reported by Paul Khuong
2017 (defun local-copy-prop-bug-with-move-arg (x)
2022 (multiple-value-bind (a b
)
2026 (test-util:with-test
(:name
(labels multiple-value-bind
:copy-propagation
))
2027 (assert (equal '(0 1) (multiple-value-list
2028 (local-copy-prop-bug-with-move-arg nil
))))
2029 (assert (equal '(1 0) (multiple-value-list
2030 (local-copy-prop-bug-with-move-arg t
)))))
2032 ;;;; with-pinned-objects & unwind-protect, using all non-tail conventions
2034 (defun wpo-quux () (list 1 2 3))
2035 (defvar *wpo-quux
* #'wpo-quux
)
2039 (sb-sys:with-pinned-objects
(*wpo-quux
*)
2040 (values (funcall *wpo-quux
*)))))
2041 (assert (equal '(1 2 3) (wpo-call)))
2043 (defun wpo-multiple-call ()
2045 (sb-sys:with-pinned-objects
(*wpo-quux
*)
2046 (funcall *wpo-quux
*))))
2047 (assert (equal '(1 2 3) (wpo-multiple-call)))
2049 (defun wpo-call-named ()
2051 (sb-sys:with-pinned-objects
(*wpo-quux
*)
2052 (values (wpo-quux)))))
2053 (assert (equal '(1 2 3) (wpo-call-named)))
2055 (defun wpo-multiple-call-named ()
2057 (sb-sys:with-pinned-objects
(*wpo-quux
*)
2059 (assert (equal '(1 2 3) (wpo-multiple-call-named)))
2061 (defun wpo-call-variable (&rest args
)
2063 (sb-sys:with-pinned-objects
(*wpo-quux
*)
2064 (values (apply *wpo-quux
* args
)))))
2065 (assert (equal '(1 2 3) (wpo-call-variable)))
2067 (defun wpo-multiple-call-variable (&rest args
)
2069 (sb-sys:with-pinned-objects
(*wpo-quux
*)
2070 (apply #'wpo-quux args
))))
2071 (assert (equal '(1 2 3) (wpo-multiple-call-named)))
2073 (defun wpo-multiple-call-local ()
2077 (sb-sys:with-pinned-objects
(*wpo-quux
*)
2079 (assert (equal '(1 2 3) (wpo-multiple-call-local)))
2081 ;;; bug 417: toplevel NIL confusing source path logic
2083 (delete-file (compile-file "bug-417.lisp"))
2084 (sb-ext:code-deletion-note
(e)
2087 ;;; unknown values return convention getting disproportionate
2088 ;;; amounts of values.
2089 (declaim (notinline one-value two-values
))
2090 (defun one-value (x)
2092 (defun two-values (x y
)
2094 (defun wants-many-values (x y
)
2095 (multiple-value-bind (a b c d e f
)
2097 (assert (and (eql (not y
) a
)
2098 (not (or b c d e f
)))))
2099 (multiple-value-bind (a b c d e f
)
2101 (assert (and (eql a x
) (eql b y
)
2102 (not (or c d e f
)))))
2103 (multiple-value-bind (a b c d e f g h i
)
2105 (assert (and (eql (not y
) a
)
2106 (not (or b c d e f g h i
)))))
2107 (multiple-value-bind (a b c d e f g h i
)
2109 (assert (and (eql a x
) (eql b y
)
2110 (not (or c d e f g h i
)))))
2111 (multiple-value-bind (a b c d e f g h i j k l m n o p q r s
)
2113 (assert (and (eql (not y
) a
)
2114 (not (or b c d e f g h i j k l m n o p q r s
)))))
2115 (multiple-value-bind (a b c d e f g h i j k l m n o p q r s
)
2117 (assert (and (eql a x
) (eql b y
)
2118 (not (or c d e f g h i j k l m n o p q r s
))))))
2119 (wants-many-values 1 42)
2121 ;;; constant coalescing
2123 (defun count-code-constants (x f
)
2124 (let ((code (sb-kernel:fun-code-header f
))
2126 (loop for i from sb-vm
:code-constants-offset below
(sb-kernel:code-header-words code
)
2127 do
(when (equal x
(sb-kernel:code-header-ref code i
))
2133 (defun compile2 (lambda)
2134 (let* ((lisp "compiler-impure-tmp.lisp")
2135 (fasl (compile-file-pathname lisp
)))
2138 (with-open-file (f lisp
:direction
:output
)
2139 (prin1 `(setf *lambda
* ,lambda
) f
))
2140 (multiple-value-bind (fasl warn fail
) (compile-file lisp
)
2141 (declare (ignore warn
))
2143 (error "File-compiling ~S failed." lambda
))
2144 (let ((*lambda
* nil
))
2146 (values *lambda
* (test-util:checked-compile lambda
)))))
2147 (ignore-errors (delete-file lisp
))
2148 (ignore-errors (delete-file fasl
)))))
2150 ;; named and unnamed
2151 (defconstant +born-to-coalesce
+ '.born-to-coalesce.
)
2152 (multiple-value-bind (file-fun core-fun
)
2153 (compile2 '(lambda ()
2154 (let ((x (cons +born-to-coalesce
+ nil
))
2155 (y (cons '.born-to-coalesce. nil
)))
2157 (assert (= 1 (count-code-constants '.born-to-coalesce. file-fun
)))
2158 (assert (= 1 (count-code-constants '.born-to-coalesce. core-fun
))))
2160 ;; some things must retain identity under COMPILE, but we want to coalesce them under COMPILE-FILE
2161 (defun assert-coalescing (constant)
2162 (let ((value (copy-seq (symbol-value constant
))))
2163 (multiple-value-bind (file-fun core-fun
)
2164 (compile2 `(lambda ()
2165 (let ((x (cons ,constant nil
))
2166 (y (cons ',value nil
)))
2168 (assert (= 1 (count-code-constants value file-fun
)))
2169 (assert (= 2 (count-code-constants value core-fun
)))
2170 (let* ((l (funcall file-fun
))
2172 (b (car (second l
))))
2173 (assert (and (equal value a
)
2176 (let* ((l (funcall core-fun
))
2178 (b (car (second l
))))
2179 (assert (and (equal value a
)
2181 (not (eq a b
))))))))
2183 (defconstant +born-to-coalesce2
+ "maybe coalesce me!")
2184 (assert-coalescing '+born-to-coalesce2
+)
2186 (defconstant +born-to-coalesce3
+ #*01101001011101110100011)
2187 (assert-coalescing '+born-to-coalesce3
+)
2189 (defconstant +born-to-coalesce4
+ '(foo bar
"zot" 123 (nested "quux") #*0101110010))
2190 (assert-coalescing '+born-to-coalesce4
+)
2192 (defclass some-constant-thing
() ())
2194 ;;; correct handling of nested things loaded via SYMBOL-VALUE
2195 (defvar *sneaky-nested-thing
* (list (make-instance 'some-constant-thing
)))
2196 (defconstant +sneaky-nested-thing
+ *sneaky-nested-thing
*)
2197 (multiple-value-bind (file-fun core-fun
) (compile2 '(lambda () +sneaky-nested-thing
+))
2198 (assert (equal *sneaky-nested-thing
* (funcall file-fun
)))
2199 (assert (equal *sneaky-nested-thing
* (funcall core-fun
))))
2201 ;;; catch constant modifications thru undefined variables
2202 (defun sneak-set-dont-set-me (x)
2203 (ignore-errors (setq dont-set-me x
)))
2204 (defconstant dont-set-me
42)
2205 (assert (not (sneak-set-dont-set-me 13)))
2206 (assert (= 42 dont-set-me
))
2207 (defun sneak-set-dont-set-me2 (x)
2208 (ignore-errors (setq dont-set-me2 x
)))
2209 (defconstant dont-set-me2
(make-instance 'some-constant-thing
))
2210 (assert (not (sneak-set-dont-set-me2 13)))
2211 (assert (typep dont-set-me2
'some-constant-thing
))
2213 ;;; check that non-trivial constants are EQ across different files: this is
2214 ;;; not something ANSI either guarantees or requires, but we want to do it
2216 (defconstant +share-me-1
+ #-inline-constants
123.456d0
#+inline-constants nil
)
2217 (defconstant +share-me-2
+ "a string to share")
2218 (defconstant +share-me-3
+ (vector 1 2 3))
2219 (defconstant +share-me-4
+ (* 2 most-positive-fixnum
))
2220 (multiple-value-bind (f1 c1
) (compile2 '(lambda () (values +share-me-1
+
2224 #-inline-constants pi
)))
2225 (multiple-value-bind (f2 c2
) (compile2 '(lambda () (values +share-me-1
+
2229 #-inline-constants pi
)))
2230 (flet ((test (fa fb
)
2233 (multiple-value-list (funcall fa
))
2234 (multiple-value-list (funcall fb
)))))
2239 ;;; user-defined satisfies-types cannot be folded
2240 (deftype mystery
() '(satisfies mysteryp
))
2241 (defvar *mystery
* nil
)
2242 (defun mysteryp (x) (eq x
*mystery
*))
2243 (defstruct thing
(slot (error "missing") :type mystery
))
2244 (defun test-mystery (m) (when (eq :mystery
(thing-slot m
)) :ok
))
2245 (setf *mystery
* :mystery
)
2246 (assert (eq :ok
(test-mystery (make-thing :slot
:mystery
))))
2248 ;;; Singleton types can also be constant.
2249 (test-util:with-test
(:name
:propagate-singleton-types-to-eql
)
2250 (macrolet ((test (type value
&aux
(fun (gensym "FUN")))
2252 (declaim (ftype (function () (values ,type
&optional
)) ,fun
))
2260 (test (eql foo
) foo
)
2261 (test (integer 0 0) 0)
2262 (test (double-float 0d0
0d0
) 0d0
)
2263 (test (eql #\c
) #\c
))))
2265 (declaim (ftype (function () (integer 42 42)) bug-655581
))
2266 (defun bug-655581 ()
2268 (declaim (notinline bug-655581
))
2269 (test-util:with-test
(:name
:bug-655581
)
2270 (multiple-value-bind (type derived
)
2271 (funcall (test-util:checked-compile
2273 (ctu:compiler-derived-type
(bug-655581)))))
2275 (assert (equal '(integer 42 42) type
))))
2277 (test-util:with-test
(:name
:clear-derived-types-on-set-fdefn
)
2278 (let ((*evaluator-mode
* :compile
)
2279 (*derive-function-types
* t
))
2281 (defun clear-derived-types-on-set-fdefn-1 ()
2283 (setf (symbol-function 'clear-derived-types-on-set-fdefn-1
)
2284 (constantly "foobar"))
2285 (defun clear-derived-types-on-set-fdefn-2 ()
2286 (length (clear-derived-types-on-set-fdefn-1)))))
2287 (assert (= 6 (clear-derived-types-on-set-fdefn-2)))))
2289 (test-util:with-test
(:name
(:bug-655126
:derive-function-types t
))
2290 (let ((*evaluator-mode
* :compile
)
2291 (*derive-function-types
* t
))
2292 (eval `(defun bug-655126 (x) x
))
2293 ;; Full warnings are ok due to *derive-function-types* = T.
2294 (assert (eq :full-warning
2296 (eval `(defun bug-655126-2 ()
2298 ((and warning
(not style-warning
)) ()
2300 (assert (eq 'bug-655126
2302 (eval `(defun bug-655126 (x y
)
2304 ((and warning
(not sb-kernel
:redefinition-warning
)) ()
2306 (assert (eq :full-warning
2308 (eval `(defun bug-655126 (x)
2312 (not sb-kernel
:redefinition-warning
)) ()
2315 (test-util:with-test
(:name
(:bug-655126
:derive-function-types nil
))
2316 (let ((*evaluator-mode
* :compile
))
2317 (eval `(defun bug-655126/b
(x) x
))
2318 ;; Just style-warning here.
2319 (assert (eq :style-warning
2321 (eval `(defun bug-655126-2/b
()
2325 (assert (eq 'bug-655126
/b
2327 (eval `(defun bug-655126/b
(x y
)
2329 ((and warning
(not sb-kernel
:redefinition-warning
)) ()
2331 ;; Bogus self-call is always worth a full one.
2332 (assert (eq :full-warning
2334 (eval `(defun bug-655126/b
(x)
2335 (bug-655126/b x y
)))
2338 (not sb-kernel
:redefinition-warning
)) ()
2341 (test-util:with-test
(:name
:bug-657499
)
2342 ;; Don't trust derived types within the compilation unit.
2344 `((declaim (optimize safety
))
2345 (defun bug-657499-foo ()
2347 (defun bug-657499-bar ()
2348 (let ((cons (bug-657499-foo)))
2352 (locally (declare (optimize safety
))
2353 (setf (symbol-function 'bug-657499-foo
) (constantly "foobar"))
2354 (assert (eq :type-error
2356 (funcall 'bug-657499-bar
)
2358 (assert (eq 'cons
(type-error-expected-type e
)))
2359 (assert (equal "foobar" (type-error-datum e
)))
2362 (declaim (unsigned-byte *symbol-value-test-var
*))
2363 (defvar *symbol-value-test-var
*)
2365 (declaim (unsigned-byte **global-symbol-value-test-var
**))
2366 (defglobal **global-symbol-value-test-var
** 0)
2368 (test-util:with-test
(:name
:symbol-value-type-derivation
)
2372 *symbol-value-test-var
*))))
2373 (assert (equal '(function () (values unsigned-byte
&optional
))
2374 (%simple-fun-type fun
))))
2378 **global-symbol-value-test-var
**))))
2379 (assert (equal '(function () (values unsigned-byte
&optional
))
2380 (%simple-fun-type fun
))))
2383 `(lambda (*symbol-value-test-var
*)
2384 (declare (fixnum *symbol-value-test-var
*))
2385 (symbol-value '*symbol-value-test-var
*))))
2386 (ufix (type-specifier (specifier-type `(and unsigned-byte fixnum
)))))
2387 (assert (equal `(function (,ufix
) (values ,ufix
&optional
))
2388 (%simple-fun-type fun
))))
2392 (declare (fixnum **global-symbol-value-test-var
**))
2393 (symbol-global-value '**global-symbol-value-test-var
**))))
2394 (ufix (type-specifier (specifier-type `(and unsigned-byte fixnum
)))))
2395 (assert (equal `(function () (values ,ufix
&optional
))
2396 (%simple-fun-type fun
)))))
2398 (test-util:with-test
(:name
:mv-bind-to-let-type-propagation
)
2399 (let ((f (test-util:checked-compile
2401 (declare (optimize speed
)
2402 (type (integer 20 50) x
))
2403 (< (truncate x
10) 1))))
2404 (g (test-util:checked-compile
2406 (declare (optimize speed
)
2407 (type (integer 20 50) x
))
2408 (< (nth-value 1 (truncate x
10)) 10))))
2409 (h (test-util:checked-compile
2411 (declare (optimize speed
)
2412 (type (integer 20 50) x
))
2413 (multiple-value-bind (q r
)
2415 (declare (ignore r
))
2417 (type0 '(function ((integer 20 50)) (values null
&optional
)))
2418 (type1 '(function ((integer 20 50)) (values (member t
) &optional
))))
2419 (assert (equal type0
(sb-kernel:%simple-fun-type f
)))
2420 (assert (equal type1
(sb-kernel:%simple-fun-type g
)))
2421 (assert (equal type0
(sb-kernel:%simple-fun-type h
)))))
2423 (test-util:with-test
(:name
:bug-308921
)
2424 (let ((*check-consistency
* t
))
2426 `((let ((exported-symbols-alist
2427 (loop for symbol being the external-symbols of
:cl
2428 collect
(cons symbol
2429 (concatenate 'string
2431 (string-downcase symbol
))))))
2432 (defun hyperdoc-lookup (symbol)
2433 (cdr (assoc symbol exported-symbols-alist
)))))
2436 (test-util:with-test
(:name
:bug-308941
)
2437 (multiple-value-bind (warn fail
)
2438 (let ((*check-consistency
* t
))
2440 "(eval-when (:compile-toplevel :load-toplevel :execute)
2443 (foo #.(make-foo3)))"
2445 ;; ...but the compiler should not break.
2446 (assert (and warn fail
))))
2448 (test-util:with-test
(:name
:bug-903821
)
2449 (let* ((fun (test-util:checked-compile
2451 (declare (sb-ext:word x
)
2452 (type (integer 0 #.
(1- sb-vm
:n-machine-word-bits
)) n
)
2454 (logandc2 x
(ash -
1 n
)))))
2456 (intern (format nil
"ASH-LEFT-MOD~D" sb-vm
::n-machine-word-bits
) "SB-VM")))
2457 (assert (not (member (symbol-function thing-not-to-call
)
2458 (ctu:find-named-callees fun
))))
2459 (assert (= 7 (funcall fun
15 3)))))
2461 (test-util:with-test
(:name
:bug-997528
)
2462 (let ((fun (test-util:checked-compile
2464 (declare (optimize (speed 0) (space 0))
2465 (type (integer -
228645653448155482 -
228645653447928749) x
))
2466 (floor 1.0 (the (integer -
228645653448151677 -
228645653448150900) x
))))))
2467 (multiple-value-bind (quo rem
)
2468 (funcall fun -
228645653448151381)
2470 (assert (= rem
(float -
228645653448151381))))))
2472 (defmacro def-many-code-constants
()
2473 `(defun many-code-constants ()
2474 ,@(loop for i from
0 below
1000
2475 collect
`(print ,(format nil
"hi-~d" i
)))))
2477 (test-util:with-test
(:name
:many-code-constants
)
2478 (def-many-code-constants)
2479 (assert (search "hi-999"
2480 (with-output-to-string (*standard-output
*)
2481 (many-code-constants)))))
2483 (test-util:with-test
(:name
:bug-943953
)
2484 ;; we sometimes splice compiler structures like clambda in
2485 ;; source, and our error reporting would happily use that
2487 (let* ((src "bug-943953.lisp")
2488 (obj (compile-file-pathname src
)))
2489 (unwind-protect (compile-file src
)
2490 (ignore-errors (delete-file obj
)))))
2492 (declaim (inline vec-1177703
))
2493 (defstruct (vec-1177703 (:constructor vec-1177703
(&optional x
)))
2494 (x 0.0d0
:type double-float
))
2496 (declaim (inline norm-1177703
))
2497 (defun norm-1177703 (v)
2498 (vec-1177703 (sqrt (vec-1177703-x v
))))
2500 (test-util:with-test
(:name
:bug-1177703
)
2501 (test-util:checked-compile
`(lambda (x)
2502 (norm-1177703 (vec-1177703 x
)))))
2504 (declaim (inline call-1035721
))
2505 (defun call-1035721 (function)
2507 (funcall function x
)))
2509 (declaim (inline identity-1035721
))
2510 (defun identity-1035721 (x)
2513 (test-util:with-test
(:name
:bug-1035721
)
2514 (test-util:checked-compile
2517 (call-1035721 #'identity-1035721
)
2519 (identity-1035721 x
))))))
2521 (test-util:with-test
(:name
:expt-type-derivation-and-method-redefinition
)
2522 (defmethod expt-type-derivation ((x list
) &optional
(y 0.0))
2523 (declare (type float y
))
2525 ;; the redefinition triggers a type lookup of the old
2526 ;; fast-method-function's type, which had a bogus type specifier of
2527 ;; the form (double-float 0) from EXPT type derivation
2528 (defmethod expt-type-derivation ((x list
) &optional
(y 0.0))
2529 (declare (type float y
))
2532 ;; Lp# 1066451 - declarations were either misplaced or dropped
2533 ;; depending on whether the :policy argument was used in DEFTRANSFORM.
2534 ;; That was a bit random. :policy doesn't affect whether decls
2535 ;; are accepted now.
2537 (declare (special randomness-factor
))
2538 (if (constant-lvar-p randomness-factor
)
2539 (format nil
"Weird transform answer is ~D"
2540 (+ (lvar-value randomness-factor
) blah
))))
2541 (defknown weird-fn
(integer symbol
&key
(:magic real
)) t
)
2542 (deftransform weird-fn
((x s
&key
((:magic randomness-factor
)))
2543 (fixnum t
&key
(:magic fixnum
)))
2544 ;; I can't see much use for declarations other than SPECIAL here,
2545 ;; but we shouldn't supposedly allow them and then not handle them right.
2546 (declare (special fred
) (special randomness-factor
) (lvar x s
))
2548 (test-util:with-test
(:name
:deftransform-bug-1066451
)
2549 (let ((f (let ((fred 3))
2550 (declare (special fred
))
2551 (test-util:checked-compile
2552 '(lambda () (weird-fn 2 'foo
:magic
11))))))
2553 (assert (string= (funcall f
)
2554 "Weird transform answer is 14"))))
2556 (defun skip-1-passthrough (a b sb-int
:&more context count
)
2557 (declare (ignore a b
))
2558 (multiple-value-call 'list
2560 (sb-c::%more-arg-values context
1 (1- (truly-the fixnum count
)))
2562 (defun skip-2-passthrough (a b sb-int
:&more context count
)
2563 (declare (ignore a b
))
2564 (multiple-value-call 'list
2566 (sb-c::%more-arg-values context
2 (- (truly-the fixnum count
) 2))
2568 (defun skip-n-passthrough (n-skip n-copy sb-int
:&more context count
)
2569 (assert (>= count
(+ n-copy n-skip
))) ; prevent crashes
2570 (multiple-value-call 'list
2572 (sb-c::%more-arg-values context n-skip n-copy
)
2575 ;; %MORE-ARG-VALUES was wrong on x86 and x86-64 with nonzero 'skip'.
2576 ;; It's entirely possible that other backends are also not working.
2577 (test-util:with-test
(:name
:more-arg-fancy
2578 :skipped-on
:interpreter
)
2579 (assert (equal (skip-1-passthrough 0 0 'a
'b
'c
'd
'e
'f
)
2580 '(start b c d e f end
)))
2581 (assert (equal (skip-2-passthrough 0 0 'a
'b
'c
'd
'e
'f
)
2582 '(start c d e f end
)))
2583 (assert (equal (skip-n-passthrough 1 5 'a
'b
'c
'd
'e
'f
)
2584 '(start b c d e f end
)))
2585 (assert (equal (skip-n-passthrough 1 5 'a
'b
'c
'd
'e
'f
'g
)
2586 '(start b c d e f end
)))
2587 (assert (equal (skip-n-passthrough 2 5 'a
'b
'c
'd
'e
'f
'g
)
2588 '(start c d e f g end
)))
2589 (assert (equal (skip-n-passthrough 2 5 'a
'b
'c
'd
'e
'f
'g
'h
)
2590 '(start c d e f g end
))))
2592 (test-util:with-test
(:name
:macro-policy
)
2593 (flet ((count-notes ()
2595 (handler-bind ((compiler-note
2600 (multiple-value-bind (fasl warnings errors
)
2601 (compile-file "macro-policy-test.lisp"
2602 :print nil
:verbose nil
)
2603 (ignore-errors (delete-file fasl
))
2604 (assert (and (not warnings
) (not errors
)))
2606 (let* ((baseline (count-notes))
2607 (test (progv '(*frob-macro-policy
*) '(t) (count-notes)))
2608 (baseline-again (count-notes)))
2609 (assert (/= 0 baseline
))
2611 ;; macro-policy is rebound inside compile-file
2612 (assert (= baseline-again baseline
)))))
2614 (in-package :cl-user
)
2616 (with-test (:name
:merge-lambdas-dead-return
)
2617 (let ((fasl (compile-file "merge-lambdas.lisp"
2618 :print nil
:verbose nil
)))
2619 (ignore-errors (delete-file fasl
))))
2621 (declaim (inline ensure-a-fun
))
2622 (defun ensure-a-fun (f) (coerce f
'function
))
2623 (defmacro compose2
(f g
)
2624 `(let ((f (ensure-a-fun ,f
))
2625 (g (ensure-a-fun ,g
)))
2626 (lambda (arg) (funcall f
(funcall g arg
)))))
2628 (with-test (:name
:coerce-to-function-smarter
)
2629 (let ((f (checked-compile
2631 (funcall (compose2 #'integerp
#'car
) x
)))))
2632 ;; should be completely inlined
2633 (assert (null (ctu:find-named-callees f
)))))
2635 (with-test (:name
:derived-function-type-casts
)
2636 (let ((fasl (compile-file "derived-function-type-casts.lisp"
2637 :print nil
:verbose nil
)))
2639 (ignore-errors (delete-file fasl
))
2640 (assert (null (funcall 'derived-function-type-casts
)))))
2642 (with-test (:name
(compile function
:invalid-function-name
))
2643 (flet ((test-case (nameoid)
2645 1 (checked-compile `(lambda () (function ,nameoid
))
2646 :allow-failure t
)))))
2649 (test-case '(foo bar
))))
2651 (defun catch-compiled-program-error (form &rest args
)
2652 (multiple-value-bind (function failure-p
)
2653 (checked-compile form
:allow-failure t
:allow-warnings t
)
2655 (assert-error (apply function args
))))
2657 (with-test (:name
:duplicate-
&key-no-error
)
2658 (catch-compiled-program-error
2659 '(lambda () (defun duplicate-&key-no-error
(&key a a
) a
))))
2661 (with-test (:name
:bad-type-specifiers
)
2662 (catch-compiled-program-error
2663 '(lambda (x) (typep x
'(values 10)))
2665 (catch-compiled-program-error
2666 '(lambda () (declare (sb-ext:muffle-conditions
10)))))
2668 (with-test (:name
:coverage-and-errors
)
2670 '((locally (declare (optimize sb-c
:store-coverage-data
))
2673 (symbol-macrolet ((x 30))
2674 (macrolet ((foo (y) (+ x y
)))
2675 (declaim (inline environment-around-inline
))
2676 (defun environment-around-inline (z)
2679 (with-test (:name
:environment-around-inline
)
2680 (defun environment-around-inline.2 (z)
2681 (environment-around-inline z
))
2682 (assert (= (environment-around-inline.2 10) 340)))
2684 (with-test (:name
:defun-setf-return-value
)
2685 (let ((name `(setf ,(gensym))))
2686 (assert (equal (eval `(defun ,name
()))
2689 (with-test (:name
:make-sequence-unknown
)
2690 (let ((fun (checked-compile
2692 (let ((vector (make-sequence '(simple-array make-sequence-unknown
(*)) 10)))
2693 (setf (aref vector
0) x
)
2695 :allow-style-warnings t
)))
2696 (deftype make-sequence-unknown
() 'fixnum
)
2697 (assert-error (funcall fun
'abc
) type-error
)))
2699 (with-test (:name
(:compiler-messages function
:type-specifier
))
2700 ;; Previously, function types were often printed confusingly, e.g.:
2702 ;; (function ()) => #'NIL
2703 ;; (function *) => #'*
2704 ;; (function (function a)) => #'#'A
2706 (flet ((test-case (spec)
2707 (destructuring-bind (type expected
) spec
2710 (proclaim '(ftype (function () boolean
) my-function
))
2711 (handler-bind ((warning
2713 (setf report
(princ-to-string condition
))
2715 (proclaim `(ftype ,type my-function
)))
2716 (assert (search expected report
)))
2717 (fmakunbound 'my-function
)))))
2720 `(((function ()) "(FUNCTION NIL)")
2721 ((function *) "(FUNCTION *)")
2722 ((function (function *)) "(FUNCTION (FUNCTION *))")
2723 ((function (function (eql 1))) "(FUNCTION (FUNCTION (EQL 1))")))))
2725 (with-test (:name
:boxed-ref-setf-special
)
2726 (let* ((var (gensym))
2727 (fun (checked-compile `(lambda ()
2728 (declare (special ,var
))
2729 (setf ,var
10d0
)))))
2730 (ctu:assert-no-consing
(funcall fun
))))
2732 (with-test (:name
:boxed-ref-bind-special
)
2733 (let* ((var (gensym))
2734 (fun (checked-compile `(lambda ()
2736 (declare (special ,var
)))))))
2737 (ctu:assert-no-consing
(funcall fun
))))
2739 (with-test (:name
:boxed-ref-svref
)
2740 (let ((fun (checked-compile `(lambda (x)
2741 (setf (svref x
0) 10d0
))))
2742 (vector (vector nil
)))
2743 (ctu:assert-no-consing
(funcall fun vector
))))
2745 (with-test (:name
:boxed-ref-instance-set
)
2746 (let* ((name (gensym "STRUCT"))
2748 (eval `(defstruct ,name x
))
2749 (checked-compile `(lambda (x)
2750 (setf (,(sb-int:symbolicate name
'-x
) x
)
2752 (instance (funcall (sb-int:symbolicate
'make- name
))))
2753 (ctu:assert-no-consing
(funcall fun instance
))))
2755 (with-test (:name
:boxed-ref-car
)
2756 (let ((fun (checked-compile `(lambda (x)
2758 (setf (cdr x
) 10d0
))))
2760 (ctu:assert-no-consing
(funcall fun list
))))