1 ;;;; tests that dynamic-extent functionality works.
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
12 ;;;; more information.
14 (when (eq sb-ext
:*evaluator-mode
* :interpret
)
15 (sb-ext:quit
:unix-status
104))
17 (load "compiler-test-util.lisp")
20 (setq sb-c
::*check-consistency
* t
21 sb-ext
:*stack-allocate-dynamic-extent
* t
)
23 (defmacro defun-with-dx
(name arglist
&body body
)
24 `(defun ,name
,arglist
27 (declaim (notinline opaque-identity
))
28 (defun opaque-identity (x)
33 (defun-with-dx dxlength
(&rest rest
)
34 (declare (dynamic-extent rest
))
37 (with-test (:name
(:dx-
&rest
:basics
))
38 (assert (= (dxlength 1 2 3) 3))
39 (assert (= (dxlength t t t t t t
) 6))
40 (assert (= (dxlength) 0)))
43 (destructuring-bind (a b c d e f
&rest g
) list
44 (+ a b c d e f
(length g
))))
46 (defun-with-dx dxcaller
(&rest rest
)
47 (declare (dynamic-extent rest
))
50 (with-test (:name
(:dx-
&rest
:pass-down-to-callee
:tail-call
))
51 (assert (= (dxcaller 1 2 3 4 5 6 7) 22)))
53 (defun-with-dx dxcaller-align-1
(x &rest rest
)
54 (declare (dynamic-extent rest
))
57 (with-test (:name
(:dx-
&rest
:pass-down-to-callee
:non-tail-call
))
58 (assert (= (dxcaller-align-1 17 1 2 3 4 5 6 7) 39))
59 (assert (= (dxcaller-align-1 17 1 2 3 4 5 6 7 8) 40)))
63 (defun-with-dx test-nip-values
()
64 (flet ((bar (x &rest y
)
65 (declare (dynamic-extent y
))
69 (multiple-value-call #'values
73 (with-test (:name
(:nip-values
))
74 (assert (equal (multiple-value-list (test-nip-values)) '(1 5 a
))))
76 ;;; LET-variable substitution
78 (defun-with-dx test-let-var-subst1
(x)
79 (let ((y (list x
(1- x
))))
80 (opaque-identity :foo
)
81 (let ((z (the list y
)))
82 (declare (dynamic-extent z
))
85 (with-test (:name
(:let-variable-substitution
))
86 (assert (eql (test-let-var-subst1 17) 2)))
88 (defun-with-dx test-let-var-subst2
(x)
89 (let ((y (list x
(1- x
))))
90 (declare (dynamic-extent y
))
91 (opaque-identity :foo
)
92 (let ((z (the list y
)))
95 (with-test (:name
(:let-variable-substitution-2
))
96 (assert (eql (test-let-var-subst2 17) 2)))
99 ;;; DX propagation through LET-return.
101 (defun-with-dx test-lvar-subst
(x)
102 (let ((y (list x
(1- x
))))
103 (declare (dynamic-extent y
))
104 (second (let ((z (the list y
)))
105 (opaque-identity :foo
)
108 (with-test (:name
(:dx-propagation-through-let-return
))
109 (assert (eql (test-lvar-subst 11) 10)))
111 ;;; this code is incorrect, but the compiler should not fail
112 (defun-with-dx test-let-var-subst-incorrect
(x)
113 (let ((y (list x
(1- x
))))
114 (opaque-identity :foo
)
115 (let ((z (the list y
)))
116 (declare (dynamic-extent z
))
117 (opaque-identity :bar
)
123 (defun-with-dx test-alignment-dx-list
(form)
124 (multiple-value-prog1 (eval form
)
125 (let ((l (list 1 2 3 4)))
126 (declare (dynamic-extent l
))
127 (setq *x
* (copy-list l
)))))
129 (with-test (:name
(:dx-list
:alignment
))
131 (let* ((res (loop for i below n collect i
))
132 (form `(values ,@res
)))
133 (assert (equal (multiple-value-list (test-alignment-dx-list form
)) res
))
134 (assert (equal *x
* '(1 2 3 4))))))
138 (declaim (notinline true
))
143 (defun-with-dx dxclosure
(x)
146 (declare (dynamic-extent #'f
))
149 (with-test (:name
(:dx-closure
))
150 (assert (eq t
(dxclosure 13))))
154 (defun-with-dx dx-value-cell
(x)
155 ;; Not implemented everywhere, yet.
156 #+(or x86 x86-64 mips hppa
)
158 (declare (sb-int:truly-dynamic-extent cell
))
161 (declare (dynamic-extent #'f
))
166 (defun-with-dx cons-on-stack
(x)
167 (let ((cons (cons x x
)))
168 (declare (dynamic-extent cons
))
174 (defun force-make-array-on-stack (n)
175 (declare (optimize safety
))
176 (let ((v (make-array (min n
1))))
177 (declare (sb-int:truly-dynamic-extent v
))
181 (defun-with-dx make-array-on-stack-1
()
182 (let ((v (make-array '(42) :element-type
'single-float
)))
183 (declare (dynamic-extent v
))
187 (defun-with-dx make-array-on-stack-2
(n x
)
188 (declare (integer n
))
189 (let ((v (make-array n
:initial-contents x
)))
190 (declare (sb-int:truly-dynamic-extent v
))
194 (defun-with-dx make-array-on-stack-3
(x y z
)
195 (let ((v (make-array 3
196 :element-type
'fixnum
:initial-contents
(list x y z
)
197 :element-type t
:initial-contents x
)))
198 (declare (sb-int:truly-dynamic-extent v
))
202 (defun-with-dx make-array-on-stack-4
()
203 (let ((v (make-array 3 :initial-contents
'(1 2 3))))
204 (declare (sb-int:truly-dynamic-extent v
))
208 (defun-with-dx make-array-on-stack-5
()
209 (let ((v (make-array 3 :initial-element
12 :element-type t
)))
210 (declare (sb-int:truly-dynamic-extent v
))
214 (defun-with-dx vector-on-stack
(x y
)
215 (let ((v (vector 1 x
2 y
3)))
216 (declare (sb-int:truly-dynamic-extent v
))
222 (declaim (inline make-fp-struct-1
))
223 (defstruct fp-struct-1
224 (s 0.0 :type single-float
)
225 (d 0.0d0
:type double-float
))
227 (defun-with-dx test-fp-struct-1.1
(s d
)
228 (let ((fp (make-fp-struct-1 :s s
)))
229 (declare (dynamic-extent fp
))
230 (assert (eql s
(fp-struct-1-s fp
)))
231 (assert (eql 0.0d0
(fp-struct-1-d fp
)))))
233 (defun-with-dx test-fp-struct-1.2
(s d
)
234 (let ((fp (make-fp-struct-1 :d d
)))
235 (declare (dynamic-extent fp
))
236 (assert (eql 0.0 (fp-struct-1-s fp
)))
237 (assert (eql d
(fp-struct-1-d fp
)))))
239 (defun-with-dx test-fp-struct-1.3
(s d
)
240 (let ((fp (make-fp-struct-1 :d d
:s s
)))
241 (declare (dynamic-extent fp
))
242 (assert (eql s
(fp-struct-1-s fp
)))
243 (assert (eql d
(fp-struct-1-d fp
)))))
245 (defun-with-dx test-fp-struct-1.4
(s d
)
246 (let ((fp (make-fp-struct-1 :s s
:d d
)))
247 (declare (dynamic-extent fp
))
248 (assert (eql s
(fp-struct-1-s fp
)))
249 (assert (eql d
(fp-struct-1-d fp
)))))
251 (with-test (:name
(:test-fp-struct-1.1
))
252 (test-fp-struct-1.1
123.456 876.243d0
))
253 (with-test (:name
(:test-fp-struct-1.2
))
254 (test-fp-struct-1.2
123.456 876.243d0
))
255 (with-test (:name
(:test-fp-struct-1.3
))
256 (test-fp-struct-1.3
123.456 876.243d0
))
257 (with-test (:name
(:test-fp-struct-1.4
))
258 (test-fp-struct-1.4
123.456 876.243d0
))
260 (declaim (inline make-fp-struct-2
))
261 (defstruct fp-struct-2
262 (d 0.0d0
:type double-float
)
263 (s 0.0 :type single-float
))
265 (defun-with-dx test-fp-struct-2.1
(s d
)
266 (let ((fp (make-fp-struct-2 :s s
)))
267 (declare (dynamic-extent fp
))
268 (assert (eql s
(fp-struct-2-s fp
)))
269 (assert (eql 0.0d0
(fp-struct-2-d fp
)))))
271 (defun-with-dx test-fp-struct-2.2
(s d
)
272 (let ((fp (make-fp-struct-2 :d d
)))
273 (declare (dynamic-extent fp
))
274 (assert (eql 0.0 (fp-struct-2-s fp
)))
275 (assert (eql d
(fp-struct-2-d fp
)))))
277 (defun-with-dx test-fp-struct-2.3
(s d
)
278 (let ((fp (make-fp-struct-2 :d d
:s s
)))
279 (declare (dynamic-extent fp
))
280 (assert (eql s
(fp-struct-2-s fp
)))
281 (assert (eql d
(fp-struct-2-d fp
)))))
283 (defun-with-dx test-fp-struct-2.4
(s d
)
284 (let ((fp (make-fp-struct-2 :s s
:d d
)))
285 (declare (dynamic-extent fp
))
286 (assert (eql s
(fp-struct-2-s fp
)))
287 (assert (eql d
(fp-struct-2-d fp
)))))
289 (with-test (:name
(:test-fp-struct-2.1
))
290 (test-fp-struct-2.1
123.456 876.243d0
))
291 (with-test (:name
(:test-fp-struct-2.2
))
292 (test-fp-struct-2.2
123.456 876.243d0
))
293 (with-test (:name
(:test-fp-struct-2.3
))
294 (test-fp-struct-2.3
123.456 876.243d0
))
295 (with-test (:name
(:test-fp-struct-2.4
))
296 (test-fp-struct-2.4
123.456 876.243d0
))
298 (declaim (inline make-cfp-struct-1
))
299 (defstruct cfp-struct-1
300 (s (complex 0.0) :type
(complex single-float
))
301 (d (complex 0.0d0
) :type
(complex double-float
)))
303 (defun-with-dx test-cfp-struct-1.1
(s d
)
304 (let ((cfp (make-cfp-struct-1 :s s
)))
305 (declare (dynamic-extent cfp
))
306 (assert (eql s
(cfp-struct-1-s cfp
)))
307 (assert (eql (complex 0.0d0
) (cfp-struct-1-d cfp
)))))
309 (defun-with-dx test-cfp-struct-1.2
(s d
)
310 (let ((cfp (make-cfp-struct-1 :d d
)))
311 (declare (dynamic-extent cfp
))
312 (assert (eql (complex 0.0) (cfp-struct-1-s cfp
)))
313 (assert (eql d
(cfp-struct-1-d cfp
)))))
315 (defun-with-dx test-cfp-struct-1.3
(s d
)
316 (let ((cfp (make-cfp-struct-1 :d d
:s s
)))
317 (declare (dynamic-extent cfp
))
318 (assert (eql s
(cfp-struct-1-s cfp
)))
319 (assert (eql d
(cfp-struct-1-d cfp
)))))
321 (defun-with-dx test-cfp-struct-1.4
(s d
)
322 (let ((cfp (make-cfp-struct-1 :s s
:d d
)))
323 (declare (dynamic-extent cfp
))
324 (assert (eql s
(cfp-struct-1-s cfp
)))
325 (assert (eql d
(cfp-struct-1-d cfp
)))))
327 (with-test (:name
(:test-cfp-struct-1.1
))
328 (test-cfp-struct-1.1
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
329 (with-test (:name
(:test-cfp-struct-1.2
))
330 (test-cfp-struct-1.2
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
331 (with-test (:name
(:test-cfp-struct-1.3
))
332 (test-cfp-struct-1.3
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
333 (with-test (:name
(:test-cfp-struct-1.4
))
334 (test-cfp-struct-1.4
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
336 (declaim (inline make-cfp-struct-2
))
337 (defstruct cfp-struct-2
338 (d (complex 0.0d0
) :type
(complex double-float
))
339 (s (complex 0.0) :type
(complex single-float
)))
341 (defun-with-dx test-cfp-struct-2.1
(s d
)
342 (let ((cfp (make-cfp-struct-2 :s s
)))
343 (declare (dynamic-extent cfp
))
344 (assert (eql s
(cfp-struct-2-s cfp
)))
345 (assert (eql (complex 0.0d0
) (cfp-struct-2-d cfp
)))))
347 (defun-with-dx test-cfp-struct-2.2
(s d
)
348 (let ((cfp (make-cfp-struct-2 :d d
)))
349 (declare (dynamic-extent cfp
))
350 (assert (eql (complex 0.0) (cfp-struct-2-s cfp
)))
351 (assert (eql d
(cfp-struct-2-d cfp
)))))
353 (defun-with-dx test-cfp-struct-2.3
(s d
)
354 (let ((cfp (make-cfp-struct-2 :d d
:s s
)))
355 (declare (dynamic-extent cfp
))
356 (assert (eql s
(cfp-struct-2-s cfp
)))
357 (assert (eql d
(cfp-struct-2-d cfp
)))))
359 (defun-with-dx test-cfp-struct-2.4
(s d
)
360 (let ((cfp (make-cfp-struct-2 :s s
:d d
)))
361 (declare (dynamic-extent cfp
))
362 (assert (eql s
(cfp-struct-2-s cfp
)))
363 (assert (eql d
(cfp-struct-2-d cfp
)))))
365 (with-test (:name
(:test-cfp-struct-2.1
))
366 (test-cfp-struct-2.1
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
367 (with-test (:name
(:test-cfp-struct-2.2
))
368 (test-cfp-struct-2.2
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
369 (with-test (:name
(:test-cfp-struct-2.3
))
370 (test-cfp-struct-2.3
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
371 (with-test (:name
(:test-cfp-struct-2.4
))
372 (test-cfp-struct-2.4
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
)))
374 (declaim (inline make-foo1 make-foo2 make-foo3
))
377 (defun-with-dx make-foo1-on-stack
(x)
378 (let ((foo (make-foo1 :x x
)))
379 (declare (dynamic-extent foo
))
380 (assert (eql x
(foo1-x foo
)))))
383 (x 0.0 :type single-float
)
384 (y 0.0d0
:type double-float
)
389 (defun-with-dx make-foo2-on-stack
(x y
)
390 (let ((foo (make-foo2 :y y
:c
'c
)))
391 (declare (dynamic-extent foo
))
392 (assert (eql 0.0 (foo2-x foo
)))
393 (assert (eql y
(foo2-y foo
)))
394 (assert (eql 'c
(foo2-c foo
)))
395 (assert (eql nil
(foo2-b foo
)))))
397 ;;; Check that constants work out as argument for all relevant
402 (c 2 :type sb-vm
:word
)
403 (d 3.0 :type single-float
)
404 (e 4.0d0
:type double-float
))
406 (defun-with-dx make-foo3-on-stack
()
407 (let ((foo (make-foo3)))
408 (declare (dynamic-extent foo
))
409 (assert (eql 0 (foo3-a foo
)))
410 (assert (eql 1 (foo3-b foo
)))
411 (assert (eql 2 (foo3-c foo
)))
412 (assert (eql 3.0 (foo3-d foo
)))
413 (assert (eql 4.0d0
(foo3-e foo
)))))
417 (defun-with-dx nested-dx-lists
()
418 (let ((dx (list (list 1 2) (list 3 4))))
419 (declare (dynamic-extent dx
))
423 (defun-with-dx nested-dx-conses
()
424 (let ((dx (cons 1 (cons 2 (cons 3 (cons (cons t t
) nil
))))))
425 (declare (dynamic-extent dx
))
429 (defun-with-dx nested-dx-not-used
(x)
431 (let ((l (setf (car x
) (list x x x
))))
432 (declare (dynamic-extent l
))
437 (defun-with-dx nested-evil-dx-used
(x)
439 (let ((l (list x x x
)))
440 (declare (dynamic-extent l
))
448 (defparameter *bar
* nil
)
449 (declaim (inline make-nested-bad make-nested-good
))
450 (defstruct (nested (:constructor make-nested-bad
(&key bar
&aux
(bar (setf *bar
* bar
))))
451 (:constructor make-nested-good
(&key bar
)))
454 (defun-with-dx nested-good
(y)
455 (let ((x (list (list (make-nested-good :bar
(list (list (make-nested-good :bar
(list y
)))))))))
456 (declare (dynamic-extent x
))
459 (defun-with-dx nested-bad
(y)
460 (let ((x (list (list (make-nested-bad :bar
(list (list (make-nested-bad :bar
(list y
)))))))))
461 (declare (dynamic-extent x
))
462 (unless (equalp (caar x
) (make-nested-good :bar
*bar
*))
463 (error "got ~S, wanted ~S" (caar x
) (make-nested-good :bar
*bar
*)))
466 (with-test (:name
:conservative-nested-dx
)
467 ;; NESTED-BAD should not stack-allocate :BAR due to the SETF.
468 (assert (equalp (nested-bad 42) (make-nested-good :bar
*bar
*)))
469 (assert (equalp *bar
* (list (list (make-nested-bad :bar
(list 42)))))))
471 ;;; multiple uses for dx lvar
473 (defun-with-dx multiple-dx-uses
()
474 (let ((dx (if (true t
)
477 (declare (dynamic-extent dx
))
481 ;;; handler-case and handler-bind should use DX internally
483 (defun dx-handler-bind (x)
484 (handler-bind ((error
486 (break "OOPS: ~S caused ~S" x c
)))
487 ((and serious-condition
(not error
))
489 (break "OOPS2: ~S did ~S" x c
))))
492 (defun dx-handler-case (x)
493 (assert (zerop (handler-case (/ 2 x
)
495 (break "OOPS: ~S caused ~S" x c
)
500 (defvar *a-cons
* (cons nil nil
))
502 #+stack-allocatable-closures
503 (with-test (:name
(:no-consing
:dx-closures
))
504 (assert-no-consing (dxclosure 42)))
506 #+stack-allocatable-lists
507 (with-test (:name
(:no-consing
:dx-lists
))
508 (assert-no-consing (dxlength 1 2 3))
509 (assert-no-consing (dxlength t t t t t t
))
510 (assert-no-consing (dxlength))
511 (assert-no-consing (dxcaller 1 2 3 4 5 6 7))
512 (assert-no-consing (test-nip-values))
513 (assert-no-consing (test-let-var-subst2 17))
514 (assert-no-consing (test-lvar-subst 11))
515 (assert-no-consing (nested-dx-lists))
516 (assert-consing (nested-dx-not-used *a-cons
*))
517 (assert-no-consing (nested-evil-dx-used *a-cons
*))
518 (assert-no-consing (multiple-dx-uses)))
520 (with-test (:name
(:no-consing
:dx-value-cell
))
521 (assert-no-consing (dx-value-cell 13)))
523 #+stack-allocatable-fixed-objects
524 (with-test (:name
(:no-consing
:dx-fixed-objects
))
525 (assert-no-consing (cons-on-stack 42))
526 (assert-no-consing (make-foo1-on-stack 123))
527 (assert-no-consing (nested-good 42))
528 (assert-no-consing (nested-dx-conses))
529 (assert-no-consing (dx-handler-bind 2))
530 (assert-no-consing (dx-handler-case 2)))
532 #+stack-allocatable-vectors
533 (with-test (:name
(:no-consing
:dx-vectors
))
534 (assert-no-consing (force-make-array-on-stack 128))
535 (assert-no-consing (make-array-on-stack-1))
536 (assert-no-consing (make-array-on-stack-2 5 '(1 2.0 3 4.0 5)))
537 (assert-no-consing (make-array-on-stack-3 9 8 7))
538 (assert-no-consing (make-array-on-stack-4))
539 (assert-no-consing (make-array-on-stack-5))
540 (assert-no-consing (vector-on-stack :x
:y
)))
542 #+raw-instance-init-vops
543 (with-test (:name
(:no-consing
:dx-raw-instances
))
545 (setf a
1.24 b
1.23d0
)
546 (assert-no-consing (make-foo2-on-stack a b
)))
547 (assert-no-consing (make-foo3-on-stack)))
549 ;;; not really DX, but GETHASH and (SETF GETHASH) should not cons
551 (defvar *table
* (make-hash-table))
553 (defun test-hash-table ()
554 (setf (gethash 5 *table
*) 13)
557 (with-test (:name
(:no-consing
:hash-tables
))
558 (assert-no-consing (test-hash-table)))
560 ;;; with-spinlock and with-mutex should use DX and not cons
562 (defvar *slock
* (sb-thread::make-spinlock
:name
"slocklock"))
564 (defun test-spinlock ()
565 (sb-thread::with-spinlock
(*slock
*)
568 (defvar *mutex
* (sb-thread::make-mutex
:name
"mutexlock"))
571 (sb-thread:with-mutex
(*mutex
*)
575 (with-test (:name
(:no-consing
:mutex
))
576 (assert-no-consing (test-mutex)))
579 (with-test (:name
(:no-consing
:spinlock
))
580 (assert-no-consing (test-spinlock)))
584 ;;; Bugs found by Paul F. Dietz
586 (with-test (:name
(:dx-bug-misc
:pfdietz
))
593 (declare (optimize (speed 2) (space 0) (safety 0)
594 (debug 1) (compilation-speed 3)))
595 (let* ((v5 (cons b b
)))
596 (declare (dynamic-extent v5
))
601 ;;; bug reported by Svein Ove Aas
602 (defun svein-2005-ii-07 (x y
)
603 (declare (optimize (speed 3) (space 2) (safety 0) (debug 0)))
604 (let ((args (list* y
1 2 x
)))
605 (declare (dynamic-extent args
))
606 (apply #'aref args
)))
608 (with-test (:name
(:dx-bugs-misc
:svein-2005-ii-07
))
612 #3A
(((1 1 1) (1 1 1) (1 1 1))
613 ((1 1 1) (1 1 1) (4 1 1))
614 ((1 1 1) (1 1 1) (1 1 1))))
617 ;;; bug reported by Brian Downing: stack-allocated arrays were not
618 ;;; filled with zeroes.
619 (defun-with-dx bdowning-2005-iv-16
()
620 (let ((a (make-array 11 :initial-element
0)))
621 (declare (dynamic-extent a
))
622 (assert (every (lambda (x) (eql x
0)) a
))))
624 (with-test (:name
(:dx-bug-misc
:bdowning-2005-iv-16
))
625 #+(or hppa mips x86 x86-64
)
626 (assert-no-consing (bdowning-2005-iv-16))
627 (bdowning-2005-iv-16))
629 (declaim (inline my-nconc
))
630 (defun-with-dx my-nconc
(&rest lists
)
631 (declare (dynamic-extent lists
))
632 (apply #'nconc lists
))
633 (defun-with-dx my-nconc-caller
(a b c
)
634 (let ((l1 (list a b c
))
637 (with-test (:name
:rest-stops-the-buck
)
638 (let ((list1 (my-nconc-caller 1 2 3))
639 (list2 (my-nconc-caller 9 8 7)))
640 (assert (equal list1
'(1 2 3 1 2 3)))
641 (assert (equal list2
'(9 8 7 9 8 7)))))
643 (defun-with-dx let-converted-vars-dx-allocated-bug
(x y z
)
644 (let* ((a (list x y z
))
647 (declare (dynamic-extent c
))
648 (values (first c
) (second c
))))
649 (with-test (:name
:let-converted-vars-dx-allocated-bug
)
650 (multiple-value-bind (i j
) (let-converted-vars-dx-allocated-bug 1 2 3)
651 (assert (and (equal i j
)
652 (equal i
(list 1 2 3))))))
654 ;;; workaround for bug 419 -- real issue remains, but check that the
656 (defun-with-dx bug419
(x)
657 (multiple-value-call #'list
658 (eval '(values 1 2 3))
660 (declare (dynamic-extent x
))
665 (declare (dynamic-extent #'mget
#'mset
))
666 ((lambda (f g
) (eval `(progn ,f
,g
(values 4 5 6)))) #'mget
#'mset
)))))
668 (with-test (:name
(:dx-bug-misc
:bug419
))
669 (assert (equal (bug419 42) '(1 2 3 4 5 6))))
671 ;;; Multiple DX arguments in a local function call
672 (defun test-dx-flet-test (fun n f1 f2 f3
)
673 (let ((res (with-output-to-string (s)
674 (assert (eql n
(ignore-errors (funcall fun s
)))))))
675 (multiple-value-bind (x pos
) (read-from-string res nil
)
676 (assert (equalp f1 x
))
677 (multiple-value-bind (y pos2
) (read-from-string res nil nil
:start pos
)
678 (assert (equalp f2 y
))
679 (assert (equalp f3
(read-from-string res nil nil
:start pos2
))))))
680 #+(or hppa mips x86 x86-64
)
681 (assert-no-consing (assert (eql n
(funcall fun nil
))))
682 (assert (eql n
(funcall fun nil
))))
684 (macrolet ((def (n f1 f2 f3
)
685 (let ((name (sb-pcl::format-symbol
:cl-user
"DX-FLET-TEST.~A" n
)))
687 (defun-with-dx ,name
(s)
689 (declare (dynamic-extent x
))
698 (with-test (:name
(:dx-flet-test
,n
))
699 (test-dx-flet-test #',name
,n
,f1
,f2
,f3
))))))
700 (def 0 (list :one
) (list :two
) (list :three
))
701 (def 1 (make-array 128) (list 1 2 3 4 5 6 7 8) (list 'list
))
702 (def 2 (list 1) (list 2 3) (list 4 5 6 7)))
704 ;;; Test that unknown-values coming after a DX value won't mess up the
706 (defun test-update-uvl-live-sets (x y z
)
707 (declare (optimize speed
(safety 0)))
709 (declare (dynamic-extent a
))
710 (eval `(list (length ',a
) ',b
))))
712 (bar (list x y z
) ; dx push
714 (multiple-value-call 'list
715 (eval '(values 1 2 3)) ; uv push
721 (with-test (:name
(:update-uvl-live-sets
))
722 (assert (equal '((0 4) (3 ((1 2 3 5) 14)))
723 (test-update-uvl-live-sets #() 4 5))))
725 (with-test (:name
:regression-1.0
.23.38)
726 (compile nil
'(lambda ()
728 (let ((res (cons x x
)))
731 (declaim (inline make
))
732 (let ((z (make 1 2)))
733 (declare (dynamic-extent z
))
736 (compile nil
'(lambda ()
738 (let ((res (cons x x
)))
741 (declaim (inline make
))
742 (let ((z (make 1 2)))
743 (declare (dynamic-extent z
))
747 ;;; On x86 and x86-64 upto 1.0.28.16 LENGTH and WORDS argument
748 ;;; tns to ALLOCATE-VECTOR-ON-STACK could be packed in the same
749 ;;; location, leading to all manner of badness. ...reproducing this
750 ;;; reliably is hard, but this it at least used to break on x86-64.
751 (defun length-and-words-packed-in-same-tn (m)
752 (declare (optimize speed
(safety 0) (debug 0) (space 0)))
753 (let ((array (make-array (max 1 m
) :element-type
'fixnum
)))
754 (declare (dynamic-extent array
))
755 (array-total-size array
)))
756 (with-test (:name
:length-and-words-packed-in-same-tn
)
757 (assert (= 1 (length-and-words-packed-in-same-tn -
3))))
759 (with-test (:name
:handler-case-bogus-compiler-note
)
760 (handler-bind ((compiler-note #'error
))
761 ;; Taken from SWANK, used to signal a bogus stack allocation
764 `(lambda (files fasl-dir load
)
765 (let ((needs-recompile nil
))
767 (let ((dest (binary-pathname src fasl-dir
)))
770 (when (or needs-recompile
771 (not (probe-file dest
))
772 (file-newer-p src dest
))
773 (setq needs-recompile t
)
774 (ensure-directories-exist dest
)
775 (compile-file src
:output-file dest
:print nil
:verbose t
))
777 (load dest
:verbose t
)))
778 (serious-condition (c)
779 (handle-loadtime-error c dest
))))))))))
781 (declaim (inline foovector barvector
))
782 (defun foovector (x y z
)
783 (let ((v (make-array 3)))
788 (defun barvector (x y z
)
789 (make-array 3 :initial-contents
(list x y z
)))
790 (with-test (:name
:dx-compiler-notes
)
791 (flet ((assert-notes (j lambda
)
793 (handler-bind ((compiler-note (lambda (c)
798 (error "Wanted ~S notes, got ~S for~% ~S"
800 ;; These ones should complain.
801 (assert-notes 1 `(lambda (x)
802 (let ((v (make-array x
)))
803 (declare (dynamic-extent v
))
805 (assert-notes 2 `(lambda (x)
806 (let ((y (if (plusp x
)
809 (declare (dynamic-extent y
))
812 (assert-notes 1 `(lambda (x)
813 (let ((y (foovector x x x
)))
814 (declare (sb-int:truly-dynamic-extent y
))
817 ;; These ones should not complain.
818 (assert-notes 0 `(lambda (name)
820 ((posix-getenv (function c-string c-string
)
823 (alien-funcall posix-getenv name
)))))
824 (assert-notes 0 `(lambda (x)
825 (let ((y (barvector x x x
)))
826 (declare (dynamic-extent y
))
829 (assert-notes 0 `(lambda (list)
830 (declare (optimize (space 0)))
832 (assert-notes 0 `(lambda (other)
834 (ignore-errors (funcall other s c n
)))))))
836 ;;; Stack allocating a value cell in HANDLER-CASE would blow up stack
837 ;;; in an unfortunate loop.
838 (defun handler-case-eating-stack ()
840 (do ((n 0 (logand most-positive-fixnum
(1+ n
))))
842 (multiple-value-bind (value error
) (ignore-errors)
843 (when (and value error
) nil
))
845 (assert (= sp
(sb-c::%primitive sb-c
:current-stack-pointer
)))
846 (setf sp
(sb-c::%primitive sb-c
:current-stack-pointer
))))))
847 (with-test (:name
:handler-case-eating-stack
)
848 (assert-no-consing (handler-case-eating-stack)))
850 ;;; A nasty bug where RECHECK-DYNAMIC-EXTENT-LVARS thought something was going
851 ;;; to be stack allocated when it was not, leading to a bogus %NIP-VALUES.
852 ;;; Fixed by making RECHECK-DYNAMIC-EXTENT-LVARS deal properly with nested DX.
854 `(simple-array single-float
(3)))
855 (declaim (ftype (function (t t t
) vec
) vec
))
856 (declaim (inline vec
))
858 (make-array 3 :element-type
'single-float
:initial-contents
(list a b c
)))
860 (declare (type vec vec
))
862 (let ((vec (vec (aref vec
0) (aref vec
1) (aref vec
2))))
863 (declare (dynamic-extent vec
))
865 (with-test (:name
:recheck-nested-dx-bug
)
866 (assert (funcall (bad-boy (vec 1.0 2.0 3.3))
867 (lambda (vec) (equalp vec
(vec 1.0 2.0 3.3)))))
868 (flet ((foo (x) (declare (ignore x
))))
869 (let ((bad-boy (bad-boy (vec 2.0 3.0 4.0))))
870 (assert-no-consing (funcall bad-boy
#'foo
)))))
872 (with-test (:name
:bug-497321
)
873 (flet ((test (lambda type
)
875 (handler-bind ((condition (lambda (c)
877 (unless (typep c type
)
878 (error "wanted ~S for~% ~S~%got ~S"
879 type lambda
(type-of c
))))))
880 (compile nil lambda
))
882 (test `(lambda () (declare (dynamic-extent #'bar
)))
884 (test `(lambda () (declare (dynamic-extent bar
)))
886 (test `(lambda (bar) (cons bar
(lambda () (declare (dynamic-extent bar
)))))
887 'sb-ext
:compiler-note
)
890 (cons #'bar
(lambda () (declare (dynamic-extent #'bar
))))))
891 'sb-ext
:compiler-note
)))