1 ;;;; miscellaneous compiler tests with side effects (e.g. DEFUN
2 ;;;; changing FDEFINITIONs and globaldb stuff)
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; While most of SBCL is derived from the CMU CL system, the test
8 ;;;; files (like this one) were written from scratch after the fork
11 ;;;; This software is in the public domain and is provided with
12 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
13 ;;;; more information.
15 (cl:in-package
:cl-user
)
17 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
19 (use-package "ASSERTOID"))
21 (declaim (optimize (debug 3) (speed 2) (space 1)))
23 ;;; Until version 0.6.9 or so, SBCL's version of Python couldn't do
24 ;;; this correctly, due to the bug patched by Rob MacLachlan on the
25 ;;; cmucl-imp list 2000-06-21, and applied to SBCL by Martin Atzmueller.
26 ;;; (The effectiveness of the test also depends on the implicit
27 ;;; function typing of Python (where DEFUN is like DECLAIM FTYPE),
28 ;;; which violates the ANSI spec, and should be fixed. Once that
29 ;;; unrelated bug is fixed, this code will no longer test the type
30 ;;; inference behavior it's intended to test.)
31 (defun emptyvalues (&rest rest
) (declare (ignore rest
)) (values))
34 (let ((res (emptyvalues)))
35 (unless (typep res
'foo
)
37 (assert (eq (bar) 'expected-value
))
39 (declaim (ftype (function (real) (values integer single-float
)) valuesify
))
42 (coerce x
'single-float
)))
43 (defun exercise-valuesify (x)
44 (multiple-value-bind (i f
) (valuesify x
)
45 (declare (type integer i
))
46 (declare (type single-float f
))
48 (assert (= (exercise-valuesify 1.25) 2.25))
50 ;;; An early version (sbcl-0.6.11.33) of code to check FTYPEs from DEFUN
51 ;;; against DECLAIMed FTYPEs blew up when an FTYPE was DECLAIMed
52 ;;; to be pure FUNCTION, because the internal representation of
53 ;;; FUNCTION itself (as opposed to subtypes of FUNCTION, such as
54 ;;; (FUNCTION () T)) is a BUILT-IN-CLASS object, not a FUN-TYPE
56 (declaim (ftype function i-am-just-a-function
))
57 (defun i-am-just-a-function (x y
) (+ x y
1))
59 ;;; Stig E Sandoe reported in cclan-Bugs-431263 that SBCL couldn't
60 ;;; compile this. sbcl-0.6.12.26 died in CIRCULAR-LIST-P with "The
61 ;;; value \"EST\" is not of type LIST." Dan Barlow fixed it.
63 '((5 "EDT" .
"EST") (6 "CDT" .
"CST") (7 "MDT" .
64 "MST") (8 "PDT" .
"PST")
65 (0 "GMT" .
"GDT") (-2 "MET" .
"MET DST"))
66 "*The string representations of the time zones.")
68 (declaim (optimize (debug 1) (speed 1) (space 1)))
70 ;;; The old CMU CL Python compiler assumed that it was safe to infer
71 ;;; function types (including return types) from function definitions
72 ;;; and then use them to optimize code later [and it was almost
73 ;;; right!]. This is of course bad when functions are redefined. The
74 ;;; problem was fixed in sbcl-0.6.12.57.
87 (assert (eql (bar 11) :real
))
88 (assert (eql (bar -
11) :fixnum
))
89 (setf (symbol-function 'foo
) #'identity
)
90 (assert (eql (bar 11) :fixnum
))
91 (assert (eql (bar -
11.0) :real
))
92 (assert (eql (bar "this is a test") :string
))
93 (assert (eql (bar (make-hash-table)) :t
))
95 ;;; bug reported by Brian Spilsbury sbcl-devel 2001-09-30, fixed by
96 ;;; Alexey Dejneka patch sbcl-devel 2001-10-02
97 (defun pixarray-element-size (pixarray)
98 (let ((eltype (array-element-type pixarray
)))
99 (cond ((eq eltype
'bit
) 1)
101 (eq (first eltype
) 'unsigned-byte
))
104 (error "Invalid pixarray: ~S." pixarray
)))))
105 (assert (eql 1 (pixarray-element-size #*110)))
107 ;;; bug 31 turned out to be a manifestation of non-ANSI array type
108 ;;; handling, fixed by CSR in sbcl-0.7.3.8.
109 (defun array-element-type-handling (x)
110 (declare (optimize safety
))
111 (declare (type (vector cons
) x
))
112 (when (consp (aref x
0))
114 (assert (raises-error?
115 (array-element-type-handling
116 (make-array 3 :element-type t
:initial-element
0))
119 ;;; bug 220: type check inserted after all arguments in MV-CALL caused
120 ;;; failure of stack analysis
121 (defun bug220-helper ()
123 (assert (equal (multiple-value-call #'list
124 (the integer
(bug220-helper))
128 ;;; bug 221: sbcl 0.7.9.13 failed to compile the following function
129 (declaim (ftype (function (fixnum) (values package boolean
)) bug221-f1
))
130 (declaim (ftype (function (t) (values package boolean
)) bug221-f2
))
132 (funcall (if b
#'bug221-f1
#'bug221-f2
) x
))
134 ;;; bug 166: compiler failure
136 (defmethod permanentize ((uustk bug166s
))
137 (flet ((frob (hash-table test-for-deletion
)
139 (obj-entry.stale?
(oe)
140 (destructuring-bind (key . datum
) oe
141 (declare (type simple-vector key
))
142 (deny0 (void? datum
))
143 (some #'stale? key
))))
144 (declare (inline frob obj-entry.stale?
))
145 (frob (uustk.args-hash-
>obj-alist uustk
)
147 (frob (uustk.hash-
>memoized-objs-list uustk
)
151 ;;; bugs 115, 226: compiler failure in lifetime analysis
153 (declare (optimize (speed 2) (debug 3)))
155 (unwind-protect nil
)))
161 (declare (optimize (speed 2) (debug 3)))
171 (declare (optimize (speed 0) (safety 3) (debug 3)))
172 (flet ((safe-format (stream string
&rest r
)
173 (unless (ignore-errors (progn
174 (apply #'format stream string r
)
176 (format stream
"~&foo ~S" string
))))
178 ((eq my-result
:ERROR
)
180 ((ignore-errors (typep condition result
))
181 (safe-format t
"~&bar ~S" result
))
183 (safe-format t
"~&baz ~S (~A) ~S" condition condition result
)))))))
185 ;;; bug 231: SETQ did not check the type of the variable being set
187 (declare (optimize safety
) (type (integer 0 8) x
))
189 (assert (raises-error?
(bug231a-1 8) type-error
))
192 (declare (optimize safety
) (type (integer 0 8) x
))
193 (list (lambda (y) (setq x y
))
195 (destructuring-bind (set get
) (bug231a-2 0)
197 (assert (eql (funcall get
) 8))
198 (assert (raises-error?
(funcall set
9) type-error
))
199 (assert (eql (funcall get
) 8)))
202 (declare (optimize safety
) (type integer x
))
204 (declare (type (real 1) x
))
207 (assert (raises-error?
(bug231b nil
1) type-error
))
208 (assert (raises-error?
(bug231b 0 1.5) type-error
))
209 (assert (raises-error?
(bug231b 0 0) type-error
))
211 ;;; A bug appeared in flaky7_branch. Python got lost in unconverting
212 ;;; embedded tail calls during let-convertion.
213 (defun bug239 (bit-array-2 &optional result-bit-array
)
214 (declare (type (array bit
) bit-array-2
)
215 (type (or (array bit
) (member t nil
)) result-bit-array
))
216 (unless (simple-bit-vector-p bit-array-2
)
218 (lambda (data1 start1
)
220 (lambda (data2 start2
)
222 (lambda (data3 start3
)
223 (declare (ignore start3
))
224 (print (list data1 data2
)))
226 (values bit-array-2
0)))
228 (assert (equal (bug239 (make-array 4 :element-type
'bit
234 (defstruct some-structure a
)
235 (eval-when (:compile-toplevel
)
236 ;; in the big CLASS reorganization in pre8, this would fail with
237 ;; SOME-STRUCTURE-A is not FBOUNDP. Fixed in 0.pre8.64
238 (find-class 'some-structure nil
))
239 (eval-when (:load-toplevel
)
240 (assert (typep (find-class 'some-structure
) 'class
)))
242 (sb-ext:quit
:unix-status
104) ; success