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
16 base_tmpfilename="compiler-test-$$-tmp"
17 tmpfilename="$base_tmpfilename.lisp"
18 compiled_tmpfilename="$base_tmpfilename.fasl"
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, as we define a function multiply in the same file
31 cat > $tmpfilename <<EOF
33 (defun foo (x) (list x))
34 (defun foo (x) (cons x x))
36 expect_failed_compile $tmpfilename
38 # This shouldn't fail, as the inner FLETs should not be treated as
39 # having the same name.
40 cat > $tmpfilename <<EOF
43 (flet ((baz (y) (load y)))
44 (declare (notinline baz))
47 (flet ((baz (y) (load y)))
48 (declare (notinline baz))
51 expect_clean_compile $tmpfilename
53 # This shouldn't fail despite the apparent type mismatch, because of
54 # the NOTINLINE declamation.
55 cat > $tmpfilename <<EOF
57 (defun foo (x) (list x))
58 (declaim (notinline foo))
59 (defun bar (x) (1+ (foo x)))
61 expect_clean_compile $tmpfilename
63 # This shouldn't fail despite the apparent type mismatch, because of
64 # the NOTINLINE declaration.
65 cat > $tmpfilename <<EOF
67 (defun foo (x) (list x))
69 (declare (notinline foo))
72 expect_clean_compile $tmpfilename
74 # This in an ideal world would fail (that is, return with FAILURE-P
75 # set), but at present it doesn't.
76 cat > $tmpfilename <<EOF
78 (defun foo (x) (list x))
80 (declare (notinline foo))
82 (declare (inline foo))
85 # expect_failed_compile $tmpfilename
87 # This used to not warn, because the VALUES derive-type optimizer was
88 # insufficiently precise.
89 cat > $tmpfilename <<EOF
91 (defun foo (x) (declare (ignore x)) (values))
92 (defun bar (x) (1+ (foo x)))
94 expect_failed_compile $tmpfilename
96 # Even after making the VALUES derive-type optimizer more precise, the
97 # following should still be clean.
98 cat > $tmpfilename <<EOF
100 (defun foo (x) (declare (ignore x)) (values))
101 (defun bar (x) (car x))
103 expect_clean_compile $tmpfilename
105 # NOTINLINE on known functions shouldn't inhibit type inference
106 # (spotted by APD sbcl-devel 2003-06-14)
107 cat > $tmpfilename <<EOF
108 (in-package :cl-user)
110 (declare (notinline list))
113 expect_failed_compile $tmpfilename
115 # ERROR wants to check its format string for sanity...
116 cat > $tmpfilename <<EOF
117 (in-package :cl-user)
122 expect_failed_compile $tmpfilename
124 # ... but it (ERROR) shouldn't complain about being unable to optimize
125 # when it's uncertain about its argument's type
126 cat > $tmpfilename <<EOF
127 (in-package :cl-user)
131 fail_on_compiler_note $tmpfilename
133 # test case from Rudi for some CLOS WARNINGness that shouldn't have
135 cat > $tmpfilename <<EOF
136 (eval-when (:compile-toplevel :load-toplevel :execute)
137 (defstruct buffer-state
140 (defclass buffered-stream-mixin ()
141 ((buffer-state :initform (make-buffer-state))))
143 (defgeneric frob (stream))
144 (defmethod frob ((stream t))
146 (defmethod frob ((stream buffered-stream-mixin))
148 ((index (buffer-state-output-index (slot-value stream 'buffer-state))))
152 expect_clean_compile $tmpfilename
154 # undeclared unbound variables should cause a full warning, as they
155 # invoke undefined behaviour
156 cat > $tmpfilename <<EOF
159 expect_failed_compile $tmpfilename
161 cat > $tmpfilename <<EOF
162 (declaim (special *x*))
165 expect_clean_compile $tmpfilename
167 cat > $tmpfilename <<EOF
168 (defun foo () (declare (special x)) x)
170 expect_clean_compile $tmpfilename
172 # MUFFLE-CONDITIONS tests
173 cat > $tmpfilename <<EOF
175 (declare (muffle-conditions style-warning))
178 expect_clean_compile $tmpfilename
180 cat > $tmpfilename <<EOF
182 (declare (muffle-conditions code-deletion-note))
185 fail_on_compiler_note $tmpfilename
187 cat > $tmpfilename <<EOF
189 (declare (muffle-conditions compiler-note))
190 (declare (optimize speed))
193 fail_on_compiler_note $tmpfilename
195 cat > $tmpfilename <<EOF
196 (declaim (muffle-conditions compiler-note))
198 (declare (optimize speed))
201 fail_on_compiler_note $tmpfilename
203 cat > $tmpfilename <<EOF
204 (declaim (muffle-conditions compiler-note))
206 (declare (unmuffle-conditions compiler-note))
207 (declare (optimize speed))
210 expect_compiler_note $tmpfilename
212 # undefined variable causes a WARNING
213 cat > $tmpfilename <<EOF
214 (declaim (muffle-conditions warning))
215 (declaim (unmuffle-conditions style-warning))
218 expect_clean_compile $tmpfilename
220 # top level LOCALLY behaves nicely
221 cat > $tmpfilename <<EOF
223 (declare (muffle-conditions warning))
226 expect_clean_compile $tmpfilename
228 cat > $tmpfilename <<EOF
230 (declare (muffle-conditions warning))
234 expect_failed_compile $tmpfilename
237 rm $compiled_tmpfilename