Debian Codegraph @

src/tests/normal-tests/compiler.lsp

raw
1 ;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil -*-
2 ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
3
4 ;;;; Author: Juan Jose Garcia-Ripoll
5 ;;;; Created: Fri Apr 14 11:13:17 CEST 2006
6 ;;;; Contains: Compiler regression tests
7
8 (in-package :cl-test)
9
10 (suite 'cmp)
11
12
13 ;; cl-001
14
15 ;;; Date: 09/05/2006
16 ;;; From: Brian Spilsbury
17 ;;; Fixed: 20/05/2006 (Brian Spilsbury)
18 ;;; Description:
19 ;;;
20 ;;; (DEFPACKAGE "FOO" (:USE) (:IMPORT-FROM "CL" "NIL" "T"))
21 ;;; fails to import symbol NIL because IMPORT is invoked as
22 ;;; (IMPORT NIL (find-package "CL")), which does not import
23 ;;; any symbol.
24 ;;;
25 (test cmp.0001.import
26 (defpackage "FOO" (:USE) (:IMPORT-FROM "CL" "NIL" "T"))
27 (multiple-value-bind (symbol access)
28 (find-symbol "NIL" (find-package "FOO"))
29 (is (and (eql symbol NIL)
30 (eql access :INTERNAL))))
31 (delete-package "FOO"))
32
33 ;;; Date: 09/05/2006
34 ;;; From: Brian Spilsbury
35 ;;; Fixed: 20/05/2006 (Brian Spilsbury)
36 ;;; Description:
37 ;;;
38 ;;; Compiled FLET forms failed to shadow global macro definitions, if not
39 ;;; for the compiler, at least for MACRO-FUNCTION and MACROEXPAND[-1]
40 ;;;
41 (test cmp.0002.macro-shadow
42 (with-compiler ("aux-cl-0002.lsp" :load t)
43 '(defmacro foo () 2)
44 '(defmacro bar (symbol &environment env)
45 (and (macro-function symbol env) t))
46 '(defun doit () (flet ((foo () 1)) (bar foo))))
47 (delete-file "aux-cl-0002.lsp")
48 (delete-file (compile-file-pathname "aux-cl-0002" :type :fas))
49 (is-false (doit))
50 (fmakunbound 'doit)
51 (fmakunbound 'bar)
52 (fmakunbound 'foo))
53
54 ;;;
55 ;;; Fixed: 14/06/2006 (juanjo)
56 ;;; Description:
57 ;;;
58 ;;; APROPOS, APROPOS-LIST and HELP* are case sensitive.
59 ;;;
60 (test cmp.0003.apropos
61 (is (equal (apropos-list "bin")
62 (apropos-list "bin"))))
63
64 ;;; Date: 08/07/2006 (Dave Roberts)
65 ;;; Fixed: 02/08/2006 (juanjo)
66 ;;; Description:
67 ;;;
68 ;;; SLIME traps when invoking DESCRIBE. Reason is that STREAMP breaks on
69 ;;; Gray streams.
70 ;;;
71 (test cmp.0004.streamp
72 (is-true (streamp (make-instance 'gray:fundamental-stream))))
73
74 ;;; Date: 02/08/2006 (juanjo)
75 ;;; Description:
76 ;;;
77 ;;; There is a problem with SUBTYPEP and type STREAM
78 ;;;
79 (defclass gray-stream-test (gray:fundamental-character-output-stream) ())
80 (test cmp.0005.subtypep-stream
81 (is (equal (multiple-value-list
82 (subtypep (find-class 'gray:fundamental-stream) 'stream))
83 (list t t)))
84 (is (equal (multiple-value-list
85 (subtypep (find-class 'gray-stream-test) 'stream))
86 (list t t))))
87
88 ;;; Date: 09/07/2006 (Tim S)
89 ;;; Fixed: 09/07/2006 (Tim S)
90 ;;; Description:
91 ;;;
92 ;;; ENOUGH-NAMESTRING provided too large pathnames even when the
93 ;;; pathname was a subdirectory of the default pathname.
94 ;;;
95 ;;; Date: 31/12/2006 (Richard M. Kreuter)
96 ;;; Fixed: 5/1/2007 (Juanjo)
97 ;;; Description:
98 ;;; ENOUGH-NAMESTRING does not simplify the pathname when the
99 ;;; directory matches completely that of the default path.
100 ;;;
101
102
103 (ext:with-clean-symbols (*enough-namestring_tests*)
104 (defvar *enough-namestring_tests*
105 `(("/A/b/C/"
106 ("/A/b/C/drink-up.sot"
107 "/A/b/C/loozer/whiskey.sot"
108 "/A/b/C/loozer/whiskey"
109 "/A/b/whiskey.sot"
110 "/A/"
111 "whiskey.sot"
112 "loozer/whiskey.sot"
113 "C/loozer/whisky.sot"
114 ""))
115 ("A/b/C" ("A/b/C" "A/b/C/loozer" "b/C" "/A/b/C" "/A/" ""))
116 ("/" ("/A/b/C/drink-up.sot" "/A/b/C/" "/A/" ""))
117 ("" ("/A/b/C/drink-up.sot" "/A/b/C/loozer/whiskey.sot"
118 "/A/b/C/loozer/whiskey" "/A/b/whiskey.sot"
119 "/A/" "whiskey.sot" "loozer/whiskey.sot" "C/loozer/whisky.sot"))
120 ("/A/*/C/drink-up.sot"
121 ("/A/*/C/drink-up.sot" "/A/b/C/drink-up.sot" "/A/b/C/loozer/whiskey.*"
122 "/A/b/C/loozer/*.sot" "/A/**/whiskey.sot" ""))
123 ("/A/b/../c/d.sot" ("/A/b/../c/d.sot" "/A/b/../c/D/e.sot"
124 "/A/c/d.sot" "../c/d.sot"
125 "c/e/d.sot"))))
126
127 (test cmp.0006.enough-namestring
128 (labels ((test-path (path defaults)
129 (let* ((e-ns (enough-namestring path defaults))
130 (d1 (pathname-directory path))
131 (d2 (pathname-directory defaults))
132 (d3 (pathname-directory e-ns)))
133 (and (equalp (merge-pathnames e-ns defaults)
134 (merge-pathnames (parse-namestring path nil defaults)
135 defaults))
136 ;; If directories concide, the "enough-namestring"
137 ;; removes the directory. But only if the pathname is
138 ;; absolute.
139 (not (and (equal (first d1) ':absolute)
140 (equalp d1 d2)
141 d3)))))
142 (test-default+paths (default+paths)
143 (let ((defaults (first default+paths))
144 (paths (second default+paths)))
145 (every (lambda (path)
146 (handler-case (test-path path defaults)
147 (error (error) 'NIL)))
148 paths))))
149 (is-true
150 (every #'test-default+paths *enough-namestring_tests*)))))
151
152 ;;; Date: 10/08/2006 (Lars Brinkhoff)
153 ;;; Fixed: 1/09/2006 (juanjo)
154 ;;; Details:
155 ;;;
156 ;;; ADJUST-ARRAY must signal a type error when the value of :FILL-POINTER is
157 ;;; not NIL and the adjustable array does not have a fill pointer
158 ;;;
159 (test cmp.0007.adjustable-array
160 (is (equal
161 (loop for fp in '(nil t) collect
162 (loop for i in '(t nil 0 1 2 3) collect
163 (and
164 (handler-case (adjust-array (make-array 3 :adjustable t :fill-pointer fp) 4
165 :fill-pointer i)
166 (type-error (c) nil)
167 (error (c) t))
168 t)))
169 '((nil t nil nil nil nil) (t t t t t t)))))
170
171 ;;; Date: 09/10/2006 (Dustin Long)
172 ;;; Fixed: 10/10/2006
173 ;;; Description:
174 ;;;
175 ;;; The namestring "." is improperly parsed, getting a file type of ""
176 ;;; Additionally we found it more convenient to have the _last_ dot mark
177 ;;; the file type, so that (pathname-type "foo.mpq.txt") => "txt"
178 ;;;
179
180 (test cmp.0008.parse-namestring
181 (is-false
182 (loop for (namestring name type) in
183 '(("." "." NIL) (".." "." "") (".foo" ".foo" NIL) (".foo.mpq.txt" ".foo.mpq" "txt")
184 ("foo.txt" "foo" "txt") ("foo.mpq.txt" "foo.mpq" "txt"))
185 unless (let ((x (parse-namestring namestring)))
186 (and (equal name (pathname-name x))
187 (equal type (pathname-type x))
188 (equal '() (pathname-directory x))))
189 collect namestring)))
190
191 ;;; Date: 28/09/2006
192 ;;; Fixed: 10/10/2006
193 ;;; Description:
194 ;;;
195 ;;; Nested calls to queue_finalizer trashed the value of cl_core.to_be_finalized
196 ;;; The following code tests that at least three objects are finalized.
197 ;;;
198 ;;; Note: this test fails in multithreaded mode. GC takes too long!
199 (test cmp.0009.finalization
200 (is-equal '(0 1 2 3 4)
201 (let ((all-tags))
202 (flet ((custom-finalizer (tag)
203 #'(lambda (o)
204 (declare (ignore o))
205 (push tag all-tags))))
206 (let ((a '()))
207 (dotimes (i 5)
208 (let ((x (cons i i)))
209 (si::set-finalizer x (custom-finalizer i))
210 (push x a))))
211 ;; mitigate GC slowness
212 (sleep 1)
213 (dotimes (j 100)
214 (dotimes (i 10000)
215 (cons 1.0 1.0))
216 (ext:gc t)))
217 (sort all-tags #'<))))
218
219 ;;; Date: 8/10/2006 (Dustin Long)
220 ;;; Fixed: 10/10/2006 (Dustin Long)
221 ;;; Description:
222 ;;;
223 ;;; Hash table iterators have to check that their argument is
224 ;;; really a hash table.
225 ;;;
226 (test cmp.0010.hash-iterator
227 (is-false
228 (loop for i in *mini-universe*
229 when (and (not (hash-table-p i))
230 (handler-case (progn (loop for k being the hash-keys of i) t)
231 (error (c) nil)))
232 collect (type-of i))))
233
234 ;;; Date: 31/12/2006 (Richard M. Kreuter)
235 ;;; Fixed: 5/1/2007 (Juanjo)
236 ;;; Description:
237 ;;;
238 ;;; The keyword :BACK does not work as expected when creating pathnames
239 ;;; and causes an error when at the beginning: (:RELATIVE :BACK)
240 ;;;
241 (test cmp.0011.make-pathname-with-back
242 (is-false
243 (loop for i from 0 to 200
244 with l = (random 10)
245 with x = (if (zerop l) 0 (random (1+ l)))
246 with y = (if (= l x) 0 (random (- l x)))
247 nconc (let* ((l (loop for i from 0 below l collect (princ-to-string i)))
248 (l2 (append (subseq l 0 y) '("break" :back) (subseq l y nil)))
249 (d1 (list* :absolute (subseq l2 0 x)))
250 (d2 (list* :relative (subseq l2 x nil)))
251 (d3 (list* :absolute l2))
252 (d4 (list* :relative l2))
253 (p1 (handler-case (make-pathname :directory d1)
254 (error (c) nil)))
255 (p2 (handler-case (make-pathname :directory d2)
256 (error (c) nil)))
257 (p3 (handler-case (make-pathname :directory d3)
258 (error (c) nil)))
259 (p4 (handler-case (make-pathname :directory d4)
260 (error (c) nil))))
261 (if (and p1 p2 p3 p4
262 ;; MERGE-PATHNAMES eliminates :BACK
263 (equalp l (rest (pathname-directory (merge-pathnames p2 p1))))
264 ;; MAKE-PATHNAME does not eliminate :BACK
265 (not (equalp l (rest (pathname-directory (make-pathname :directory d3)))))
266 (not (equalp l (rest (pathname-directory (make-pathname :directory d4))))))
267 nil
268 (list (list l d1 d2 d3 d4 l2 x y)))))))
269
270 ;;; Date: 11/03/2007 (Fare)
271 ;;; Fixed: 23/03/2007 (Juanjo)
272 ;;; Description:
273 ;;;
274 ;;; COPY-READTABLE did not copy the entries of the "from" table
275 ;;; when a second argument, i.e. a "destination" table was supplied.
276 ;;;
277 (test cmp.0012.copy-readtable
278 (is-false
279 (let ((from-readtable (copy-readtable))
280 (to-readtable (copy-readtable))
281 (char-list '()))
282 (dotimes (i 20)
283 (let* ((code (+ 32 (random 70)))
284 (c (code-char code)))
285 (push c char-list)
286 (set-macro-character c
287 (eval `(lambda (str ch) ,code))
288 nil
289 from-readtable)))
290 (copy-readtable from-readtable to-readtable)
291 (loop for c in char-list
292 unless (and (eql (char-code c)
293 (let ((*readtable* from-readtable))
294 (read-from-string (string c))))
295 (eq (get-macro-character c from-readtable)
296 (get-macro-character c to-readtable)))
297 collect c))))
298
299 ;;; Date: 05/01/2008 (Anonymous, SF bug report)
300 ;;; Fixed: 06/01/2008 (Juanjo)
301 ;;; Description:
302 ;;;
303 ;;; For a file linked as follows "ln -s //usr/ /tmp/foo",
304 ;;; (truename #p"/tmp/foo") signals an error because //usr is
305 ;;; parsed as a hostname.
306 ;;;
307 #-(or cygwin haiku windows)
308 (test cmp.0013.truename
309 (si:system "rm -rf foo; ln -sf //usr/ foo")
310 (is (equal (namestring (truename "./foo")) "/usr/"))
311 (si::system "rm foo"))
312
313 ;;; Date: 30/08/2008 (Josh Elsasser)
314 ;;; Fixed: 01/09/2008 (Juanjo)
315 ;;; Description:
316 ;;;
317 ;;; Inside the form read by #., recursive definitions a la #n=
318 ;;; and #n# were not properly expanded
319 ;;;
320 (test cmp.0014.sharp-dot
321 (is
322 (equal (with-output-to-string (*standard-output*)
323 (let ((*print-circle* t))
324 (read-from-string "'#.(princ (list '#1=(1 2) '#1#))")))
325 "(#1=(1 2) #1#)")))
326
327 ;;; Date: 30/08/2008 (Josh Elsasser)
328 ;;; Fixed: 30/08/2008 (Josh Elsasser)
329 ;;; Description:
330 ;;;
331 ;;; A setf expansion that produces a form with a macro that also has
332 ;;; its own setf expansion does not giver rise to the right code.
333 ;;;
334 (test cmp.0015.setf-expander
335 (define-setf-expander triple (place &environment env)
336 (multiple-value-bind (dummies vals newval setter getter)
337 (get-setf-expansion place env)
338 (let ((store (gensym)))
339 (values dummies
340 vals
341 `(,store)
342 `(let ((,(car newval) (/ ,store 3)))
343 (triple ,setter))
344 `(progn
345 (triple ,getter))))))
346 (defmacro hidden (val)
347 `(triple ,val))
348 (defmacro triple (val)
349 `(* 3 ,val))
350 (is-true (equalp
351 (eval '(let ((foo 5))
352 (list foo (triple foo) (setf (triple foo) 6) foo (triple foo))))
353 (eval '(let ((foo 5))
354 (list foo (hidden foo) (setf (hidden foo) 6) foo (hidden foo))))))
355 (fmakunbound 'hidden)
356 (fmakunbound 'triple))
357
358 ;;; Date: 17/2/2009
359 ;;; Fixed: 17/2/2009
360 ;;; Description:
361 ;;;
362 ;;; The defstruct form fails with an :include field that overwrites
363 ;;; a slot that is read only.
364 ;;;
365 (defstruct compiler.0016-a (a 1 :read-only t))
366 (defstruct (compiler.0016-b (:include compiler.0016-a (a 2))))
367 (defstruct (compiler.0016-c (:include compiler.0016-a (a 3 :read-only t))))
368 (test cmp.0016.defstruct-include
369 (is-true
370 (handler-case
371 (eval '(defstruct (compiler.0016-d (:include compiler.0016-a (a 2 :read-only nil)))))
372 (error (c) t)))
373 (is (= (compiler.0016-a-a (make-compiler.0016-a)) 1))
374 (is (= (compiler.0016-b-a (make-compiler.0016-b)) 2))
375 (is (= (compiler.0016-c-a (make-compiler.0016-c)) 3))
376 (is-true
377 (handler-case
378 (eval '(setf (compiler.0016-c-a (make-compiler.0016-c)) 3))
379 (error (c) t))))
380
381 ;;; Date: 9/11/2009
382 ;;; Fixed: 9/11/2009
383 ;;; Description:
384 ;;;
385 ;;; LOAD does not work with special files (/dev/null)
386 ;;;
387 (test cmp.0017.load-special
388 (finishes
389 (load #+(or windows mingw32) "NUL"
390 #-(or windows mingw32) "/dev/null")))
391
392 ;;; Date: 16/11/2009 (Gabriel)
393 ;;; Fixed: 20/11/2009 (Juanjo)
394 ;;; Description:
395 ;;;
396 ;;; #= and ## reader macros do not work well with #.
397 ;;;
398 (test cmp.0018.sharp-eq
399 (is
400 (equal (handler-case (values (read-from-string "(#1=(0 1 2) #.(length '#1#))"))
401 (serious-condition (c) nil))
402 '((0 1 2) 3))))
403
404 ;;; Date: 14/11/2009 (M. Mondor)
405 ;;; Fixed: 20/11/2009 (Juanjo)
406 ;;; Description:
407 ;;;
408 ;;; FDEFINITION and SYMBOL-FUNCTION cause SIGSEGV when acting on NIL.
409 ;;;
410 (test cmp.0019.fdefinition
411 (is-true
412 (handler-case (fdefinition nil)
413 (undefined-function (c) t)
414 (serious-condition (c) nil)))
415 (is-true
416 (handler-case (symbol-function nil)
417 (undefined-function (c) t)
418 (serious-condition (c) nil))))
419
420 ;;; Date: 29/11/2009 (P. Costanza)
421 ;;; Fixed: 29/11/2009 (Juanjo)
422 ;;; Description:
423 ;;;
424 ;;; Updating of instances is not triggered by MAKE-INSTANCES-OBSOLETE.
425 ;;;
426 (ext:with-clean-symbols (class-a class-a-b class-a-c class-a-x)
427 (test cmp.0020.make-instances-obsolete
428 (defclass class-a ()
429 ((b :accessor class-a-b :initarg :b)
430 (c :accessor class-a-c :initarg :c)))
431 (let ((instance (make-instance 'class-a :b 2 :c 3))
432 (update-guard nil))
433 (defmethod update-instance-for-redefined-class :before
434 ((instance standard-object) added-slots discarded-slots property-list
435 &rest initargs)
436 (setf update-guard t))
437 (macrolet ((check-situation (change-form trigger-form result doc)
438 `(progn
439 (setf update-guard nil)
440 ,change-form
441 (is (and (null update-guard)
442 (progn ,trigger-form
443 (eq update-guard ,result)))
444 ,doc))))
445 (check-situation
446 (make-instances-obsolete (find-class 'class-a))
447 (class-a-b instance)
448 t
449 "Direct call to MAKE-INSTANCES-OBSOLETE doesn't work.")
450 (check-situation
451 (defclass class-a ()
452 ((b :accessor class-a-b :initarg :b)))
453 (class-a-b instance)
454 t
455 "Removing a slot does not obsolete class instances.")
456 (check-situation
457 (defclass class-a ()
458 ((b :accessor class-a-b :initarg :b)
459 (c :accessor class-a-c :initarg :c)))
460 (class-a-b instance)
461 t
462 "Adding a slot does not obsolete class instances.")
463 (check-situation
464 (defclass class-a ()
465 ((c :accessor class-a-c :initarg :c)
466 (b :accessor class-a-b :initarg :b)))
467 (class-a-b instance)
468 t
469 "Shuffling slots does not obsolete class instances.")
470 (check-situation
471 (defclass class-a ()
472 ((c :accessor class-a-c :initarg :c :allocation :class)
473 (b :accessor class-a-b :initarg :b)))
474 (class-a-b instance)
475 t
476 "Changing slot allocation does not obsolete class instances.")
477 (check-situation
478 (defclass class-a ()
479 ((b :accessor class-a-b :initarg :b)
480 (c :accessor class-a-c :initarg :c)))
481 (class-a-b instance)
482 t
483 "Redefining class does not obsolete class instances.")
484 (check-situation
485 (defclass class-a ()
486 ((b :accessor class-a-b :initarg :b)
487 (c :accessor class-a-c :initarg :c)))
488 (class-a-b instance)
489 nil
490 "Without a change system should not make instances obsolete.")
491 (check-situation
492 (defclass class-a ()
493 ((b :accessor class-a-x :initarg :b)
494 (c :accessor class-a-c :initarg :c)))
495 (class-a-x instance)
496 nil
497 "Changing accessors should not make instances obsolete.")
498 ;; The old accessor is removed (the generic function).
499 (signals error (class-a-b instance)
500 "Reader method is not removed after redefinition.")
501 (is (fboundp 'class-a-b)
502 "Redefining a class removes generic functions.")))))
503
504 ;;; Date: 25/03/2009 (R. Toy)
505 ;;; Fixed: 4/12/2009 (Juanjo)
506 ;;; Description:
507 ;;;
508 ;;; Conversion of rationals into floats is done by truncating, not by
509 ;;; rounding, what implies a loss of accuracy.
510 ;;;
511 (test cmp.0021.ratio-to-float
512 ;; The test builds a ratio which is very close to 1 but which is below it
513 ;; If we truncate instead of rounding the output will not be 1 coerced
514 ;; to that floating point type.
515 (is-false
516 (loop for type in '(short-float single-float double-float long-float)
517 for bits = (float-precision (coerce 1 type))
518 do (loop for i from (+ bits 7) to (+ bits 13)
519 nconc (loop with value = (ash 1 i)
520 with expected = (coerce 1 type)
521 for j from 0 to 10
522 for x = (- value j)
523 for r = (/ (1- x) x)
524 for f1 = (coerce r type)
525 for f2 = (- (coerce (- r) type))
526 unless (and (= f1 expected) (= f2 expected))
527 collect (list type r))))))
528
529 ;;; Date: 06/04/2010 (M. Kocic)
530 ;;; Fixed: 4/12/2009
531 ;;; Description:
532 ;;;
533 ;;; Inspection of structs is broken due to undefined inspect-indent
534 ;;;
535 (ext:with-clean-symbols (st1)
536 (test cmp.0022.inspect-struct
537 (is-true
538 (let ((*query-io* (make-string-input-stream "q
539 ")))
540 (defstruct st1 p1)
541 (let ((v1 (make-st1 :p1 "tttt")))
542 (handler-case (progn (inspect v1) t)
543 (error (c) nil)))))))
544
545
546 ;; cmp-001
547
548 ;;; Date: 12/03/2006
549 ;;; From: Dan Corkill
550 ;;; Fixed: 14/04/2006 (juanjo)
551 ;;; Description:
552 ;;;
553 ;;; The inner RETURN form should return to the outer block.
554 ;;; However, the closure (lambda (x) ...) is improperly translated
555 ;;; by the compiler to (lambda (x) (block nil ...) and thus this
556 ;;; form outputs '(1 2 3 4).
557 ;;;
558 (test cmp.0023.block
559 (is
560 (eql (funcall (cmplambda ()
561 (block nil
562 (funcall 'mapcar
563 #'(lambda (x)
564 (when x (return x)))
565 '(1 2 3 4)))))
566 1)))
567
568 ;;; Fixed: 12/01/2006 (juanjo)
569 ;;; Description:
570 ;;;
571 ;;; COMPILE-FILE-PATHNAME now accepts both :FAS and :FASL as
572 ;;; synonyms.
573 ;;;
574 ;;;
575 (test cmp.0024.pathname
576 (is (equalp (compile-file-pathname "foo" :type :fas)
577 (compile-file-pathname "foo" :type :fasl))))
578
579 ;;; Fixed: 21/12/2005 (juanjo)
580 ;;; Description:
581 ;;;
582 ;;; Compute the path of the intermediate files (*.c, *.h, etc)
583 ;;; relative to that of the fasl or object file.
584 ;;;
585 (ext:with-clean-symbols (foo)
586 (test cmp.0025.paths
587 (let* ((output (compile-file-pathname "tmp/ecl-aux" :type :fasl))
588 #-ecl-bytecmp
589 (h-file (compile-file-pathname output :type :h))
590 #-ecl-bytecmp
591 (c-file (compile-file-pathname output :type :c))
592 #-ecl-bytecmp
593 (data-file (compile-file-pathname output :type :data)))
594 (and
595 (zerop (si::system "rm -rf tmp; mkdir -p tmp"))
596 (null (nth-value 2 (ext:run-program "rm" '("-rf" "tmp"))))
597 (null (nth-value 2 (ext:run-program "mkdir" '("-p" "tmp"))))
598 (is (with-compiler ("aux-compiler.0103-paths.lsp"
599 :output-file output
600 :c-file t :h-file t :data-file t)
601 '(defun foo (x) (1+ x))))
602 (is (probe-file output))
603 #-ecl-bytecmp
604 (is (probe-file c-file))
605 #-ecl-bytecmp
606 (is (probe-file h-file))
607 #-ecl-bytecmp
608 (is (probe-file data-file))
609 (null (nth-value 2 (ext:run-program "rm" '("-rf" "tmp"))))
610 (null (nth-value 2 (ext:run-program "mkdir" '("-p" "tmp"))))
611 (delete-file "aux-compiler.0103-paths.lsp")))))
612
613 ;;; Date: 08/03/2006
614 ;;; From: Dan Corkill
615 ;;; Fixed: 09/03/2006 (juanjo)
616 ;;; Description:
617 ;;;
618 ;;; DEFCONSTANT does not declare the symbol as global and thus the
619 ;;; compiler issues warnings when the symbol is referenced in the
620 ;;; same file in which it is defined as constant.
621 ;;;
622 #-ecl-bytecmp
623 (test cmp.0026.defconstant-warn
624 (is-false
625 (let ((warn nil))
626 (with-dflet ((c::cmpwarn (setf warn t)))
627 (with-compiler ("aux-compiler.0104.lsp")
628 '(defconstant +foo+ (list 1 2 3))
629 '(print +foo+)))
630 (delete-file "aux-compiler.0104.lsp")
631 (delete-file (compile-file-pathname "aux-compiler.0104.lsp" :type :fas))
632 warn)))
633
634 ;;; Date: 16/04/2006
635 ;;; From: Juanjo
636 ;;; Fixed: 16/04/2006 (juanjo)
637 ;;; Description:
638 ;;;
639 ;;; Special declarations should only affect the variable bound and
640 ;;; not their initialization forms. That, even if the variables are
641 ;;; the arguments of a function.
642 ;;;
643 (test cmp.0027.declaration
644 (let ((form '(lambda (y)
645 (flet ((faa (&key (x y))
646 (declare (special y))
647 x))
648 (let ((y 4))
649 (declare (special y))
650 (faa))))))
651 ;; We must test that both the intepreted and the compiled form
652 ;; output the same value.
653 (is (= (funcall (compile 'nil form) 3) 3))
654 (is (= (funcall (coerce form 'function) 3) 3))))
655
656 ;;; Date: 26/04/2006
657 ;;; From: Michael Goffioul
658 ;;; Fixed: ----
659 ;;; Description:
660 ;;;
661 ;;; Functions with more than 64 arguments have to be invoked using
662 ;;; the lisp stack.
663 ;;;
664 (test cmp.0028.call-arguments-limit
665 (let ((form '(lambda ()
666 (list (list
667 'a0 'b0 'c0 'd0 'e0 'f0 'g0 'h0 'i0
668 'j0 'k0 'l0 'm0 'n0 'o0 'p0 'q0
669 'r0 's0 't0 'u0 'v0 'w0 'x0 'y0 'z0
670 'a1 'b1 'c1 'd1 'e1 'f1 'g1 'h1 'i1
671 'j1 'k1 'l1 'm1 'n1 'o1 'p1 'q1
672 'r1 's1 't1 'u1 'v1 'w1 'x1 'y1 'z1
673 'a2 'b2 'c2 'd2 'e2 'f2 'g2 'h2 'i2
674 'j2 'k2 'l2 'm2 'n2 'o2 'p2 'q2
675 'r2 's2 't2 'u2 'v2 'w2 'x2 'y2 'z2
676 'a3 'b3 'c3 'd3 'e3 'f3 'g3 'h3 'i3
677 'j3 'k3 'l3 'm3 'n3 'o3 'p3 'q3
678 'r3 's3 't3 'u3 'v3 'w3 'x3 'y3 'z3
679 'a4 'b4 'c4 'd4 'e4 'f4 'g4 'h4 'i4
680 'j4 'k4 'l4 'm4 'n4 'o4 'p4 'q4
681 'r4 's4 't4 'u4 'v4 'w4 'x4 'y4 'z4
682 'a5 'b5 'c5 'd5 'e5 'f5 'g5 'h5 'i5
683 'j5 'k5 'l5 'm5 'n5 'o5 'p5 'q5
684 'r5 's5 't5 'u5 'v5 'w5 'x5 'y5 'z5
685 'a6 'b6 'c6 'd6 'e6 'f6 'g6 'h6 'i6
686 'j6 'k6 'l6 'm6 'n6 'o6 'p6 'q6
687 'r6 's6 't6 'u6 'v6 'w6 'x6 'y6 'z6)))))
688 (is (equal (funcall (compile 'foo form))
689 (funcall (coerce form 'function))))))
690
691 ;;; Date: 16/05/2005
692 ;;; Fixed: 18/05/2006 (juanjo)
693 ;;; Description:
694 ;;;
695 ;;; The detection of when a lisp constant has to be externalized
696 ;;; using MAKE-LOAD-FORM breaks down with some circular structures
697 ;;;
698 (defclass compiler-test-class ()
699 ((parent :accessor compiler-test-parent :initform nil)
700 (children :initarg :children :accessor compiler-test-children :initform nil)))
701
702 (defmethod make-load-form ((x compiler-test-class) &optional environment)
703 (declare (ignore environment))
704 (values
705 ;; creation form
706 `(make-instance ',(class-of x) :children ',(slot-value x 'children))
707 ;; initialization form
708 `(setf (compiler-test-parent ',x) ',(slot-value x 'parent))))
709
710 (test cmp.0029.circular-load-form
711 (is
712 (equal
713 (loop for object in
714 (let ((l (list 1 2 3)))
715 (list l
716 (subst 3 l l)
717 (make-instance 'compiler-test-class)
718 (subst (make-instance 'compiler-test-class) 3 l)))
719 collect (si::need-to-make-load-form-p object))
720 '(nil nil t t))))
721
722 ;;; Date: 18/05/2005
723 ;;; Fixed: 17/05/2006 (Brian Spilsbury & juanjo)
724 ;;; Description:
725 ;;;
726 ;;; The compiler is not able to externalize constants that have no
727 ;;; printed representation. In that case MAKE-LOAD-FORM should be
728 ;;; used.
729 ;;;
730 ;;;
731 ;;; Date: 2020-02-12
732 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/562
733 ;;; Description:
734 ;;;
735 ;;; Circular structures are not properly initialized because make
736 ;;; and init form order of evaluation is not always correct.
737 (test cmp.0030.make-load-form
738 (multiple-value-bind (file output)
739 (with-compiler ("make-load-form.lsp")
740 "(in-package cl-test)"
741 "(eval-when (:compile-toplevel)
742 (defparameter s4.0030 (make-instance 'compiler-test-class))
743 (defparameter s5.0030 (make-instance 'compiler-test-class))
744 (setf (compiler-test-parent s5.0030) s4.0030)
745 (setf (compiler-test-children s4.0030) (list s5.0030)))"
746 "(defparameter a.0030 '#.s5.0030)"
747 "(defparameter b.0030 '#.s4.0030)"
748 "(defparameter c.0030 '#.s5.0030)"
749 "(defun foo.0030 ()
750 (let ((*print-circle* t))
751 (with-output-to-string (s) (princ '#1=(1 2 3 #.s4.0030 #1#) s))))")
752 (declare (ignore output))
753 (load file)
754 (delete-file "make-load-form.lsp")
755 (delete-file file))
756 (let ((str (foo.0030)))
757 (is (and (search "#1=(1 2 3 #<a CL-TEST::COMPILER-TEST-CLASS" str)
758 (search "> #1#)" str))))
759 (is (eq (compiler-test-parent a.0030) b.0030))
760 (is (eq (first (compiler-test-children b.0030)) a.0030))
761 (is (eq a.0030 c.0030)))
762
763 ;;; Date: 9/06/2006 (Pascal Costanza)
764 ;;; Fixed: 13/06/2006 (juanjo)
765 ;;; Description:
766 ;;;
767 ;;; A MACROLET function creates a set of local macro definitions.
768 ;;; The forms that expand these macros are themselves affected by
769 ;;; enclosing MACROLET and SYMBOL-MACRO definitions:
770 ;;; (defun bar ()
771 ;;; (macrolet ((x () 2))
772 ;;; (macrolet ((m () (x)))
773 ;;; (m))))
774 ;;; (compile 'bar)
775 ;;; (bar) => 2
776 ;;;
777 (ext:with-clean-symbols (bar)
778 (test cmp.0031.macrolet
779 (is (= 2 (progn
780 (defun bar ()
781 (macrolet ((x () 2))
782 (macrolet ((m () (x)))
783 (m))))
784 (compile 'bar)
785 (bar))))
786 (is (= 2 (progn
787 (defun bar ()
788 (symbol-macrolet ((x 2))
789 (macrolet ((m () x))
790 (m))))
791 (compile 'bar)
792 (bar))))))
793
794 ;;; Fixed: 13/06/2006 (juanjo)
795 ;;; Description:
796 ;;;
797 ;;; A MACROLET that references a local variable from the form in
798 ;;; which it appears can cause corruption in the interpreter. We
799 ;;; solve this by signalling errors whenever such reference
800 ;;; happens.
801 ;;;
802 ;;; Additionally MACROLET forms should not see the other macro
803 ;;; definitions on the same form, much like FLET functions cannot
804 ;;; call their siblings.
805 ;;;
806 (ext:with-clean-symbols (compiler-foo)
807 (test cmp.0032.macrolet-2
808 (is-equal '(error 1 error error 6 (7 8) error error)
809 (flet ((eval-with-error (form)
810 (handler-case (eval form)
811 (error (c) 'error))))
812 (let ((faa 1))
813 (declare (special faa))
814 (mapcar #'eval-with-error
815 '((let ((faa 2))
816 (macrolet ((m () faa))
817 (m)))
818 (let ((faa 4))
819 (declare (special faa))
820 (macrolet ((m () faa))
821 (m)))
822 (let ((faa 4))
823 (declare (special compiler-foo))
824 (macrolet ((m () compiler-foo))
825 (m)))
826 (let ((faa 5))
827 (macrolet ((m () compiler-foo))
828 (m)))
829 (macrolet ((compiler-foo () 6))
830 (macrolet ((m () (compiler-foo)))
831 (m)))
832 (macrolet ((f1 () 7)
833 (f2 () 8))
834 ;; M should not see the new definitions F1 and F2
835 (macrolet ((f1 () 9)
836 (f2 () 10)
837 (m () (list 'quote (list (f1) (f2)))))
838 (m)))
839 (flet ((compiler-foo () 1))
840 (macrolet ((m () (compiler-foo)))
841 (m)))
842 (labels ((compiler-foo () 1))
843 (macrolet ((m () (compiler-foo)))
844 (m))))))))
845 (makunbound 'compiler-foo)
846 (fmakunbound 'compiler-foo)))
847
848 ;;; Date: 22/06/2006 (juanjo)
849 ;;; Fixed: 29/06/2006 (juanjo)
850 ;;; Description:
851 ;;;
852 ;;; ECL only accepted functions with less than 65 required
853 ;;; arguments. Otherwise it refused to compile the function. The fix must
854 ;;; respect the limit in the number of arguments passed in the C stack and
855 ;;; use the lisp stack for the other required arguments.
856 ;;;
857 #-ecl-bytecmp
858 (test cmp.0033.c-arguments-limit
859 (is (equal '((10 :ERROR :ERROR) (20 :ERROR :ERROR) (30 :ERROR :ERROR)
860 (40 :ERROR :ERROR) (50 :ERROR :ERROR) (63 :ERROR :ERROR)
861 (64 :ERROR :ERROR) (65 :ERROR :ERROR) (70 :ERROR :ERROR))
862 (mapcar
863 #'(lambda (nargs)
864 (let* ((arg-list (loop for i from 0 below nargs
865 collect (intern (format nil "arg~d" i))))
866 (data (loop for i from 0 below nargs collect i))
867 (lambda-form `(lambda ,arg-list
868 (and (equalp (list ,@arg-list) ',data)
869 ,nargs)))
870 (c:*compile-verbose* nil)
871 (c:*compile-print* nil)
872 (function (compile 'foo lambda-form)))
873 (list (apply function (subseq data 0 nargs))
874 (handler-case (apply function (make-list (1+ nargs)))
875 (error (c) :error))
876 (handler-case (apply function (make-list (1- nargs)))
877 (error (c) :error)))))
878 '(10 20 30 40 50 63 64 65 70)))))
879
880 ;;; Date: 12/07/2008 (Josh Elsasser)
881 ;;; Fixed: 02/08/2008 (Juanjo)
882 ;;; Description:
883 ;;;
884 ;;; ECL fails to properly compute the closure type of a function that
885 ;;; returns a lambda that calls the function itself.
886 ;;;
887 (test cmp.0034.compute-closure
888 (is
889 (with-compiler ("aux-compiler.0103-paths.lsp" :load t)
890 '(defun testfun (outer)
891 (labels ((testlabel (inner)
892 (if inner
893 (testfun-map
894 (lambda (x) (testlabel x))
895 inner))
896 (print outer)))
897 (testlabel outer))))))
898
899 ;;; Date: 02/09/2008 (Josh Elsasser)
900 ;;; Fixed: 12/09/2008 (Josh Elsasser)
901 ;;; Description:
902 ;;;
903 ;;; FTYPE proclamations and declarations do not accept user defined
904 ;;; function types.
905 ;;;
906 (ext:with-clean-symbols (compiler.float-function
907 compiler.float)
908 (test cmp.0035.ftype-user-type
909 (progn
910 (deftype compiler.float-function () '(function (float) float))
911 (deftype compiler.float () 'float)
912 (loop for (type . fails) in
913 '(((function (float) float) . nil)
914 (cons . t)
915 (compiler.float-function . nil)
916 (compiler.float . t))
917 always (let ((form1 `(proclaim '(ftype ,type foo)))
918 (form2 `(cmplambda ()
919 (declare (ftype ,type foo))
920 (foo))))
921 (cond (fails
922 (signals simple-error (eval form1))
923 (signals warning (eval form2)))
924 (:otherwise
925 (finishes (eval form1))
926 (finishes (eval form2)))))))))
927
928 ;;; Date: 01/11/2008 (E. Marsden)
929 ;;; Fixed: 02/11/2008 (Juanjo)
930 ;;; Description:
931 ;;;
932 ;;; When compiled COERCE with type INTEGER may cause double
933 ;;; evaluation of a form.
934 ;;;
935 ;;; ------------------------------------------------------------
936 ;;; Date: 03/11/2008 (E. Marsden)
937 ;;; Fixed: 08/11/2008 (Juanjo)
938 ;;; Description:
939 ;;;
940 ;;; TYPEP, with a real type, produces strange results.
941 ;;;
942 (test cmp.0036.coerce
943 (is-true (= 1
944 (funcall
945 (compile 'foo '(lambda (x)
946 (coerce (shiftf x 2) 'integer)))
947 1)))
948 (is-false (funcall
949 (compile 'foo '(lambda (x)
950 (typep (shiftf x 1) '(real 10 20))))
951 5)))
952
953 ;;; Date: 20/07/2008 (Juanjo)
954 ;;; Fixed: 20/07/2008 (Juanjo)
955 ;;; Description:
956 ;;;
957 ;;; In the new compiler, when compiling LET forms with special variables
958 ;;; the values of the variables are not saved to make the assignments
959 ;;; really parallel.
960 ;;;
961 (test cmp.0037.let-with-specials
962 (is
963 (=
964 7
965 (progn
966 (defvar *stak-x*)
967 (defvar *stak-y*)
968 (defvar *stak-z*)
969 (funcall
970 (compile
971 nil
972 '(lambda (*stak-x* *stak-y* *stak-z*)
973 (labels
974 ((stak-aux ()
975 (if (not (< (the fixnum *stak-y*) (the fixnum *stak-x*)))
976 *stak-z*
977 (let ((*stak-x* (let ((*stak-x* (the fixnum (1- (the fixnum *stak-x*))))
978 (*stak-y* *stak-y*)
979 (*stak-z* *stak-z*))
980 (stak-aux)))
981 (*stak-y* (let ((*stak-x* (the fixnum (1- (the fixnum *stak-y*))))
982 (*stak-y* *stak-z*)
983 (*stak-z* *stak-x*))
984 (stak-aux)))
985 (*stak-z* (let ((*stak-x* (the fixnum (1- (the fixnum *stak-z*))))
986 (*stak-y* *stak-x*)
987 (*stak-z* *stak-y*))
988 (stak-aux))))
989 (stak-aux)))))
990 (stak-aux)))) 18 12 6)))))
991
992 ;;; Date: 06/10/2009 (J. Pellegrini)
993 ;;; Fixed: 06/10/2009 (Juanjo)
994 ;;; Description:
995 ;;; Extended strings were not accepted as documentation by the interpreter.
996 ;;;
997 (ext:with-clean-symbols (foo)
998 (test cmp.0038.docstrings
999 (eval `(defun foo ()
1000 ,(make-array 10 :initial-element #\Space :element-type 'character)
1001 2))
1002 (is (= (eval (funcall 'foo)) 2))))
1003
1004 ;;; Date: 07/11/2009 (A. Hefner)
1005 ;;; Fixed: 07/11/2009 (A. Hefner + Juanjo)
1006 ;;; Description:
1007 ;;; ECL ignores the IGNORABLE declaration
1008 ;;;
1009 (test cmp.0039.ignorable
1010 (let ((c::*suppress-compiler-messages* t))
1011 ;; Issue a warning for unused variables
1012 (is-true
1013 (handler-case (prog1 nil
1014 (cmplambda (x y) (print x)) nil)
1015 (warning (c) t)))
1016 ;; Do not issue a warning for unused variables declared IGNORE
1017 (is-true
1018 (handler-case (prog1 t
1019 (cmplambda (x y)
1020 (declare (ignore y))
1021 (print x)))
1022 (warning (c) nil)))
1023 ;; Do not issue a warning for unused variables declared IGNORABLE
1024 (is-true
1025 (handler-case (prog1 t
1026 (cmplambda (x y)
1027 (declare (ignorable y))
1028 (print x)))
1029 (warning (c) nil)))
1030 ;; Do not issue a warning for used variables declared IGNORABLE
1031 (is-true
1032 (handler-case (prog1 t
1033 (cmplambda (x y)
1034 (declare (ignorable x y))
1035 (print x)))
1036 (warning (c) nil)))))
1037
1038 ;;; Date: 29/11/2009 (P. Costanza)
1039 ;;; Fixed: 29/11/2009 (Juanjo)
1040 ;;; Description:
1041 ;;; When calling a bytecodes (SETF ...) function from a compiled function
1042 ;;; an invalid memory access is produced. This is actually a consequence
1043 ;;; of a mismatch between the position of the fields bytecodes.entry
1044 ;;; and cfun.entry
1045 ;;;
1046 #-ecl-bytecmp
1047 (test cmp.0040.bytecodes-entry-position
1048 (let ((indices (funcall (cmplambda ()
1049 (ffi:c-inline () () list "
1050 union cl_lispunion x[1];
1051 cl_index bytecodes = (char*)(&(x->bytecodes.entry)) - (char*)x;
1052 cl_index bclosure = (char*)(&(x->bclosure.entry)) - (char*)x;
1053 cl_index cfun = (char*)(&(x->cfun.entry)) - (char*)x;
1054 cl_index cfunfixed = (char*)(&(x->cfunfixed.entry)) - (char*)x;
1055 cl_index cclosure = (char*)(&(x->cclosure.entry)) - (char*)x;
1056 @(return) = cl_list(5, MAKE_FIXNUM(bytecodes),
1057 MAKE_FIXNUM(bclosure),
1058 MAKE_FIXNUM(cfun),
1059 MAKE_FIXNUM(cfunfixed),
1060 MAKE_FIXNUM(cclosure));" :one-liner nil)))))
1061 (is-true (apply #'= indices)) t))
1062
1063 ;;; Date: 07/02/2010 (W. Hebich)
1064 ;;; Fixed: 07/02/2010 (Juanjo)
1065 ;;; Description:
1066 ;;; THE forms do not understand VALUES types
1067 ;;; (the (values t) (funcall sym))
1068 ;;;
1069 (test cmp.0041.the-and-values
1070 (is
1071 (handler-case (cmplambda () (the (values t) (faa)))
1072 (warning (c) nil))))
1073
1074
1075 ;;; Date: 28/03/2010 (M. Mondor)
1076 ;;; Fixed: 28/03/2010 (Juanjo)
1077 ;;; Description:
1078 ;;; ECL does not compile type declarations of a symbol macro
1079 ;;;
1080 (test cmp.0042.symbol-macro-declaration
1081 (is
1082 (handler-case (cmplambda (x)
1083 (symbol-macrolet ((y x))
1084 (declare (fixnum y))
1085 (+ y x)))
1086 (warning (c) nil))))
1087
1088 ;;; Date: 24/04/2010 (Juanjo)
1089 ;;; Fixed 24/04/2010 (Juanjo)
1090 ;;; Description:
1091 ;;; New special form, WITH-BACKEND.
1092 ;;;
1093 (ext:with-clean-symbols (*compiler.0122* compiler.0122a)
1094 (defparameter *compiler.0122* nil)
1095 (test cmp.0043.with-backend
1096 ;; we ensure compiler.0122a isn't compiled upfront
1097 (eval '(defun compiler.0122a ()
1098 (ext:with-backend
1099 :bytecodes (setf *compiler.0122* :bytecodes)
1100 :c/c++ (setf *compiler.0122* :c/c++))))
1101 (is-eql :bytecodes
1102 (progn (compiler.0122a)
1103 *compiler.0122*))
1104 (is-eql :bytecodes
1105 (compiler.0122a))
1106 #-ecl-bytecmp
1107 (is-eql :c/c++
1108 (progn (compile 'compiler.0122a)
1109 (compiler.0122a)
1110 *compiler.0122*))
1111 #-ecl-bytecmp
1112 (is-eql :c/c++
1113 (compiler.0122a))))
1114
1115
1116
1117 ;;; Date: 10/08/2008
1118 ;;; From: Juanjo
1119 ;;; Fixed: 10/08/2008
1120 ;;; Description:
1121 ;;;
1122 ;;; COS, SIN and TAN were expanded using a wrong C expression.
1123 ;;;
1124
1125 (test cmp.0044.inline-cos
1126 (is-false
1127 (loop with *compile-verbose* = nil
1128 with *compile-print* = nil
1129 for type in '(short-float single-float double-float long-float)
1130 for sample = (coerce 1.0 type)
1131 for epsilon in '(#.short-float-epsilon #.single-float-epsilon #.double-float-epsilon #.long-float-epsilon)
1132 unless (loop for op in '(sin cos tan sinh cosh tanh)
1133 for f = (compile 'nil `(lambda (x)
1134 (declare (,type x)
1135 (optimize (safety 0)
1136 (speed 3)))
1137 (+ ,sample (,op x))))
1138 always (loop for x from (- pi) below pi by 0.05
1139 for xf = (float x sample)
1140 for error = (- (funcall f xf) (+ 1 (funcall op xf)))
1141 always (< (abs error) epsilon)))
1142 collect type)))
1143
1144
1145
1146 ;;; Description:
1147 ;;;
1148 ;;; The interpreter selectively complains when assigning a variable
1149 ;;; that has not been declared as special and is not local.
1150 ;;;
1151 ;;; Fixed: 03/2006 (juanjo)
1152 ;;;
1153 (test cmp.0045.global-setq
1154 (is (equal
1155 '(:no-error :error)
1156 (mapcar
1157 (lambda (ext:*action-on-undefined-variable*)
1158 (handler-case
1159 (progn (eval `(setq ,(gensym) 1)) :no-error)
1160 (error (c) :error)))
1161 '(nil ERROR)))))
1162
1163 ;;; Date: 24/04/2010 (Juanjo)
1164 ;;; Fixed: 24/04/2010 (Juanjo)
1165 ;;; Description:
1166 ;;; The interpreter does not increase the lexical environment depth when
1167 ;;; optimizing certain forms (LIST, LIST*, CONS...) and thus causes some
1168 ;;; of the arguments to be eagerly evaluated.
1169 ;;;
1170 (test cmp.0046.list-optimizer-error
1171 (is (string-equal
1172 (with-output-to-string (*standard-output*)
1173 (eval '(list (print 1) (progn (print 2) (print 3)))))
1174 "
1175 1
1176 2
1177 3 ")))
1178
1179
1180
1181 ;;; Date: 2015-09-04
1182 ;;; Fixed: Daniel Kochmański
1183 ;;; Description
1184 ;;; Compiler signalled arithmetic-error when producing C code for infinity
1185 ;;; and NaN float values (part of ieee floating point extensions).
1186
1187 #+ieee-floating-point
1188 (test cmp.0047.infinity-test
1189 (finishes
1190 (compile nil
1191 (lambda ()
1192 (> 0.0 ext:single-float-negative-infinity))))
1193 (is-true
1194 (let ((ofile
1195 (with-compiler ("aux-compiler-0048.infty-test.2.lsp" :load t)
1196 '(defun doit () (> 0.0 ext:single-float-negative-infinity)))))
1197 (delete-file "aux-compiler-0048.infty-test.2.lsp")
1198 (delete-file ofile)
1199 (doit))))
1200
1201
1202
1203 ;;; Date: 2015-12-18
1204 ;;; Fixed: Daniel Kochmański
1205 ;;; Description
1206 ;;; Compiler expanded FIND incorrectly (ignored START and END arguments)
1207
1208 (ext:with-clean-symbols (check-single-wildcard)
1209 (test cmp.0048.cmpopt-sequences
1210 (defun check-single-wildcard (identifier wildcard-pos)
1211 (not (find #\* identifier :start (1+ wildcard-pos))))
1212 (is-true (check-single-wildcard "dan*" 3))))
1213
1214 ;;; Date: 2016-02-10
1215 ;;; Fixed: Daniel Kochmański
1216 ;;; Description
1217 ;;; Aux closures created by C compiler weren't handled correctly
1218 ;;; in respect of the environment and declarations of the
1219 ;;; variables
1220 (test cmp.0049.cmptop/call
1221 (finishes
1222 (funcall (cmplambda ()
1223 (labels
1224 ((fun-2 () (fun-3 'cool))
1225 (fun-3 (clause-var)
1226 (flet ((fun-4 () clause-var))
1227 (fun-4))))
1228 (let ((fun-1 (lambda () (fun-2))))
1229 (funcall fun-1)))))))
1230
1231
1232 ;;; Date 2016-04-21
1233 ;;; Fixed: Daniel Kochmański
1234 ;;; Description
1235 ;;; typep didn't recognize * as a t abberv
1236 ;;;
1237 (test cmp.0050.ftype-args*
1238 (declaim (ftype (function (*) (values T)) ce))
1239 (defun ce (expression) expression)
1240 (is-false (ce nil)))
1241
1242
1243 ;;; Date 2016-08-09 (jd)
1244 ;;; Description
1245 ;;; No adequate specialization of MAKE-LOAD-FORM for an object of
1246 ;;; type RANDOM-TYPE
1247 (test cmp.0051.make-load-form.random-state
1248 (finishes (make-load-form (make-random-state))))
1249
1250
1251 ;;; Date 2016-12-20
1252 ;;; Reported by Paul F. Dietz
1253 ;;; Description
1254 ;;;
1255 ;;; Order of VALUES evaluation in compiled code is wrong.
1256 ;;;
1257 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/330
1258 (ext:with-clean-symbols (f2)
1259 (test cmp.0052.values-evaluation-order
1260 (defun f2 (a) (lcm (values a (setq a 1))))
1261 (is-eql 10 (f2 10))
1262 (compile 'f2)
1263 (is-eql 10 (f2 10))))
1264
1265 ;;; Date 2017-06-27
1266 ;;; Reported by Fabrizio Fabbri
1267 ;;; Description
1268 ;;;
1269 ;;; Compiled function drop argument type checkin
1270 ;;; on constant.
1271 ;;;
1272 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/353
1273 (test cmp.0053.check-values-type-on-constant
1274 (handler-case (funcall (cmplambda ()
1275 (rplaca 'A 1)))
1276 (simple-type-error () t)
1277 (error () nil)
1278 (:no-error (v) (declare (ignore v)) nil)))
1279
1280 ;;; Date 2017-06-28
1281 ;;; Reported by Fabrizio Fabbri
1282 ;;; Description
1283 ;;;
1284 ;;; Compiled assoc does not check that alist argument
1285 ;;; is a valid association list.
1286 ;;;
1287 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/353
1288 (test cmp.0054.invalid-argument-type
1289 (handler-case (funcall (cmplambda ()
1290 (assoc 'z '((a . b) :bad (c . d)))))
1291 (simple-type-error () t)
1292 (error () nil)
1293 (:no-error (v) (declare (ignore v)) nil)))
1294
1295 ;;; Date 2017-07-05
1296 ;;; Reported by Fabrizio Fabbri
1297 ;;; Description
1298 ;;;
1299 ;;; Compiled vector-push and vector-push-extend
1300 ;;; does not check for invalid argument and
1301 ;;; SIGSEGV
1302 ;;;
1303 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/353
1304 (test cmp.0055.invalid-argument-type
1305 (is-true
1306 (handler-case (funcall (cmplambda ()
1307 (vector-push)))
1308 (program-error () t)
1309 (error () nil)
1310 (:no-error (v) (declare (ignore v)) nil))))
1311
1312 ;;; Date 2017-08-10
1313 ;;; Description
1314 ;;;
1315 ;;; On some platforms (without feenableexcept) compiling code with
1316 ;;; constants being infinity cause fpe-exception.
1317 #+ieee-floating-point
1318 (test cmp.0056.artificial-fpe
1319 (finishes
1320 (funcall (cmplambda ()
1321 (eql 10d0 ext:double-float-positive-infinity)))))
1322
1323 ;;; Date 2017-08-10
1324 ;;; Description
1325 ;;;
1326 ;;; Confirm, that malformed code compiles (errors should be issued
1327 ;;; at runtime).
1328 (test cmp.0057.expand
1329 (let (fun)
1330 ;; expand-mapcar
1331 (is (setf fun (cmplambda () (mapcar))))
1332 (signals program-error (funcall fun))
1333 ;; expand-vector-push
1334 (is (setf fun (cmplambda () (vector-push))))
1335 (signals program-error (funcall fun))))
1336
1337 ;;; Date 2017-08-16
1338 ;;;
1339 ;;; Description
1340 ;;;
1341 ;;; `si:coerce-to-vector' (called from cmpopt) had invalid
1342 ;;; check-type statements preventing compilation of valid code.
1343 (test cmp.0058.coerce-expand
1344 (finishes (load (with-compiler ("aux-compiler.0058-coerce.lsp")
1345 '(defun flesh-failures ()
1346 (load-time-value
1347 (coerce #(0) '(simple-array (unsigned-byte 8) (1)))))))))
1348
1349 ;;; Date 2017-09-29
1350 ;;;
1351 ;;; Description
1352 ;;;
1353 ;;; `typep' compiler macroexpansion did treat
1354 ;;; `gray:fundamental-stream' as subtype of `ext:ansi-stream'.
1355 (test cmp.0059.gray-is-not-ansi
1356 (let ((stream (make-instance 'gray:fundamental-stream)))
1357 (is-false (typep stream 'ext:ansi-stream))))
1358
1359 ;;; Date 2017-11-21
1360 ;;; Description
1361 ;;;
1362 ;;; loop on dotted lists with destructuring bind gave a type error
1363 ;;;
1364 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/418
1365 (test cmp.0060.loop-on-dotted-list
1366 (finishes (funcall (cmplambda () (loop for (i) on '(1 2 . 3))))))
1367
1368 ;;; Date 2017-12-02
1369 ;;; Description
1370 ;;;
1371 ;;; type declarations for optional and keyword function arguments
1372 ;;; resulted in an error, when the default values weren't of the
1373 ;;; specified type.
1374 ;;;
1375 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/292
1376 (test cmp.0061.optional-type-declaration
1377 (declaim (ftype (function (real &optional real &key (:c symbol)) real) foo))
1378 (defun foo (a &optional (b 'test) &key (c 1)) (if b c a))
1379 (compile 'foo)
1380 (finishes (foo 1)))
1381
1382 ;;; Date 2018-01-23
1383 ;;; Description
1384 ;;;
1385 ;;; block referenced across closure boundries could lead to a local variable
1386 ;;; corruption due to the change of _when_ closure type is computed.
1387 ;;;
1388 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/374
1389 (test cmp.0062.ccb-block-variable-corruption
1390 (defun fooman ()
1391 (let ((foo-1 0)
1392 (second-time nil))
1393 (tagbody :G124
1394 (block exitpoint
1395 (handler-bind ((simple-error
1396 #'(lambda (c)
1397 (declare (ignore c))
1398 (if (= foo-1 0)
1399 (format nil "all is fine folks~%")
1400 (error "foo-1 is ~s should be 0" foo-1))
1401 ;; exitpoint is referenced across closure boundries
1402 (return-from exitpoint nil))))
1403 (signal 'simple-error)))
1404 (unless second-time
1405 (setf second-time t)
1406 (GO :G124)))))
1407 (compile 'fooman)
1408 (finishes (fooman)))
1409
1410 ;;; Date 2018-02-10
1411 ;;; Description
1412 ;;;
1413 ;;; Compiler macros do not get shadowed by lexical function bindings.
1414 ;;;
1415 ;;; Spec: http://www.lispworks.com/documentation/HyperSpec/Body/03_bba.htm
1416 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/83
1417 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/237
1418 (test cmp.0063.lexical-macrolet
1419 (defun foo () :function)
1420 (define-compiler-macro foo () :compiler-macro)
1421 (let ((result (funcall (cmplambda ()
1422 (macrolet ((foo () :macrolet))
1423 (foo))))))
1424 (is (eq :macrolet result) "Expected :MACROLET, got ~s." result)))
1425
1426 ;;; Date 2018-02-11
1427 ;;; Description
1428 ;;;
1429 ;;; ecl_bclosure lexenv is not used during complation (both bytecmp and ccmp).
1430 ;;; That leads to dangling references in compiled code.
1431 ;;;
1432 ;;; Bug https://gitlab.com/embeddable-common-lisp/ecl/issues/429
1433 (test cmp.0064.bytecmp-compile-bclosure
1434 (let ((fun-1 (lambda () :fun-1-nil))
1435 (fun-2 (let ((fun-2-var :var)) (lambda () fun-2-var)))
1436 (fun-3 (flet ((fun-3-fun () :fun)) (lambda () (fun-3-fun))))
1437 (fun-4 (macrolet ((fun-4-mac () :mac)) (lambda () (fun-4-mac))))
1438 (fun-5 (symbol-macrolet ((fun-5-sym :sym)) (lambda () fun-5-sym))))
1439 (is (eq :fun-1-nil (funcall fun-1)))
1440 (is (eq :var (funcall fun-2)))
1441 (is (eq :fun (funcall fun-3)))
1442 (is (eq :mac (funcall fun-4)))
1443 (is (eq :sym (funcall fun-5)))
1444 (let ((fun-1 (ext::bc-compile nil fun-1))
1445 (fun-2 (ext::bc-compile nil fun-2))
1446 (fun-3 (ext::bc-compile nil fun-3))
1447 (fun-4 (ext::bc-compile nil fun-4))
1448 (fun-5 (ext::bc-compile nil fun-5)))
1449 (is (eq :fun-1-nil (funcall fun-1)))
1450 (is (eq :var (ignore-errors (funcall fun-2))) "fun-2-var from lexenv is not used.")
1451 (is (eq :fun (ignore-errors (funcall fun-3))) "fun-3-fun from lexenv is not used.")
1452 (is (eq :mac (ignore-errors (funcall fun-4))) "fun-4-mac from lexenv is not used.")
1453 (is (eq :sym (ignore-errors (funcall fun-5))) "fun-5-sym from lexenv is not used."))))
1454
1455 (test cmp.0065.cmp-compile-bclosure
1456 (let ((fun-1 (lambda () :fun-1-nil))
1457 (fun-2 (let ((fun-2-var :var)) (lambda () fun-2-var)))
1458 (fun-3 (flet ((fun-3-fun () :fun)) (lambda () (fun-3-fun))))
1459 (fun-4 (macrolet ((fun-4-mac () :mac)) (lambda () (fun-4-mac))))
1460 (fun-5 (symbol-macrolet ((fun-5-sym :sym)) (lambda () fun-5-sym))))
1461 (is (eq :fun-1-nil (funcall fun-1)))
1462 (is (eq :var (funcall fun-2)))
1463 (is (eq :fun (funcall fun-3)))
1464 (is (eq :mac (funcall fun-4)))
1465 (is (eq :sym (funcall fun-5)))
1466 (let ((fun-1 (compile nil fun-1))
1467 (fun-2 (compile nil fun-2))
1468 (fun-3 (compile nil fun-3))
1469 (fun-4 (compile nil fun-4))
1470 (fun-5 (compile nil fun-5)))
1471 (is (eq :fun-1-nil (funcall fun-1)))
1472 (is (eq :var (ignore-errors (funcall fun-2))) "fun-2-var from lexenv is not used.")
1473 (is (eq :fun (ignore-errors (funcall fun-3))) "fun-3-fun from lexenv is not used.")
1474 (is (eq :mac (ignore-errors (funcall fun-4))) "fun-4-mac from lexenv is not used.")
1475 (is (eq :sym (ignore-errors (funcall fun-5))) "fun-5-sym from lexenv is not used."))))
1476
1477 ;;; Date 2018-02-12
1478 ;;; Description
1479 ;;;
1480 ;;; bytecmp always makes flet functions closures even if lexenv is empty.
1481 (test cmp.0066.bytecodes-flet-closure
1482 (let ((fun-1 (flet ((a () 1)) #'a))
1483 (fun-2 (let ((b 3)) ; this make break if we replace B with a constant
1484 (flet ((a () b)) #'a))))
1485 (is (null (nth-value 1 (function-lambda-expression fun-1))))
1486 (is (nth-value 1 (function-lambda-expression fun-2)))))
1487
1488 ;;; Date 2018-02-13
1489 ;;; Description
1490 ;;;
1491 ;;; ext::bc-compile executed compiled form.
1492 (test cmp.0067.bytecodes-compile-exec
1493 (multiple-value-bind (fun warn err)
1494 (ext::bc-compile nil '(flet ((a () 3)) #'a))
1495 (is (and (null fun) warn err)
1496 "bc-compile: invalid lambda expression should signal error.")))
1497
1498 ;;; Date 2018-02-13
1499 ;;; Description
1500 ;;;
1501 ;;; compile / ext::bc-compile doesn't accept (setf foo).
1502 (ext:with-clean-symbols (foo bar)
1503 (test cmp.0068.bytecmp-setf-foo
1504 (defun (setf foo) (x) x)
1505 (multiple-value-bind (fun warn err)
1506 (ext::bc-compile '(setf foo))
1507 (is (and fun (null warn) (null err))
1508 "bc-compile: (setf foo) is a valid function name.")))
1509 (test cmp.0069.cmp-setf-foo
1510 (defun (setf foo) (x) x)
1511 (multiple-value-bind (fun warn err)
1512 (compile '(setf foo))
1513 (is (and fun (null warn) (null err))
1514 "compile: (setf foo) is a valid function name."))))
1515
1516 ;;; Date 2019-04-02
1517 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/468
1518 ;;; Fixed: 177ad215ea91524756a00b24436273b065628081
1519 ;;; Description
1520 ;;;
1521 ;;; TYPECASE doesn't distinguish between different complex types
1522 ;;; when compiled.
1523 (ext:with-clean-symbols (xxx)
1524 (test cmp.0070.cmp-typecase-complex
1525 (defun xxx ()
1526 (let ((ci #c(5 7))
1527 (cs #c(1.0s0 1.0s0))
1528 (cd #c(1.0d0 1.0d0)))
1529 (list (typecase ci
1530 ((complex integer) 'ci)
1531 ((complex single-float) 'csf)
1532 ((complex double-float) 'cdf))
1533 (typecase cs
1534 ((complex integer) 'ci)
1535 ((complex single-float) 'csf)
1536 ((complex double-float) 'cdf))
1537 (typecase cs
1538 ((complex integer) 'ci)
1539 ((complex double-float) 'cdf)
1540 ((complex single-float) 'csf))
1541 (typecase cd
1542 ((complex integer) 'ci)
1543 ((complex single-float) 'csf)
1544 ((complex double-float) 'cdf))
1545 (typecase cd
1546 ((complex integer) 'ci)
1547 ((complex double-float) 'cdf)
1548 ((complex single-float) 'csf))
1549 (typecase ci
1550 ((complex (integer 0 3)) 'invalid)
1551 ((complex (integer 0 6)) 'invalid)
1552 ((complex (integer 4 8)) 'ci)
1553 ((complex integer) 'overboard)))))
1554 (is-equal (xxx) '(ci csf csf cdf cdf ci))
1555 (compile 'xxx)
1556 (is-equal (xxx) '(ci csf csf cdf cdf ci))))
1557
1558 ;;; Date 2019-04-19
1559 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/493
1560 ;;; Fixed: a73df694
1561 ;;; Description
1562 ;;;
1563 ;;; SUBTYPEP and TYPEP are not consistent for COMPLEX type in ANSI
1564 ;;; spec. SUBTYPEP pursues the internal representation (with
1565 ;;; UPGRADED-COMPLEX-PART-TYPE) while TYPEP goes after the type of
1566 ;;; the complex number parts to match the typespec. Problem was
1567 ;;; exhibited in compiled code. These are just a few examples which
1568 ;;; explore ECL potential failures. Test which goes more
1569 ;;; systematically across more types is defined in ansi-tests under
1570 ;;; name SUBTYPEP-COMPLEX.8.
1571 (test cmp.0071.cmp-typep-subtypep
1572 (is (typep #c(1.0 2.0) '(complex single-float)))
1573 (is (typep #c(1 2) '(complex fixnum)))
1574 (is (typep #c(1 2) '(complex (integer 0 8))))
1575 (is (not (typep #c(1.0 2.0) '(complex double-float))))
1576 (is (not (typep #c(1 2) '(complex (integer 0 1)))))
1577 (is (not (typep #c(1/2 2/3) '(complex (integer 0 1)))))
1578 ;;
1579 #-complex-float (is (subtypep '(complex single-float) '(complex double-float)))
1580 #-complex-float (is (subtypep '(complex double-float) '(complex single-float)))
1581 #-complex-float (is (subtypep '(complex double-float) '(complex float)))
1582 #+complex-float (is (not (subtypep '(complex single-float) '(complex double-float))))
1583 #+complex-float (is (not (subtypep '(complex double-float) '(complex single-float))))
1584 (is (subtypep '(complex double-float) '(complex float)))
1585 (is (subtypep '(complex fixnum) '(complex integer)))
1586 (is (subtypep '(complex integer) '(complex fixnum)))
1587 (is (subtypep '(complex ratio) '(complex fixnum)))
1588 (is (subtypep '(complex bit) '(complex ratio)))
1589 ;; this should be true even if single-float has a specialized
1590 ;; representation because of the first rule:
1591 ;;
1592 ;; (subtypep (complex t1) (complex t2)) is T, T when
1593 ;;
1594 ;; 1. (subtypep t1 t2) is T, T or
1595 ;; 2. (equal (ucpt t1) (ucpt t2))
1596 (is (subtypep '(complex single-float) '(complex real)))
1597 #-complex-float
1598 (is (and (subtypep '(complex bit) '(complex double-float))
1599 (subtypep '(complex double-float) '(complex bit))))
1600 #+complex-float
1601 (is (and (not (subtypep '(complex bit) '(complex double-float)))
1602 (not (subtypep '(complex double-float) '(complex bit) )))))
1603
1604 ;;; Date 2019-04-26
1605 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/497
1606 ;;; Fixed: 60978163
1607 ;;; Description
1608 ;;;
1609 ;;; Constant folding first dropped the multiple values, then
1610 ;;; refused to compile properly for not self-evaluating ones. This
1611 ;;; test checks if both cases are compiled correctly.
1612 (test cmp.0072.cmp-constant-fold
1613 (let (f1 f2)
1614 (finishes (setq f1 (cmplambda () (byte 0 0))))
1615 (finishes (setq f2 (cmplambda () (truncate 2 1))))
1616 (is (equal '(0 . 0) (funcall f1)))
1617 (is (equal '(2 0) (multiple-value-list (funcall f2))))))
1618
1619 ;;; Date 2019-07-02
1620 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/513
1621 ;;; Description
1622 ;;;
1623 ;;; When number of args in unoptimized long call is exactly
1624 ;;; ECL_C_ARGUMENTS limit we have a segfault, when it is greater
1625 ;;; parse_key signals a condition.
1626 (test cmp.0073.c-arguments-limit.miscompilation
1627 (with-compiler ("aux-cmp-0073.lsp" :load t)
1628 `(progn
1629 (defclass modual-bleh ()
1630 ((xxx :initarg :foo :initform nil)))
1631 (defmethod shared-initialize :after
1632 ((instance modual-bleh) (slot-names t) &key)
1633 42)
1634 (defun run-1 ()
1635 ">=63 arguments parse-key problem (first :foo is eaten)."
1636 (make-instance
1637 'modual-bleh
1638 :foo 00 :foo 01 :foo 02 :foo 03 :foo 04 :foo 05 :foo 06 :foo 07 :foo 08 :foo 09
1639 :foo 10 :foo 11 :foo 12 :foo 13 :foo 14 :foo 15 :foo 16 :foo 17 :foo 18 :foo 19
1640 :foo 20 :foo 21 :foo 22 :foo 23 :foo 24 :foo 25 :foo 26 :foo 27 :foo 28 :foo 29
1641 :foo 30 :foo 31))
1642 (defun run-2 ()
1643 "=62 arguments segmentation fault."
1644 (make-instance
1645 'modual-bleh
1646 :foo 00 :foo 01 :foo 02 :foo 03 :foo 04 :foo 05 :foo 06 :foo 07 :foo 08 :foo 09
1647 :foo 10 :foo 11 :foo 12 :foo 13 :foo 14 :foo 15 :foo 16 :foo 17 :foo 18 :foo 19
1648 :foo 20 :foo 21 :foo 22 :foo 23 :foo 24 :foo 25 :foo 26 :foo 27 :foo 28 :foo 29
1649 :foo 30))
1650 (defun run-3 ()
1651 "<=61 arguments all fine."
1652 (make-instance
1653 'modual-bleh
1654 :foo 00 :foo 01 :foo 02 :foo 03 :foo 04 :foo 05 :foo 06 :foo 07 :foo 08 :foo 09
1655 :foo 10 :foo 11 :foo 12 :foo 13 :foo 14 :foo 15 :foo 16 :foo 17 :foo 18 :foo 19
1656 :foo 20 :foo 21 :foo 22 :foo 23 :foo 24 :foo 25 :foo 26 :foo 27 :foo 28 :foo 29))))
1657 (finishes (run-1))
1658 (finishes (run-2))
1659 (finishes (run-3)))
1660
1661 ;;; Date 2020-01-12
1662 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/550
1663 ;;; Description
1664 ;;;
1665 ;;; When we invoke an unopitmized long call (that is we apply from
1666 ;;; a stack frame), function argument is evaluated after the
1667 ;;; arguments what is wrong for operators where function is the
1668 ;;; first argument (and should be evaluated first).
1669 (test cmp.0074.c-arguments-limit.evaluation-rule
1670 (flet ((make-fn (n)
1671 `(lambda ()
1672 (let ((se-var '()))
1673 (funcall (prog1 #'list (push :fun se-var))
1674 ,@(list* `(push :arg se-var)
1675 (make-list (1- n))))
1676 (nreverse se-var))))
1677 (check-fn (form)
1678 (is (equal '(:fun :arg) (funcall (compile nil form))))))
1679 (check-fn (make-fn 10))
1680 (check-fn (make-fn (1+ si::c-arguments-limit)))
1681 (check-fn (make-fn (1- si::c-arguments-limit)))
1682 (check-fn (make-fn si::c-arguments-limit))))
1683
1684 ;;; Date 2020-03-18
1685 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/545
1686 ;;; Description
1687 ;;;
1688 ;;; The closure type for local functions calling global closures was
1689 ;;; not determined correctly to also be a global closure.
1690 (test cmp.0075.local-fun.closure-type
1691 (ext:with-clean-symbols (*function*)
1692 (defvar *function*)
1693 (let* ((fun (lambda (b)
1694 (flet ((%f10 () b))
1695 (flet ((%f4 () (%f10)))
1696 (incf b)
1697 ;; makes a global closure out of %f10
1698 (setf *function* #'%f10)
1699 (%f4)))))
1700 (result (funcall (compile nil fun) 3)))
1701 (is (eq result 4))
1702 (is (eq (funcall *function*) 4)))))
1703
1704 ;;; Date 2020-03-13
1705 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/565
1706 ;;; Description
1707 ;;;
1708 ;;; This test checks whether the same constant is coalesced to the EQ
1709 ;;; value among three distinct top-level forms.
1710 ;;;
1711 ;;; ccmp's COMPILE-FILE produces two vectors VV and VVtemp which represent
1712 ;;; the fasl data segment. The latter is deallocated after all top-level
1713 ;;; forms are evaluated. As compiler processes them currently if the
1714 ;;; object is first pushed to the temporary segment and then we try to add
1715 ;;; it to the permanent segment we have two versions of the same objects
1716 ;;; which are not EQ. File src/cmp/cmpwt.lsp has an appropriate FIXME in
1717 ;;; the ADD-OBJECT function definition.
1718 (test cmp.0076.make-load-form-non-eq
1719 (multiple-value-bind (file output)
1720 (with-compiler ("make-temp.lsp")
1721 "(in-package #:cl-test)"
1722 "(eval-when (:compile-toplevel :load-toplevel :execute)
1723 (defclass my-class ()
1724 ((name :initarg :name :accessor name)))
1725 (defmethod print-object ((obj my-class) stream)
1726 (print-unreadable-object (obj stream :identity t)
1727 (format stream \"~s ~s\" (name obj) (class-name (class-of obj)))))
1728 (defmethod make-load-form ((x my-class) &optional environment)
1729 (declare (ignore environment))
1730 `(make-instance ',(class-of x) :name ',(slot-value x 'name))))"
1731 "(eval-when (:compile-toplevel)
1732 (defparameter s4 (make-instance 'my-class :name :s4)))"
1733 "(defparameter *s4-a* nil)"
1734 "(defparameter *s4-b* nil)"
1735 "(let ((a '#.s4))
1736 (setf *s4-a* a))"
1737 "(defun foo ()
1738 (let ((x #.s4))
1739 (values x *s4-a* *s4-b*)))"
1740 "(let ((b '#.s4))
1741 (setf *s4-b* b))")
1742 (declare (ignore output))
1743 (load file)
1744 (delete-file "make-temp.lsp")
1745 (delete-file file))
1746 (multiple-value-bind (x a b) (foo)
1747 (is (eq x a) "~a is not eq to ~a" x a)
1748 (is (eq x b) "~a is not eq to ~a" x b)
1749 (is (eq a b) "~a is not eq to ~a" a b)))
1750
1751 (ext:with-clean-symbols (class)
1752 (test cmp.0077.make-load-form.circular-dep
1753 (macrolet ((make-template (&body extra)
1754 `(with-compiler ("make-circle.lsp")
1755 '(progn
1756 (in-package #:cl-test)
1757 (eval-when (:compile-toplevel :load-toplevel :execute)
1758 (defclass class ()
1759 ((peer :initform nil :initarg :peer :accessor peer)
1760 (peer* :initform nil :initarg :peer* :accessor peer*)))
1761 (defmethod make-load-form ((x class) &optional env)
1762 (declare (ignore env))
1763 (values `(make-instance 'class :peer ',(peer x))
1764 `(setf (peer* ',x) ',(peer* x)))))
1765 (eval-when (:compile-toplevel)
1766 (defparameter var1 (make-instance 'class))
1767 (defparameter var2 (make-instance 'class :peer var1))
1768 ,@extra))
1769 "(defun foo () (values '#.var1 '#.var2))")))
1770 ;; Ordinary case (reference).
1771 (multiple-value-bind (file output)
1772 (make-template)
1773 (load file)
1774 (delete-file "make-circle.lsp")
1775 (delete-file file)
1776 (multiple-value-bind (v1 v2) (foo)
1777 (is (eq (peer v2) v1))))
1778 ;; Circularity between make forms (should signal an error).
1779 (signals error
1780 (unwind-protect (multiple-value-bind (file output)
1781 (make-template (setf (peer var1) var2))
1782 (when file (delete-file file)))
1783 (delete-file "make-circle.lsp"))
1784 "Successfully compiled a file with a circular dependency.")
1785 ;; Circularity between make and init forms (is not an error!).
1786 (multiple-value-bind (file output)
1787 (make-template (setf (peer* var1) var2))
1788 (load file)
1789 (delete-file "make-circle.lsp")
1790 (delete-file file)
1791 (multiple-value-bind (v1 v2) (foo)
1792 (is (eq (peer v2) v1))
1793 (is (eq (peer* v1) v2))))
1794 ;; Circularity between init forms (is not an error!).
1795 (multiple-value-bind (file output)
1796 (make-template (setf (peer* var1) var2)
1797 (setf (peer* var2) var1))
1798 (load file)
1799 (delete-file "make-circle.lsp")
1800 (delete-file file)
1801 (multiple-value-bind (v1 v2) (foo)
1802 (is (eq (peer v2) v1))
1803 (is (eq (peer* v1) v2))
1804 (is (eq (peer* v2) v1)))))))
1805
1806 ;;; Date 2020-03-13
1807 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/571
1808 ;;; Description
1809 ;;;
1810 ;;; LOAD-TIME-VALUE inside a DEFMETHOD is evaluated at the
1811 ;;; compilation time.
1812 (test cmp.0078.defmethod-not-eager
1813 (finishes (with-compiler ("aux-compiler.0078.lsp")
1814 `(defclass class () ())
1815 `(defmethod method ()
1816 (load-time-value (find-class class))))))
1817
1818 ;;; Date 2020-05-01
1819 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/577
1820 ;;; Description
1821 ;;;
1822 ;;; Inlining of closures did not work properly if closed over
1823 ;;; variables were in the scope in which the inlined function was
1824 ;;; called.
1825 (test cmp.0079.inline-closure
1826 ;; local function
1827 (is (equal
1828 (funcall (compile
1829 nil
1830 (lambda ()
1831 (let ((b 123)
1832 results)
1833 (flet ((set-b (x) (setf b x))
1834 (get-b () b))
1835 (declare (inline set-b get-b))
1836 (push (get-b) results)
1837 (push b results)
1838 (let ((b 345))
1839 (push (get-b) results)
1840 (push b results)
1841 (set-b 0)
1842 (push (get-b) results)
1843 (push b results))
1844 (push (get-b) results)
1845 (push b results))
1846 (nreverse results)))))
1847 '(123 123 123 345 0 345 0 0)))
1848 ;; global function from bytecodes compiler, proclaimed inline
1849 (ext:with-clean-symbols (set-b get-b)
1850 (proclaim '(inline set-b get-b))
1851 (eval
1852 '(let ((b 123))
1853 (defun set-b (x)
1854 (setf b x))
1855 (defun get-b () b)))
1856 (is (equal
1857 (funcall (compile
1858 nil
1859 (lambda ()
1860 (let (results)
1861 (push (get-b) results)
1862 (let ((b 345))
1863 (push (get-b) results)
1864 (push b results)
1865 (set-b 0)
1866 (push (get-b) results)
1867 (push b results))
1868 (push (get-b) results)
1869 (nreverse results)))))
1870 '(123 123 345 0 345 0))))
1871 ;; global function in same file, declaimed inline
1872 (load (with-compiler ("inline-closure.lsp")
1873 '(in-package #:cl-test)
1874 '(declaim (inline set-b.0079a get-b.0079a))
1875 '(let ((b 123))
1876 (defun set-b.0079a (x)
1877 (setf b x))
1878 (defun get-b.0079a () b))
1879 '(defun foo.0079a ()
1880 (let (results)
1881 (push (get-b.0079a) results)
1882 (let ((b 345))
1883 (push (get-b.0079a) results)
1884 (push b results)
1885 (set-b.0079a 0)
1886 (push (get-b.0079a) results)
1887 (push b results))
1888 (push (get-b.0079a) results)
1889 (nreverse results)))))
1890 (is (equal
1891 (funcall 'foo.0079a)
1892 '(123 123 345 0 345 0)))
1893 ;; global function in different file, proclaimed inline
1894 (proclaim '(inline set-b.0079b get-b.0079b))
1895 (load (with-compiler ("inline-closure-1.lsp")
1896 '(in-package #:cl-test)
1897 '(let ((b 123))
1898 (defun set-b.0079b (x)
1899 (setf b x))
1900 (defun get-b.0079b () b))))
1901 (load (with-compiler ("inline-closure-2.lsp")
1902 '(in-package #:cl-test)
1903 '(defun foo.0079b ()
1904 (let (results)
1905 (push (get-b.0079b) results)
1906 (let ((b 345))
1907 (push (get-b.0079b) results)
1908 (push b results)
1909 (set-b.0079b 0)
1910 (push (get-b.0079b) results)
1911 (push b results))
1912 (push (get-b.0079b) results)
1913 (nreverse results)))))
1914 (is (equal
1915 (funcall 'foo.0079b)
1916 '(123 123 345 0 345 0))))
1917
1918 ;;; Date 2020-05-08
1919 ;;;
1920 ;;; Regression from a fix for #577.
1921 (test cmp.0080.inline-closure
1922 (is (funcall (compile
1923 nil
1924 '(lambda ()
1925 (labels ((bam (pos)
1926 (declare (inline bam))
1927 (if (= pos 42)
1928 :banzai
1929 (let ((my-new-val 42))
1930 (bam my-new-val)))))
1931 (eq :banzai (bam 30))))))))
1932
1933 ;;; Date 2020-05-28
1934 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/issues/591
1935 ;;; Description
1936 ;;;
1937 ;;; MULTIPLE-VALUE-SETQ would wrongly assign NIL to special variables
1938 ;;; due to not saving env->nvalues before calling SET
1939 (ext:with-clean-symbols (*a* *b* foo)
1940 (defvar *a* :wrong-a)
1941 (defvar *b* :wrong-b)
1942 (defun foo () (values :right-a :right-b))
1943 (test cmp.0081.m-v-setq-special
1944 (is (funcall (compile
1945 nil
1946 '(lambda ()
1947 (multiple-value-setq (*a* *b*) (foo))
1948 (and (eq *a* :right-a)
1949 (eq *b* :right-b))))))))
1950
1951 ;;; Date 2020-08-14
1952 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/594
1953 ;;; Description
1954 ;;;
1955 ;;; The code walker used in DEFMETHOD would call MAKE-LOAD-VALUE
1956 ;;; for literal objects encountered during code walking, even while
1957 ;;; loading a file or using eval.
1958 (ext:with-clean-symbols (test-class test-method)
1959 (eval '(defclass test-class () ()))
1960 (eval '(defmethod make-load-form ((obj test-class) &optional env)
1961 (error "We shouldn't have called MAKE-LOAD-FORM here.")))
1962 (test cmp.0082.defmethod-make-load-form
1963 (let* ((test-obj (make-instance 'test-class))
1964 (code `(defmethod test-method ()
1965 ,test-obj)))
1966 (finishes (eval code)))))
1967
1968 ;;; Date 2021-01-02
1969 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/620
1970 ;;; Description
1971 ;;;
1972 ;;; RETURN inside the symbol or value arguments for PROGV leads to
1973 ;;; a segfault
1974 (ext:with-clean-symbols (*s*)
1975 (test cmp.0083.progv-return
1976 (proclaim '(special *s*))
1977 (is (eql 0 (funcall (cmplambda ()
1978 (block nil
1979 (progv (list (return 0)) (list 1)))))))
1980 (is (eql 0 (funcall (cmplambda ()
1981 (block nil
1982 (progv '(*s*) (list (return 0))))))))
1983 (is (not (boundp '*s*)))
1984 (is (eql 1 (funcall (cmplambda ()
1985 (block nil
1986 (progv '(*s*) (list 0) (return 1) *s*))))))
1987 (is (not (boundp '*s*)))))
1988
1989 ;;; Date 2021-01-16
1990 ;;; Description
1991 ;;;
1992 ;;; Compiling a local function of type CLOSURE can lead to an
1993 ;;; internal compiler error if the function is later inlined
1994 ;;; because the compiler would indiscriminantly change the closure
1995 ;;; type to LEXICAL during inlining.
1996 (ext:with-clean-symbols (some-global-fun another-global-fun)
1997 (defun some-global-fun (fun)
1998 (funcall fun))
1999 (defun another-global-fun (x)
2000 x)
2001 (test cmp.0084.inline-local-closure-type
2002 (let ((fun '(lambda (arg)
2003 (declare (optimize speed))
2004 (labels
2005 ((a ()
2006 (some-global-fun #'b)
2007 (c))
2008 (b ()
2009 (c))
2010 (c ()
2011 ;; c is of type CLOSURE (arg is passed to
2012 ;; a global function). This "infects" a
2013 ;; and b to be of type CLOSURE too.
2014 (incf arg)
2015 (another-global-fun arg)))
2016 (declare (inline a))
2017 (a))))
2018 compiled-fun warnings-p errors-p)
2019 (finishes (multiple-value-setq (compiled-fun warnings-p error-p)
2020 (compile nil fun)))
2021 (is (null errors-p))
2022 (is (= (funcall compiled-fun 0) 2)))))
2023
2024 ;;; Date 2020-08-14
2025 ;;; Description
2026 ;;;
2027 ;;; (values (values)) was miscompiled and returned no value
2028 ;;; instead of the correct nil
2029 (test cmp.0085.values-values
2030 (is (equal '(nil)
2031 (multiple-value-list
2032 (funcall
2033 (cmplambda () (values (values))))))))
2034
2035 ;;; Date 2021-03-25
2036 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/633
2037 ;;; Description
2038 ;;;
2039 ;;; The order of function arguments was wrong when inlining a
2040 ;;; function with &key and &aux arguments. This test checks
2041 ;;; correct ordering in general.
2042 (test cmp.0086.inline-ordering-function-arguments
2043 (is (equal (multiple-value-list
2044 (funcall (cmplambda ()
2045 (flet ((f (a
2046 &optional (b a)
2047 &rest c
2048 &key (d c)
2049 &aux (e d))
2050 (list a b c d e)))
2051 (declare (inline f))
2052 (values (f 1)
2053 (f 1 2)
2054 (f 1 2 :d 3))))))
2055 '((1 1 nil nil nil)
2056 (1 2 nil nil nil)
2057 (1 2 (:d 3) 3 3)))))
2058
2059 ;;; Date 2021-03-30
2060 ;;; Description
2061 ;;;
2062 ;;; let bindings of lists like '(quote ...) were miscompiled
2063 (test cmp.0087.let-list-containing-quote
2064 (is (equal '((quote) (quote a b c))
2065 (funcall
2066 (cmplambda ()
2067 (let ((x '(quote))
2068 (y '(quote a b c)))
2069 (list x y)))))))
2070
2071 ;;; Date 2021-11-19
2072 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/662
2073 ;;; Description
2074 ;;;
2075 ;;; In ccmp a global symbol macro cannot be lexically rebound.
2076 ;;;
2077 (test cmp.0089.symbol-macro
2078 (when (finishes
2079 (with-compiler ("cmp.0089.symbol-macro.lsp" :load t)
2080 `(define-symbol-macro cmp.0089.sym 42)
2081 `(defun cmp.0089.fun1 (cmp.0089.sym) cmp.0089.sym)
2082 `(defun cmp.0089.fun2 () cmp.0089.sym)))
2083 (is (= 15 (cmp.0089.fun1 15)))
2084 (is (= 42 (cmp.0089.fun2)))))
2085
2086 ;;; Date 2022-01-29
2087 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/672
2088 ;;; Description
2089 ;;;
2090 ;;; Apply, funcall and multiple-value-call did not check the
2091 ;;; number of arguments when lambda expressions. This test fairly
2092 ;;; comprehensively checks that we signal an error if we get wrong
2093 ;;; number of arguments and also includes some non-error cases.
2094 ;;;
2095 (test cmp.0090.funcall/apply-inline-and-number-of-arguments
2096 (let ((*standard-output* (make-broadcast-stream)))
2097 (signals error (funcall (cmplambda () (funcall (lambda (a b) (list a b)) 1))))
2098 (signals error (funcall (cmplambda () (funcall (lambda (a b) (list a b)) 1 2 3))))
2099 (signals error (funcall (cmplambda () (funcall (lambda (a &optional b) (list a b)) 1 2 3))))
2100 (is (equal (funcall (cmplambda () (funcall (lambda (a &optional b) (list a b)) 1))) '(1 nil)))
2101 (is (equal (funcall (cmplambda () (funcall (lambda (a &optional b) (list a b)) 1 2))) '(1 2)))
2102 (signals error (funcall (cmplambda () (apply (lambda (a b) (list a b)) '(1)))))
2103 (signals error (funcall (cmplambda () (apply (lambda (a b) (list a b)) '(1 2 3)))))
2104 (signals error (funcall (cmplambda () (apply (lambda (a b) (list a b)) 1 '(2 3)))))
2105 (is (equal (funcall (cmplambda (x) (apply (lambda (a b) (list a b)) x)) '(1 2)) '(1 2)))
2106 (is (equal (funcall (cmplambda (x) (apply (lambda (a b) (list a b)) 1 x)) '(2)) '(1 2)))
2107 (signals error (funcall (cmplambda (x) (apply (lambda (a b) (list a b)) 1 x)) '(2 3)))
2108 (is (equal (funcall (cmplambda () (apply (lambda (a &optional b) (list a b)) '(1)))) '(1 nil)))
2109 (signals error (funcall (cmplambda () (apply (lambda (a &optional b) (list a b)) '(1 2 3)))))
2110 (signals error (funcall (cmplambda () (apply (lambda (a &optional b) (list a b)) 1 '(2 3)))))
2111 (is (equal (funcall (cmplambda (x) (apply (lambda (a &optional b) (list a b)) x)) '(1 2)) '(1 2)))
2112 (is (equal (funcall (cmplambda (x) (apply (lambda (a &optional b) (list a b)) 1 x)) '(2)) '(1 2)))
2113 (signals error (funcall (cmplambda (x) (apply (lambda (a &optional b) (list a b)) 1 x)) '(2 3)))
2114 (signals error (funcall (cmplambda () (multiple-value-call (lambda (a b) (list a b)) (values 1)))))
2115 (signals error (funcall (cmplambda () (multiple-value-call (lambda (a b) (list a b)) (values 1 2 3)))))
2116 (signals error (funcall (cmplambda () (multiple-value-call (lambda (a &optional b) (list a b)) (values 1 2 3)))))
2117 (is (equal (funcall (cmplambda () (multiple-value-call (lambda (a &optional b) (list a b)) (values 1)))) '(1 nil)))
2118 (is (equal (funcall (cmplambda () (multiple-value-call (lambda (a &optional b) (list a b)) (values 1 2)))) '(1 2)))))
2119
2120 ;;; Date 2022-08-13
2121 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/630
2122 ;;; Description
2123 ;;;
2124 ;;; The compiler would run into an infinite loop when two lists
2125 ;;; with the same circular structure were contained as literal
2126 ;;; data in the same file.
2127 ;;;
2128 (test cmp.0091.infinite-loop-circular-data
2129 (finishes (with-compiler ("infinite-loop-circular-data.lsp")
2130 '(eq '#1=(a . #1#) '#2=(a . #2#))
2131 '(eq '#3=(a b . #3#) '#4=(a b . #4#))
2132 '(eq '#5=(#5# . a) '#6=(#6# . a))
2133 '(eq '#7=((#7# . a) . b) '#8=((#8# . a) . b))
2134 '(eq '#9=((a . #9#) . b) '#10=((a . #10#) . b))
2135 '(eq '#11=(#11# . #11#) '#12=(#12# . #12#)))))
2136
2137 ;;; Date 2022-12-30
2138 ;;; Description
2139 ;;;
2140 ;;; Check that function redefinitions for functions which are
2141 ;;; declared as inline are picked up correctly even if we can't
2142 ;;; inline the new definition (e.g. because it is a closure).
2143 ;;;
2144 (test cmp.0092.inline-redefinition
2145 (setf (compiler-macro-function 'foo) nil)
2146 (finishes (with-compiler ("inline-redefinition-1.lsp" :load t)
2147 '(declaim (inline foo))
2148 '(defun foo () 1)
2149 '(defun bar () (foo))))
2150 (is (eql (bar) 1))
2151 (finishes (with-compiler ("inline-redefinition-2.lsp" :load t)
2152 '(let ((a 2))
2153 (defun ensure-compiler-cannot-optimize-away-the-let-statement (x)
2154 (setf a x))
2155 (defun foo ()
2156 a))
2157 '(defun bar () (foo))))
2158 (is (eql (bar) 2)))
2159
2160 ;;; Date 2023-06-18
2161 ;;; Description
2162 ;;;
2163 ;;; Compound function types in type declarations must not end up
2164 ;;; as arguments to TYPEP.
2165 ;;;
2166 (deftype fun-type.0093a () '(function (integer) integer))
2167 (deftype fun-type.0093b (tp) `(function (,tp) ,tp))
2168
2169 (defstruct struct.0093
2170 (f1 #'(lambda (x) (+ x 2)) :type (function (integer) integer))
2171 (f2 #'(lambda (x) (+ x 2)) :type fun-type.0093a)
2172 (f3 #'(lambda (x) (+ x 2)) :type (fun-type.0093b integer)))
2173
2174 (defclass class.0093 ()
2175 ((f1 :initform #'(lambda (x) (+ x 2)) :initarg :f1 :reader class.0093-f1
2176 :type (function (integer) integer))
2177 (f2 :initform #'(lambda (x) (+ x 2)) :initarg :f2 :reader class.0093-f2
2178 :type fun-type.0093a)
2179 (f3 :initform #'(lambda (x) (+ x 2)) :initarg :f3 :reader class.0093-f3
2180 :type (fun-type.0093b integer))))
2181
2182 (test cmp.0093.declare-compound-function-types
2183 ;; type declarations for function arguments
2184 (is (= 5 (funcall (compile nil (lambda (f)
2185 (declare (ext:check-arguments-type) (ext:type-assertions)
2186 (type (function (integer) integer) f))
2187 (funcall f 3)))
2188 #'(lambda (x) (+ x 2)))))
2189 (is (= 5 (funcall (compile nil (lambda (f)
2190 (declare (ext:check-arguments-type) (ext:type-assertions)
2191 (type fun-type.0093a f))
2192 (funcall f 3)))
2193 #'(lambda (x) (+ x 2)))))
2194 (is (= 5 (funcall (compile nil (lambda (f)
2195 (declare (ext:check-arguments-type) (ext:type-assertions)
2196 (type (fun-type.0093b integer) f))
2197 (funcall f 3)))
2198 #'(lambda (x) (+ x 2)))))
2199 ;; type declarations for local variables
2200 (is (= 5 (funcall (compile nil (lambda ()
2201 (declare (ext:evaluate-forms) (ext:type-assertions))
2202 (let ((f #'(lambda (x) (+ x 2))))
2203 (declare (type (function (integer) integer) f))
2204 (funcall f 3)))))))
2205 (is (= 5 (funcall (compile nil (lambda ()
2206 (declare (ext:evaluate-forms) (ext:type-assertions))
2207 (let ((f #'(lambda (x) (+ x 2))))
2208 (declare (type fun-type.0093a f))
2209 (funcall f 3)))))))
2210 (is (= 5 (funcall (compile nil (lambda ()
2211 (declare (ext:evaluate-forms) (ext:type-assertions))
2212 (let ((f #'(lambda (x) (+ x 2))))
2213 (declare (type (fun-type.0093b integer) f))
2214 (funcall f 3)))))))
2215 ;; type declarations using THE with constant argument
2216 (is (typep (funcall (compile nil (lambda ()
2217 (declare (ext:evaluate-forms) (ext:type-assertions))
2218 (the (function (integer) integer)
2219 #.#'(lambda (x) (+ x 2))))))
2220 'function))
2221 (is (typep (funcall (compile nil (lambda ()
2222 (declare (ext:evaluate-forms) (ext:type-assertions))
2223 (the fun-type.0093a
2224 #.#'(lambda (x) (+ x 2))))))
2225 'function))
2226 (is (typep (funcall (compile nil (lambda ()
2227 (declare (ext:evaluate-forms) (ext:type-assertions))
2228 (the (fun-type.0093b integer)
2229 #.#'(lambda (x) (+ x 2))))))
2230 'function))
2231 ;; type declarations in DEFSTRUCT
2232 (let ((s (make-struct.0093)))
2233 (is (typep (struct.0093-f1 s) 'function))
2234 (is (typep (struct.0093-f2 s) 'function))
2235 (is (typep (struct.0093-f3 s) 'function)))
2236 (let ((s (make-struct.0093 :f1 #'(lambda (x) (+ x 3))
2237 :f2 #'(lambda (x) (+ x 3))
2238 :f3 #'(lambda (x) (+ x 3)))))
2239 (is (typep (struct.0093-f1 s) 'function))
2240 (is (typep (struct.0093-f2 s) 'function))
2241 (is (typep (struct.0093-f3 s) 'function)))
2242 ;; type declarations in DEFCLASS
2243 (let ((i (make-instance 'class.0093)))
2244 (is (typep (class.0093-f1 i) 'function))
2245 (is (typep (class.0093-f2 i) 'function))
2246 (is (typep (class.0093-f3 i) 'function)))
2247 (let ((i (make-instance 'class.0093
2248 :f1 #'(lambda (x) (+ x 3))
2249 :f2 #'(lambda (x) (+ x 3))
2250 :f3 #'(lambda (x) (+ x 3)))))
2251 (is (typep (class.0093-f1 i) 'function))
2252 (is (typep (class.0093-f2 i) 'function))
2253 (is (typep (class.0093-f3 i) 'function))))
2254
2255
2256 ;;; Date 2023-06-18
2257 ;;; Description
2258 ;;;
2259 ;;; TYPEP with a compound function type as argument must not be
2260 ;;; simplified to FUNCTIONP.
2261 ;;;
2262 (deftype fun-type.0094a () '(function (integer) integer))
2263 (deftype fun-type.0094b (tp) `(function (,tp) ,tp))
2264
2265 (test cmp.0094.typep-compound-function-type
2266 (signals error (funcall (compile nil (lambda (x) (typep x '(function (integer) integer))))
2267 #'(lambda (x) (+ x 2))))
2268 (signals error (funcall (compile nil (lambda (x) (typep x 'fun-type.0094a)))
2269 #'(lambda (x) (+ x 2))))
2270 (signals error (funcall (compile nil (lambda (x) (typep x '(fun-type.0094b integer))))
2271 #'(lambda (x) (+ x 2)))))
2272
2273 ;;; Date 2023-06-24
2274 ;;; Description
2275 ;;;
2276 ;;; The compiler produced invalid C code when unable to coerce
2277 ;;; between incompatible C types. This situation typically
2278 ;;; indicates a bug but it can also happen because of a failure of
2279 ;;; the dead code elimination step. In this case we were
2280 ;;; outputting invalid C code for the dead part and thus the
2281 ;;; compilation could fail for valid Lisp code.
2282 ;;;
2283 (test cmp.0095.unreachable-code-unboxed-value
2284 (is (eql
2285 (funcall (compile nil
2286 (lambda (y)
2287 (declare (optimize (safety 0) (speed 3))
2288 (fixnum y))
2289 (funcall (lambda (x)
2290 (cond ((typep x 'fixnum) (1+ x))
2291 ((characterp x) (char-code x))))
2292 (the fixnum (1+ y)))))
2293 2)
2294 4)))
2295
2296 ;;; Date 2023-09-15
2297 ;;; Description
2298 ;;;
2299 ;;; The compiler may optimize away MULTIPLE-VALUE-CALL when all forms are
2300 ;;; known to be (VALUES ,@things) or /atom/. This test verify the correct
2301 ;;; result. The last value is NIL as a gotcha for an atom that is a list.
2302 ;;;
2303 (test cmp.0095.multiple-value-call-with-values
2304 (flet ((check-fun (fun)
2305 (is-equal '(1 2 3 nil) (funcall fun 1 2 3 nil))))
2306 (check-fun (cmplambda (a b c d) (multiple-value-call #'list a b c d)))
2307 (check-fun (cmplambda (a b c d) (multiple-value-call #'list (values a b) c d)))
2308 (check-fun (cmplambda (a b c d) (multiple-value-call #'list (values a b) (values c d))))
2309 (check-fun (cmplambda (a b c d) (multiple-value-call #'list (values a b c d)))))
2310 ;; Let's throw SYMBOL-MACROLET into the mix.
2311 (macrolet ((cmplambda* (args &body body)
2312 `(cmplambda ,args
2313 (symbol-macrolet ((y-vals (values 3 nil))
2314 (n-vals (list 3 nil))
2315 (nth-v3 3)
2316 (nth-v4 nil))
2317 ,@body))))
2318 (flet ((check-yfn (fun) (is-equal '(1 2 3 nil) (funcall fun 1 2)))
2319 (check-nfn (fun) (is-equal '(1 2 (3 nil)) (funcall fun 1 2))))
2320 (check-yfn (cmplambda* (a b) (multiple-value-call #'list (values a b) nth-v3 nth-v4)))
2321 (check-yfn (cmplambda* (a b) (multiple-value-call #'list (values a b) y-vals)))
2322 (check-nfn (cmplambda* (a b) (multiple-value-call #'list (values a b) n-vals)))))
2323 ;; And add MACROLET. We could go out on a limb here to check functions with a
2324 ;; compiler macro, but that'd be an overkill. We don't currently optimize for
2325 ;; normal macros in the first place.
2326 (macrolet ((cmplambda* (args &body body)
2327 `(cmplambda ,args
2328 (let ((v3 3)
2329 (v4 nil))
2330 (macrolet ((y-vals () `(values v3 v4))
2331 (n-vals () `(list v3 v4))
2332 (nth-v3 () `v3)
2333 (nth-v4 () `v4))
2334 ,@body)))))
2335 (flet ((check-yfn (fun) (is-equal '(1 2 3 nil) (funcall fun 1 2)))
2336 (check-nfn (fun) (is-equal '(1 2 (3 nil)) (funcall fun 1 2))))
2337 (check-yfn (cmplambda* (a b) (multiple-value-call #'list (values a b) (nth-v3) (nth-v4))))
2338 (check-yfn (cmplambda* (a b) (multiple-value-call #'list (values a b) (y-vals))))
2339 (check-nfn (cmplambda* (a b) (multiple-value-call #'list (values a b) (n-vals)))))))
2340
2341 ;;; Unreleased refactor branch had a regression where constants were not
2342 ;;; properly initialized in the LET form.
2343 (test cmp.0096.c1var/location
2344 (is (floatp (funcall (cmplambda ()
2345 (let ((x most-positive-single-float))
2346 x))))))
2347
2348 (test cmp.0097.wt-loc-regressions
2349 ;; Baseline (this works)
2350 (is (null (nth-value 1 (compile nil '(lambda (x) (not (the integer x)))))))
2351 ;; Unreleased regressions (** Unknown location found in WT-LOC: NIL)
2352 (is (null (nth-value 1 (compile nil '(lambda (x) (not (the single-float x)))))))
2353 (is (null (nth-value 1 (compile nil '(lambda (x) (not (the double-float x)))))))
2354 (is (null (nth-value 1 (compile nil '(lambda (x) (not (the long-float x))))))))
2355
2356 (test cmp.0097.cmp-regression
2357 (let ((fun (cmplambda ()
2358 (EXPT
2359 (LABELS ((%F14 () 0))
2360 (%F14))
2361 0))))
2362 (let ((res (FUNCALL fun)))
2363 (is (= 1 res) "Res is ~s, should be 1." res))))
2364
2365 ;;; Date 2023-12-23
2366 ;;; Description
2367 ;;;
2368 ;;; The compiler trusted proclaimed types for optional or keyword
2369 ;;; arguments even if their init-forms did not match the
2370 ;;; proclaimed types, leading to unsafe code even in safe mode.
2371 ;;; While technically incorrect, init-forms not matching the
2372 ;;; proclaimed type of the corresponding argument is common enough
2373 ;;; that we allow it, only signaling a style-warning.
2374 ;;;
2375 (test cmp.0098.init-forms-type-check
2376 (proclaim '(ftype (function (&optional number) t) foo.0098a))
2377 (defun foo.0098a (&optional x) (if x (list x) :good))
2378 (is (nth-value 1 (compile 'foo.0098a))) ; check that we get a style-warning
2379 (is (eql (funcall 'foo.0098a) :good))
2380 (is (eql (funcall 'foo.0098a nil) :good)) ; the type of x is (or number null)
2381 (is (equal (funcall 'foo.0098a 0) (list 0)))
2382 (signals type-error (funcall 'foo.0098a :bad-arg))
2383
2384 (proclaim '(ftype (function (&key (:x string) (:y integer)) t) foo.0098b))
2385 (defun foo.0098b (&key x (y 1.0)) (if x (1+ y) :good))
2386 (is (nth-value 1 (compile 'foo.0098b))) ; check that we get a style-warning
2387 (is (eql (funcall 'foo.0098b) :good))
2388 (is (eql (funcall 'foo.0098b :x nil) :good))
2389 (is (eql (funcall 'foo.0098b :x "") 2.0))
2390 (is (eql (funcall 'foo.0098b :y 0) :good))
2391 (is (eql (funcall 'foo.0098b :y 1.0) :good))
2392 (is (eql (funcall 'foo.0098b :x "" :y 0) 1))
2393 (signals type-error (funcall 'foo.0098b :x :bad-arg))
2394 (signals type-error (funcall 'foo.0098b :y :bad-arg))
2395 (signals type-error (funcall 'foo.0098b :x nil :y :bad-arg))
2396 (signals type-error (funcall 'foo.0098b :x "" :y :bad-arg)))
2397
2398 ;;; Date 2024-12-17
2399 ;;; Description
2400 ;;;
2401 ;;; The bytecodes compiler does not enclose FLET/LABELS functions with their
2402 ;;; macroexpansion environment, leading to miscompilation in the C later.
2403 ;;;
2404 (test cmp.0099.bytecodes-flet-labels-enclose-macrolet
2405 (dolist (op '( flet labels))
2406 (let* ((form `(lambda ()
2407 (macrolet ((plops () 42))
2408 (,op ((a () (plops))) #'a))))
2409 (f1 (funcall (ext::bc-compile nil form)))
2410 (f2 (compile nil f1)))
2411 (is (nth-value 1 (function-lambda-expression f1)))
2412 (is (eql (funcall f1) 42))
2413 (finishes (is (eql (funcall f2) 42))))
2414 (let* ((form `(lambda ()
2415 (symbol-macrolet ((klops 96))
2416 (,op ((a () klops)) #'a))))
2417 (f1 (funcall (ext::bc-compile nil form)))
2418 (f2 (compile nil f1)))
2419 (is (nth-value 1 (function-lambda-expression f1)))
2420 (is (eql (funcall f1) 96))
2421 (finishes (is (eql (funcall f2) 96))))))
2422
2423 ;;; Date 2024-12-17
2424 ;;; Description
2425 ;;;
2426 ;;; While writing cmp.0099 and adding LABELS variant I've hit a stack
2427 ;;; overflow. This test encodes that particular failure. SET-CLOSURE-ENV
2428 ;;; recursively adds the reference to the function leading to the error. In
2429 ;;; this test we check whether this pitfall is avoided and whether compiled
2430 ;;; LABELS can still reference itself.
2431 ;;;
2432 (test cmp.0100.bytecodes-labels-stack-overflow
2433 (let ((fun (labels ((a (n)
2434 (if (zerop n)
2435 'banzai
2436 (a (1- n)))))
2437 #'a)))
2438 (multiple-value-bind (fun wrn err)
2439 (compile nil fun)
2440 (finishes (is (eql (funcall fun 4) 'banzai)))
2441 (is (null wrn))
2442 (is (null err)))))
2443
2444 ;;; Date 2024-12-18
2445 ;;; Description
2446 ;;;
2447 ;;; Test for an uncommited regression in the bytecodes compiler that was
2448 ;;; introduced while fixing cmp.0100 where we've made the single label share
2449 ;;; bindings among all function closures, or we've restored invalid lexenv,
2450 ;;; or that we've miscompiled closure by C compiler.
2451 ;;;
2452 (deftest cmp.0101.bytecodes-labels-false-sharing ()
2453 (flet ((make (start)
2454 (macrolet ((start-result () 'start))
2455 (labels ((fun (n)
2456 (if (zerop n)
2457 (start-result)
2458 (1+ (fun (1- n))))))
2459 #'fun))))
2460 (let ((f1 (make 3))
2461 (f2 (make 2)))
2462 (print (= (funcall f1 3) 6))
2463 (print (= (funcall f2 3) 5))
2464 (finishes (is (null (nth-value 2 (compile nil f1)))))
2465 (finishes (is (null (nth-value 2 (compile nil f2)))))
2466 (print (= (funcall f1 3) 6))
2467 (print (= (funcall f2 3) 5)))))
2468
2469 ;;; Date 2024-12-19
2470 ;;; Description
2471 ;;;
2472 ;;; Make sure that FLET and LABELS do not create a closure when the lexenv
2473 ;;; contains only objects that are not referenced. Similar to cmp.0066.
2474 ;;;
2475 (test cmp.0102.bytecodes-flat-closure
2476 (let ((fun (let ((b 3)) (flet ((a () 1)) #'a))))
2477 (is (null (nth-value 1 (function-lambda-expression fun)))))
2478 (let ((fun (let ((b 3)) (labels ((a () 1)) #'a))))
2479 (is (null (nth-value 1 (function-lambda-expression fun))))))
2480
2481 ;;; Date 2025-01-16
2482 ;;; Description
2483 ;;;
2484 ;;; Make sure that MACROLET closes around MACROLET (see #0099).
2485 ;;;
2486 (deftest cmp.0103.macrolet-over-macrolet ()
2487 (let* ((f0 (macrolet ((foo () `(list 1 2 3)))
2488 (lambda ()
2489 (macrolet ((bar () (let ((x (foo)))
2490 `(cons ',x 42))))
2491 (lambda () (bar))))))
2492 (f1 (compile nil f0))
2493 (f2 (ext::bc-compile nil f0)))
2494 (is (equal (funcall (funcall f0)) '((1 2 3) . 42)))
2495 (is (equal (funcall (funcall f1)) '((1 2 3) . 42)))
2496 (is (equal (funcall (funcall f2)) '((1 2 3) . 42)))))
2497
2498 (deftest cmp.0104.macrolet-over-symbol-macrolet ()
2499 (let* ((f0 (macrolet ((foo () `(list 1 2 3)))
2500 (lambda ()
2501 (symbol-macrolet ((bar (cons (foo) 42)))
2502 (lambda () bar)))))
2503 (f1 (compile nil f0))
2504 (f2 (ext::bc-compile nil f0)))
2505 (is (equal (funcall (funcall f0)) '((1 2 3) . 42)))
2506 (is (equal (funcall (funcall f1)) '((1 2 3) . 42)))
2507 (is (equal (funcall (funcall f2)) '((1 2 3) . 42)))))
2508
2509 (deftest cmp.0105.symbol-macrolet-over-macrolet ()
2510 (let* ((f0 (symbol-macrolet ((foo (list 1 2 3)))
2511 (lambda ()
2512 (macrolet ((bar () (let ((x foo))
2513 `(cons ',x 42))))
2514 (lambda () (bar))))))
2515 (f1 (compile nil f0))
2516 (f2 (ext::bc-compile nil f0)))
2517 (is (equal (funcall (funcall f0)) '((1 2 3) . 42)))
2518 (is (equal (funcall (funcall f1)) '((1 2 3) . 42)))
2519 (is (equal (funcall (funcall f2)) '((1 2 3) . 42)))))
2520
2521 (deftest cmp.0106.symbol-macrolet-over-symbol-macrolet ()
2522 (let* ((f0 (symbol-macrolet ((foo (list 1 2 3)))
2523 (lambda ()
2524 (symbol-macrolet ((bar (cons foo 42)))
2525 (lambda () bar)))))
2526 (f1 (compile nil f0))
2527 (f2 (ext::bc-compile nil f0)))
2528 (is (equal (funcall (funcall f0)) '((1 2 3) . 42)))
2529 (is (equal (funcall (funcall f1)) '((1 2 3) . 42)))
2530 (is (equal (funcall (funcall f2)) '((1 2 3) . 42)))))
2531
2532 ;;; When we compile a file it is sometimes not possible to store all definitions
2533 ;;; readably. Make sure that the compiler does not error in such cases.
2534 (deftest cmp.0107.unreadable-definition ()
2535 (finishes
2536 (with-compiler ("unreadable-definition.lsp")
2537 '(macrolet ((def-it (name)
2538 `(defun test () ,(find-package name))))
2539 (def-it "COMMON-LISP")))))
2540
2541 ;;; Date 2025-04-05
2542 ;;; URL: https://gitlab.com/embeddable-common-lisp/ecl/-/issues/774
2543 ;;; Description
2544 ;;;
2545 ;;; Calls to local functions with more arguments than
2546 ;;; si::c-arguments-limit did not work.
2547 ;;;
2548 (test cmp.0108.local-number-of-arguments
2549 (let* ((data1 (append (loop repeat (1+ si::c-arguments-limit) collect 0)))
2550 (data2 (funcall (compile nil `(lambda ()
2551 (flet ((f (&rest data)
2552 (make-array (length data) :initial-contents data)))
2553 (f ,@data1)))))))
2554 (is (equalp (make-array (length data1) :initial-contents data1)
2555 data2))))
2556
2557 ;;; Date 2025-05-27
2558 ;;; Description
2559 ;;;
2560 ;;; Passing environments between CCMP and BCMP in CMP-EVAL regressed after
2561 ;;; we've moved to a flat closure representation that requires storing the
2562 ;;; record position in the compiler env (in bytecmp). One of operators that
2563 ;;; call CMP-EVAL is LOAD-TIME-VALUE. Note that only compile-time objects
2564 ;;; like macros are available in the compiler environment.
2565 ;;;
2566 (deftest cmp.0109.eval-with-env-from-ccmp ()
2567 (finishes (funcall (compile nil
2568 '(lambda ()
2569 (macrolet ((woosh (&rest args)
2570 `(return-from ,@args)))
2571 (symbol-macrolet ((value -27))
2572 (load-time-value
2573 (block b4 (woosh b4 value))))))))))