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 ;;; The old CMU CL Python compiler assumed that it was safe to infer
69 ;;; function types (including return types) from function definitions
70 ;;; and then use them to optimize code later. This is of course bad
71 ;;; when functions are redefined. The problem was fixed in
83 (assert (eql (bar 11) :real
))
84 (assert (eql (bar -
11) :fixnum
))
85 (setf (symbol-function 'foo
) #'identity
)
86 (assert (eql (bar 11) :fixnum
))
87 (assert (eql (bar -
11.0) :real
))
88 (assert (eql (bar "this is a test") :string
))
89 (assert (eql (bar (make-hash-table)) :t
))
91 ;;; bug reported by Brian Spilsbury sbcl-devel 2001-09-30, fixed by
92 ;;; Alexey Dejneka patch sbcl-devel 2001-10-02
93 (defun pixarray-element-size (pixarray)
94 (let ((eltype (array-element-type pixarray
)))
95 (cond ((eq eltype
'bit
) 1)
97 (eq (first eltype
) 'unsigned-byte
))
100 (error "Invalid pixarray: ~S." pixarray
)))))
101 (assert (eql 1 (pixarray-element-size #*110)))
103 ;;; bug 31 turned out to be a manifestation of non-ANSI array type
104 ;;; handling, fixed by CSR in sbcl-0.7.3.8.
105 (defun array-element-type-handling (x)
106 (declare (type (vector cons
) x
))
107 (when (consp (aref x
0))
109 (assert (eq (array-element-type-handling
110 (make-array 3 :element-type t
:initial-element
0))
113 ;;; bug 220: type check inserted after all arguments in MV-CALL caused
114 ;;; failure of stack analysis
115 (defun bug220-helper ()
117 (assert (equal (multiple-value-call #'list
118 (the integer
(bug220-helper))
122 ;;; bug 221: sbcl 0.7.9.13 failed to compile the following function
123 (declaim (ftype (function (fixnum) (values package boolean
)) bug221-f1
))
124 (declaim (ftype (function (t) (values package boolean
)) bug221-f2
))
126 (funcall (if b
#'bug221-f1
#'bug221-f2
) x
))
128 ;;; bug 166: compiler failure
130 (defmethod permanentize ((uustk bug166s
))
131 (flet ((frob (hash-table test-for-deletion
)
133 (obj-entry.stale?
(oe)
134 (destructuring-bind (key . datum
) oe
135 (declare (type simple-vector key
))
136 (deny0 (void? datum
))
137 (some #'stale? key
))))
138 (declare (inline frob obj-entry.stale?
))
139 (frob (uustk.args-hash-
>obj-alist uustk
)
141 (frob (uustk.hash-
>memoized-objs-list uustk
)
145 ;;; bugs 115, 226: compiler failure in lifetime analysis
147 (declare (optimize (speed 2) (debug 3)))
149 (unwind-protect nil
)))
155 (declare (optimize (speed 2) (debug 3)))
165 (declare (optimize (speed 0) (safety 3) (debug 3)))
166 (flet ((safe-format (stream string
&rest r
)
167 (unless (ignore-errors (progn
168 (apply #'format stream string r
)
170 (format stream
"~&foo ~S" string
))))
172 ((eq my-result
:ERROR
)
174 ((ignore-errors (typep condition result
))
175 (safe-format t
"~&bar ~S" result
))
177 (safe-format t
"~&baz ~S (~A) ~S" condition condition result
)))))))
179 ;;; bug 231: SETQ did not check the type of the variable being set
181 (declare (optimize safety
) (type (integer 0 8) x
))
183 (assert (raises-error?
(bug231a-1 8) type-error
))
186 (declare (optimize safety
) (type (integer 0 8) x
))
187 (list (lambda (y) (setq x y
))
189 (destructuring-bind (set get
) (bug231a-2 0)
191 (assert (eql (funcall get
) 8))
192 (assert (raises-error?
(funcall set
9) type-error
))
193 (assert (eql (funcall get
) 8)))
196 (declare (optimize safety
) (type integer x
))
198 (declare (type (real 1) x
))
201 (assert (raises-error?
(bug231b nil
1) type-error
))
202 (assert (raises-error?
(bug231b 0 1.5) type-error
))
203 (assert (raises-error?
(bug231b 0 0) type-error
))
205 (sb-ext:quit
:unix-status
104) ; success