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
14 # FIXME: the functions below should be in their own file, sourced by
15 # each of the *.test.sh scripts.
17 # Check that compiling and loading the file $1 generates an error
18 # at load time; also that just loading it directly (into the
19 # interpreter) generates an error.
22 # Test compiling and loading.
25 ;;; But loading the file should fail.
26 (multiple-value-bind (value0 value1) (ignore-errors (load *))
27 (assert (null value0))
28 (format t "VALUE1=~S (~A)~%" value1 value1)
29 (assert (typep value1 'error)))
30 (sb-ext:quit :unix-status 52)
33 echo compile-and-load $1 test failed: $?
37 # Test loading into the interpreter.
39 (multiple-value-bind (value0 value1) (ignore-errors (load "$1"))
40 (assert (null value0))
41 (format t "VALUE1=~S (~A)~%" value1 value1)
42 (assert (typep value1 'error)))
43 (sb-ext:quit :unix-status 52)
46 echo load-into-interpreter $1 test failed: $?
51 # Test that a file compiles cleanly, with no ERRORs, WARNINGs or
53 expect_clean_compile ()
56 (multiple-value-bind (pathname warnings-p failure-p)
58 (declare (ignore pathname))
59 (assert (not warnings-p))
60 (assert (not failure-p))
61 (sb-ext:quit :unix-status 52))
64 echo clean-compile $1 test failed: $?
69 expect_warned_compile ()
72 (multiple-value-bind (pathname warnings-p failure-p)
74 (declare (ignore pathname))
76 (assert (not failure-p))
77 (sb-ext:quit :unix-status 52))
80 echo warn-compile $1 test failed: $?
85 expect_failed_compile ()
88 (multiple-value-bind (pathname warnings-p failure-p)
90 (declare (ignore pathname warnings-p))
92 (sb-ext:quit :unix-status 52))
95 echo fail-compile $1 test failed: $?
100 base_tmpfilename="compiler-test-$$-tmp"
101 tmpfilename="$base_tmpfilename.lisp"
102 compiled_tmpfilename="$base_tmpfilename.fasl"
104 # This should fail, as type inference should show that the call to FOO
105 # will return something of the wrong type.
106 cat > $tmpfilename <<EOF
107 (in-package :cl-user)
108 (defun foo (x) (list x))
109 (defun bar (x) (1+ (foo x)))
111 expect_failed_compile $tmpfilename
113 # This should fail, as we define a function multiply in the same file
115 cat > $tmpfilename <<EOF
116 (in-package :cl-user)
117 (defun foo (x) (list x))
118 (defun foo (x) (cons x x))
120 expect_failed_compile $tmpfilename
122 # This shouldn't fail, as the inner FLETs should not be treated as
123 # having the same name.
124 cat > $tmpfilename <<EOF
125 (in-package :cl-user)
127 (flet ((baz (y) (load y)))
128 (declare (notinline baz))
131 (flet ((baz (y) (load y)))
132 (declare (notinline baz))
135 expect_clean_compile $tmpfilename
137 # This shouldn't fail despite the apparent type mismatch, because of
138 # the NOTINLINE declamation.
139 cat > $tmpfilename <<EOF
140 (in-package :cl-user)
141 (defun foo (x) (list x))
142 (declaim (notinline foo))
143 (defun bar (x) (1+ (foo x)))
145 expect_clean_compile $tmpfilename
147 # This shouldn't fail despite the apparent type mismatch, because of
148 # the NOTINLINE declaration.
149 cat > $tmpfilename <<EOF
150 (in-package :cl-user)
151 (defun foo (x) (list x))
153 (declare (notinline foo))
156 expect_clean_compile $tmpfilename
158 # This in an ideal world would fail (that is, return with FAILURE-P
159 # set), but at present it doesn't.
160 cat > $tmpfilename <<EOF
161 (in-package :cl-user)
162 (defun foo (x) (list x))
164 (declare (notinline foo))
166 (declare (inline foo))
169 # expect_failed_compile $tmpfilename
171 # This used to not warn, because the VALUES derive-type optimizer was
172 # insufficiently precise.
173 cat > $tmpfilename <<EOF
174 (in-package :cl-user)
175 (defun foo (x) (declare (ignore x)) (values))
176 (defun bar (x) (1+ (foo x)))
178 expect_failed_compile $tmpfilename
180 # Even after making the VALUES derive-type optimizer more precise, the
181 # following should still be clean.
182 cat > $tmpfilename <<EOF
183 (in-package :cl-user)
184 (defun foo (x) (declare (ignore x)) (values))
185 (defun bar (x) (car x))
187 expect_clean_compile $tmpfilename
189 # NOTINLINE on known functions shouldn't inhibit type inference
190 # (spotted by APD sbcl-devel 2003-06-14)
191 cat > $tmpfilename <<EOF
192 (in-package :cl-user)
194 (declare (notinline list))
197 expect_failed_compile $tmpfilename
200 rm $compiled_tmpfilename