3 # This software is part of the SBCL system. See the README file for
6 # While most of SBCL is derived from the CMU CL system, the test
7 # files (like this one) were written from scratch after the fork
10 # This software is in the public domain and is provided with
11 # absolutely no warranty. See the COPYING and CREDITS files for
18 tmpfilename="$TEST_FILESTEM.lisp"
20 # This should fail, as type inference should show that the call to FOO
21 # will return something of the wrong type.
22 cat > $tmpfilename <<EOF
24 (defun foo (x) (list x))
25 (defun bar (x) (1+ (foo x)))
27 expect_failed_compile $tmpfilename
29 # This should fail (but right now we just get a style-warning), as
30 # type inference should show that the call to FOO has a wrong number
32 cat > $tmpfilename <<EOF
34 (defun foo (x) (or x (foo x x)))
36 expect_condition_during_compile style-warning $tmpfilename
38 # This should fail, as we define a function multiply in the same file
40 cat > $tmpfilename <<EOF
42 (defun foo (x) (list x))
43 (defun foo (x) (cons x x))
45 expect_failed_compile $tmpfilename
47 # This shouldn't fail, as the inner FLETs should not be treated as
48 # having the same name.
49 cat > $tmpfilename <<EOF
52 (flet ((baz (y) (load y)))
53 (declare (notinline baz))
56 (flet ((baz (y) (load y)))
57 (declare (notinline baz))
60 expect_clean_compile $tmpfilename
62 # This shouldn't fail because it's not really a multiple definition
63 cat > $tmpfilename <<EOF
65 (eval-when (:compile-toplevel :load-toplevel :execute)
68 expect_clean_compile $tmpfilename
71 cat > $tmpfilename <<EOF
73 (eval-when (:compile-toplevel)
77 expect_clean_compile $tmpfilename
79 # This shouldn't fail despite the apparent type mismatch, because of
80 # the NOTINLINE declamation.
81 cat > $tmpfilename <<EOF
83 (defun foo (x) (list x))
84 (declaim (notinline foo))
85 (defun bar (x) (1+ (foo x)))
87 expect_clean_compile $tmpfilename
89 # This shouldn't fail, but did until sbcl-0.8.10.4x
90 cat > $tmpfilename <<EOF
92 (declaim (inline foo))
96 (list (foo y) (if (> y 1) (funcall (if (> y 0) #'foo #'identity) y))))
98 expect_clean_compile $tmpfilename
100 # This shouldn't fail despite the apparent type mismatch, because of
101 # the NOTINLINE declaration.
102 cat > $tmpfilename <<EOF
103 (in-package :cl-user)
104 (defun foo (x) (list x))
106 (declare (notinline foo))
109 expect_clean_compile $tmpfilename
111 # This in an ideal world would fail (that is, return with FAILURE-P
112 # set), but at present it doesn't.
113 cat > $tmpfilename <<EOF
114 (in-package :cl-user)
115 (defun foo (x) (list x))
117 (declare (notinline foo))
119 (declare (inline foo))
122 # expect_failed_compile $tmpfilename
124 # This used to not warn, because the VALUES derive-type optimizer was
125 # insufficiently precise.
126 cat > $tmpfilename <<EOF
127 (in-package :cl-user)
128 (defun foo (x) (declare (ignore x)) (values))
129 (defun bar (x) (1+ (foo x)))
131 expect_failed_compile $tmpfilename
133 # Even after making the VALUES derive-type optimizer more precise, the
134 # following should still be clean.
135 cat > $tmpfilename <<EOF
136 (in-package :cl-user)
137 (defun foo (x) (declare (ignore x)) (values))
138 (defun bar (x) (car x))
140 expect_clean_compile $tmpfilename
142 # NOTINLINE on known functions shouldn't inhibit type inference
143 # (spotted by APD sbcl-devel 2003-06-14)
144 cat > $tmpfilename <<EOF
145 (in-package :cl-user)
147 (declare (notinline list))
150 expect_failed_compile $tmpfilename
152 # ERROR wants to check its format string for sanity...
153 cat > $tmpfilename <<EOF
154 (in-package :cl-user)
159 expect_failed_compile $tmpfilename
161 # ... but it (ERROR) shouldn't complain about being unable to optimize
162 # when it's uncertain about its argument's type
163 cat > $tmpfilename <<EOF
164 (in-package :cl-user)
168 fail_on_condition_during_compile sb-ext:compiler-note $tmpfilename
170 # test case from Rudi for some CLOS WARNINGness that shouldn't have
172 cat > $tmpfilename <<EOF
173 #+sb-eval (eval-when (:compile-toplevel)
174 (setf sb-ext:*evaluator-mode* :compile))
176 (eval-when (:compile-toplevel :load-toplevel :execute)
177 (defstruct buffer-state
180 (defclass buffered-stream-mixin ()
181 ((buffer-state :initform (make-buffer-state))))
183 (defgeneric frob (stream))
184 (defmethod frob ((stream t))
186 (defmethod frob ((stream buffered-stream-mixin))
188 ((index (buffer-state-output-index (slot-value stream 'buffer-state))))
192 expect_clean_compile $tmpfilename
194 # undeclared unbound variables should cause a full warning, as they
195 # invoke undefined behaviour
196 cat > $tmpfilename <<EOF
199 expect_failed_compile $tmpfilename
201 cat > $tmpfilename <<EOF
202 (declaim (special *x*))
205 expect_clean_compile $tmpfilename
207 cat > $tmpfilename <<EOF
208 (defun foo () (declare (special x)) x)
210 expect_clean_compile $tmpfilename
212 # MUFFLE-CONDITIONS tests
213 cat > $tmpfilename <<EOF
215 (declare (muffle-conditions style-warning))
218 expect_clean_compile $tmpfilename
220 cat > $tmpfilename <<EOF
222 (declare (muffle-conditions code-deletion-note))
225 fail_on_condition_during_compile sb-ext:compiler-note $tmpfilename
227 cat > $tmpfilename <<EOF
229 (declare (muffle-conditions compiler-note))
230 (declare (optimize speed))
233 fail_on_condition_during_compile sb-ext:compiler-note $tmpfilename
235 cat > $tmpfilename <<EOF
236 (declaim (muffle-conditions compiler-note))
238 (declare (optimize speed))
241 fail_on_condition_during_compile sb-ext:compiler-note $tmpfilename
243 cat > $tmpfilename <<EOF
244 (declaim (muffle-conditions compiler-note))
246 (declare (unmuffle-conditions compiler-note))
247 (declare (optimize speed))
250 expect_condition_during_compile sb-ext:compiler-note $tmpfilename
252 # undefined variable causes a WARNING
253 cat > $tmpfilename <<EOF
254 (declaim (muffle-conditions warning))
255 (declaim (unmuffle-conditions style-warning))
258 expect_clean_compile $tmpfilename
260 # top level LOCALLY behaves nicely
261 cat > $tmpfilename <<EOF
263 (declare (muffle-conditions warning))
266 expect_clean_compile $tmpfilename
268 cat > $tmpfilename <<EOF
270 (declare (muffle-conditions warning))
274 expect_failed_compile $tmpfilename
276 # This should fail, and fail nicely -- not eg. loop trying to dump
277 # references to the unbound variable.
278 cat > $tmpfilename <<EOF
279 (defmacro macro-with-unbound-variables (foo)
282 (macro-with-unbound-variables 'xxx)
284 expect_failed_compile $tmpfilename
286 # This should fail, as the MAKE-LOAD-FORM must be used for
287 # externalizing conditions, and the method for CONDITION must signal
289 cat > $tmpfilename <<EOF
290 (defvar *oops* #.(make-condition 'condition))
292 expect_failed_compile $tmpfilename
294 # This should fail, as the MAKE-LOAD-FORM must be used for objects,
295 # and the method for STANDARD.OBJECT is required to signal an error.
296 cat > $tmpfilename <<EOF
297 (defvar *oops* #.(make-instance 'standard-object))
299 expect_failed_compile $tmpfilename
301 # This should be clean
302 cat > $tmpfilename <<EOF
303 (defvar *string* (make-string 10 :element-type 'base-char))
305 expect_clean_compile $tmpfilename
307 # This should style-warn (but not warn or otherwise fail) as the call
308 # to FORMAT has too many arguments, which is bad style but not
310 cat > $tmpfilename <<EOF
312 (format nil "abc~~def" a b))
314 expect_warned_compile $tmpfilename
316 # Tests that destructive-functions on known-constant data cause
317 # compile-time warnings.
318 cat > $tmpfilename <<EOF
319 (let ((string "foo"))
321 (setf string "bar")))
323 expect_clean_compile $tmpfilename
325 cat > $tmpfilename <<EOF
330 expect_clean_compile $tmpfilename
332 cat > $tmpfilename <<EOF
337 expect_clean_compile $tmpfilename
339 cat > $tmpfilename <<EOF
340 (let ((string "foo"))
342 (replace string "bar")))
344 expect_failed_compile $tmpfilename
346 cat > $tmpfilename <<EOF
348 (setf (char "bar" 0) #\1))
350 expect_failed_compile $tmpfilename
352 cat > $tmpfilename <<EOF
353 (let ((foo '(1 2 3)))
357 expect_failed_compile $tmpfilename
359 cat > $tmpfilename <<EOF
364 expect_failed_compile $tmpfilename
366 cat > $tmpfilename <<EOF
367 (declaim (optimize (speed 3) (space 0) (safety 0)))
372 expect_clean_compile $tmpfilename
374 cat > $tmpfilename <<EOF
378 expect_clean_compile $tmpfilename
380 cat > $tmpfilename <<EOF
381 (eval-when (:compile-toplevel :load-toplevel :execute)
383 (defmethod make-load-form ((foo foox) &optional env)
384 (declare (ignore env))
389 expect_clean_compile $tmpfilename
391 cat > $tmpfilename <<EOF
392 (defun something (x) x)
394 (defun something-more (x) x)
396 expect_aborted_compile $tmpfilename
398 cat > $tmpfilename <<EOF
401 expect_clean_cload $tmpfilename
403 cat > $tmpfilename <<EOF
404 (defconstant cl-package (find-package :cl))
405 (defun cl-symbol-p (x)
406 (eq (symbol-package x) cl-package))
408 expect_clean_cload $tmpfilename
410 cat > $tmpfilename <<EOF
411 (and (eval-when (:compile-toplevel) (error "oops AND")))
412 (or (eval-when (:compile-toplevel) (error "oops OR")))
413 (cond (t (eval-when (:compile-toplevel) (error "oops COND"))))
415 expect_clean_cload $tmpfilename
417 # Test correct fasl-dumping of literals in arglist defaulting.
419 cat > $tmpfilename <<EOF
420 (in-package :cl-user)
422 ;; These are CLHS examples from the dictionary entry for MAKE-LOAD-FORM.
423 (eval-when (:compile-toplevel :load-toplevel :execute)
424 (defstruct my-struct a b c)
425 (defmethod make-load-form ((s my-struct) &optional environment)
426 (make-load-form-saving-slots s :environment environment))
427 (defclass my-class ()
428 ((x :initarg :x :reader obj-x)
429 (y :initarg :y :reader obj-y)
430 (dist :accessor obj-dist)))
431 (defmethod make-load-form ((self my-class) &optional environment)
432 (make-load-form-saving-slots self
434 :environment environment)))
436 (defun bar1 (&optional (x #.(make-my-struct)))
439 (defun bar2 (&optional (x #.(make-instance 'my-class)))
442 ;; Packages are externalizable.
443 (defun bar3 (&optional (x #.*package*))
446 (assert (typep (bar1) 'my-struct))
447 (assert (typep (bar2) 'my-class))
448 (assert (eq (bar3) *package*))
451 expect_clean_cload $tmpfilename
453 cat > $tmpfilename <<EOF
454 (in-package :cl-user)
455 (defmacro foo () (error "ERROR at macroexpansion time."))
458 expect_condition_during_compile sb-c:compiler-error $tmpfilename
460 cat > $tmpfilename <<EOF
461 (eval-when (:compile-toplevel)
462 (error "ERROR within EVAL-WHEN."))
464 expect_condition_during_compile sb-c:compiler-error $tmpfilename
466 cat > $tmpfilename <<EOF
467 (defun slot-name-incf (s)
468 (with-slots (no-such-slot) s
469 (incf no-such-slot)))
471 expect_clean_cload $tmpfilename