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 (setq sb-c
::*check-consistency
* t
18 sb-ext
:*stack-allocate-dynamic-extent
* t
)
20 (defmacro defun-with-dx
(name arglist
&body body
)
21 `(defun ,name
,arglist
24 (declaim (notinline opaque-identity
))
25 (defun opaque-identity (x)
29 (defun-with-dx dxlength
(&rest rest
)
30 (declare (dynamic-extent rest
))
33 (assert (= (dxlength 1 2 3) 3))
34 (assert (= (dxlength t t t t t t
) 6))
35 (assert (= (dxlength) 0))
38 (destructuring-bind (a b c d e f
&rest g
) list
39 (+ a b c d e f
(length g
))))
41 (defun-with-dx dxcaller
(&rest rest
)
42 (declare (dynamic-extent rest
))
44 (assert (= (dxcaller 1 2 3 4 5 6 7) 22))
46 (defun-with-dx dxcaller-align-1
(x &rest rest
)
47 (declare (dynamic-extent rest
))
49 (assert (= (dxcaller-align-1 17 1 2 3 4 5 6 7) 39))
50 (assert (= (dxcaller-align-1 17 1 2 3 4 5 6 7 8) 40))
53 (defun-with-dx test-nip-values
()
54 (flet ((bar (x &rest y
)
55 (declare (dynamic-extent y
))
59 (multiple-value-call #'values
63 (assert (equal (multiple-value-list (test-nip-values)) '(1 5 a
)))
65 ;;; LET-variable substitution
66 (defun-with-dx test-let-var-subst1
(x)
67 (let ((y (list x
(1- x
))))
68 (opaque-identity :foo
)
69 (let ((z (the list y
)))
70 (declare (dynamic-extent z
))
72 (assert (eql (test-let-var-subst1 17) 2))
74 (defun-with-dx test-let-var-subst2
(x)
75 (let ((y (list x
(1- x
))))
76 (declare (dynamic-extent y
))
77 (opaque-identity :foo
)
78 (let ((z (the list y
)))
80 (assert (eql (test-let-var-subst2 17) 2))
82 ;;; DX propagation through LET-return.
83 (defun-with-dx test-lvar-subst
(x)
84 (let ((y (list x
(1- x
))))
85 (declare (dynamic-extent y
))
86 (second (let ((z (the list y
)))
87 (opaque-identity :foo
)
89 (assert (eql (test-lvar-subst 11) 10))
91 ;;; this code is incorrect, but the compiler should not fail
92 (defun-with-dx test-let-var-subst-incorrect
(x)
93 (let ((y (list x
(1- x
))))
94 (opaque-identity :foo
)
95 (let ((z (the list y
)))
96 (declare (dynamic-extent z
))
97 (opaque-identity :bar
)
102 (defun-with-dx test-alignment-dx-list
(form)
103 (multiple-value-prog1 (eval form
)
104 (let ((l (list 1 2 3 4)))
105 (declare (dynamic-extent l
))
106 (setq *x
* (copy-list l
)))))
108 (let* ((res (loop for i below n collect i
))
109 (form `(values ,@res
)))
110 (assert (equal (multiple-value-list (test-alignment-dx-list form
)) res
))
111 (assert (equal *x
* '(1 2 3 4)))))
115 (declaim (notinline true
))
120 (defun-with-dx dxclosure
(x)
123 (declare (dynamic-extent #'f
))
126 (assert (eq t
(dxclosure 13)))
130 (defun-with-dx dx-value-cell
(x)
131 ;; Not implemented everywhere, yet.
132 #+(or x86 x86-64 mips hppa
)
134 (declare (sb-int:truly-dynamic-extent cell
))
137 (declare (dynamic-extent #'f
))
142 (defun-with-dx cons-on-stack
(x)
143 (let ((cons (cons x x
)))
144 (declare (dynamic-extent cons
))
150 (defun force-make-array-on-stack (n)
151 (declare (optimize safety
))
152 (let ((v (make-array (min n
1))))
153 (declare (sb-int:truly-dynamic-extent v
))
157 (defun-with-dx make-array-on-stack-1
()
158 (let ((v (make-array '(42) :element-type
'single-float
)))
159 (declare (dynamic-extent v
))
163 (defun-with-dx make-array-on-stack-2
(n x
)
164 (declare (integer n
))
165 (let ((v (make-array n
:initial-contents x
)))
166 (declare (sb-int:truly-dynamic-extent v
))
170 (defun-with-dx make-array-on-stack-3
(x y z
)
171 (let ((v (make-array 3
172 :element-type
'fixnum
:initial-contents
(list x y z
)
173 :element-type t
:initial-contents x
)))
174 (declare (sb-int:truly-dynamic-extent v
))
178 (defun-with-dx make-array-on-stack-4
()
179 (let ((v (make-array 3 :initial-contents
'(1 2 3))))
180 (declare (sb-int:truly-dynamic-extent v
))
184 (defun-with-dx make-array-on-stack-5
()
185 (let ((v (make-array 3 :initial-element
12 :element-type t
)))
186 (declare (sb-int:truly-dynamic-extent v
))
190 (defun-with-dx vector-on-stack
(x y
)
191 (let ((v (vector 1 x
2 y
3)))
192 (declare (sb-int:truly-dynamic-extent v
))
198 (declaim (inline make-fp-struct-1
))
199 (defstruct fp-struct-1
200 (s 0.0 :type single-float
)
201 (d 0.0d0
:type double-float
))
203 (defun-with-dx test-fp-struct-1.1
(s d
)
204 (let ((fp (make-fp-struct-1 :s s
)))
205 (declare (dynamic-extent fp
))
206 (assert (eql s
(fp-struct-1-s fp
)))
207 (assert (eql 0.0d0
(fp-struct-1-d fp
)))))
209 (defun-with-dx test-fp-struct-1.2
(s d
)
210 (let ((fp (make-fp-struct-1 :d d
)))
211 (declare (dynamic-extent fp
))
212 (assert (eql 0.0 (fp-struct-1-s fp
)))
213 (assert (eql d
(fp-struct-1-d fp
)))))
215 (defun-with-dx test-fp-struct-1.3
(s d
)
216 (let ((fp (make-fp-struct-1 :d d
:s s
)))
217 (declare (dynamic-extent fp
))
218 (assert (eql s
(fp-struct-1-s fp
)))
219 (assert (eql d
(fp-struct-1-d fp
)))))
221 (defun-with-dx test-fp-struct-1.4
(s d
)
222 (let ((fp (make-fp-struct-1 :s s
:d d
)))
223 (declare (dynamic-extent fp
))
224 (assert (eql s
(fp-struct-1-s fp
)))
225 (assert (eql d
(fp-struct-1-d fp
)))))
227 (test-fp-struct-1.1
123.456 876.243d0
)
228 (test-fp-struct-1.2
123.456 876.243d0
)
229 (test-fp-struct-1.3
123.456 876.243d0
)
230 (test-fp-struct-1.4
123.456 876.243d0
)
232 (declaim (inline make-fp-struct-2
))
233 (defstruct fp-struct-2
234 (d 0.0d0
:type double-float
)
235 (s 0.0 :type single-float
))
237 (defun-with-dx test-fp-struct-2.1
(s d
)
238 (let ((fp (make-fp-struct-2 :s s
)))
239 (declare (dynamic-extent fp
))
240 (assert (eql s
(fp-struct-2-s fp
)))
241 (assert (eql 0.0d0
(fp-struct-2-d fp
)))))
243 (defun-with-dx test-fp-struct-2.2
(s d
)
244 (let ((fp (make-fp-struct-2 :d d
)))
245 (declare (dynamic-extent fp
))
246 (assert (eql 0.0 (fp-struct-2-s fp
)))
247 (assert (eql d
(fp-struct-2-d fp
)))))
249 (defun-with-dx test-fp-struct-2.3
(s d
)
250 (let ((fp (make-fp-struct-2 :d d
:s s
)))
251 (declare (dynamic-extent fp
))
252 (assert (eql s
(fp-struct-2-s fp
)))
253 (assert (eql d
(fp-struct-2-d fp
)))))
255 (defun-with-dx test-fp-struct-2.4
(s d
)
256 (let ((fp (make-fp-struct-2 :s s
:d d
)))
257 (declare (dynamic-extent fp
))
258 (assert (eql s
(fp-struct-2-s fp
)))
259 (assert (eql d
(fp-struct-2-d fp
)))))
261 (test-fp-struct-2.1
123.456 876.243d0
)
262 (test-fp-struct-2.2
123.456 876.243d0
)
263 (test-fp-struct-2.3
123.456 876.243d0
)
264 (test-fp-struct-2.4
123.456 876.243d0
)
266 (declaim (inline make-cfp-struct-1
))
267 (defstruct cfp-struct-1
268 (s (complex 0.0) :type
(complex single-float
))
269 (d (complex 0.0d0
) :type
(complex double-float
)))
271 (defun-with-dx test-cfp-struct-1.1
(s d
)
272 (let ((cfp (make-cfp-struct-1 :s s
)))
273 (declare (dynamic-extent cfp
))
274 (assert (eql s
(cfp-struct-1-s cfp
)))
275 (assert (eql (complex 0.0d0
) (cfp-struct-1-d cfp
)))))
277 (defun-with-dx test-cfp-struct-1.2
(s d
)
278 (let ((cfp (make-cfp-struct-1 :d d
)))
279 (declare (dynamic-extent cfp
))
280 (assert (eql (complex 0.0) (cfp-struct-1-s cfp
)))
281 (assert (eql d
(cfp-struct-1-d cfp
)))))
283 (defun-with-dx test-cfp-struct-1.3
(s d
)
284 (let ((cfp (make-cfp-struct-1 :d d
:s s
)))
285 (declare (dynamic-extent cfp
))
286 (assert (eql s
(cfp-struct-1-s cfp
)))
287 (assert (eql d
(cfp-struct-1-d cfp
)))))
289 (defun-with-dx test-cfp-struct-1.4
(s d
)
290 (let ((cfp (make-cfp-struct-1 :s s
:d d
)))
291 (declare (dynamic-extent cfp
))
292 (assert (eql s
(cfp-struct-1-s cfp
)))
293 (assert (eql d
(cfp-struct-1-d cfp
)))))
295 (test-cfp-struct-1.1
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
296 (test-cfp-struct-1.2
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
297 (test-cfp-struct-1.3
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
298 (test-cfp-struct-1.4
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
300 (declaim (inline make-cfp-struct-2
))
301 (defstruct cfp-struct-2
302 (d (complex 0.0d0
) :type
(complex double-float
))
303 (s (complex 0.0) :type
(complex single-float
)))
305 (defun-with-dx test-cfp-struct-2.1
(s d
)
306 (let ((cfp (make-cfp-struct-2 :s s
)))
307 (declare (dynamic-extent cfp
))
308 (assert (eql s
(cfp-struct-2-s cfp
)))
309 (assert (eql (complex 0.0d0
) (cfp-struct-2-d cfp
)))))
311 (defun-with-dx test-cfp-struct-2.2
(s d
)
312 (let ((cfp (make-cfp-struct-2 :d d
)))
313 (declare (dynamic-extent cfp
))
314 (assert (eql (complex 0.0) (cfp-struct-2-s cfp
)))
315 (assert (eql d
(cfp-struct-2-d cfp
)))))
317 (defun-with-dx test-cfp-struct-2.3
(s d
)
318 (let ((cfp (make-cfp-struct-2 :d d
:s s
)))
319 (declare (dynamic-extent cfp
))
320 (assert (eql s
(cfp-struct-2-s cfp
)))
321 (assert (eql d
(cfp-struct-2-d cfp
)))))
323 (defun-with-dx test-cfp-struct-2.4
(s d
)
324 (let ((cfp (make-cfp-struct-2 :s s
:d d
)))
325 (declare (dynamic-extent cfp
))
326 (assert (eql s
(cfp-struct-2-s cfp
)))
327 (assert (eql d
(cfp-struct-2-d cfp
)))))
329 (test-cfp-struct-2.1
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
330 (test-cfp-struct-2.2
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
331 (test-cfp-struct-2.3
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
332 (test-cfp-struct-2.4
(complex 0.123 123.456) (complex 908132.41d0
876.243d0
))
334 (declaim (inline make-foo1 make-foo2 make-foo3
))
337 (defun-with-dx make-foo1-on-stack
(x)
338 (let ((foo (make-foo1 :x x
)))
339 (declare (dynamic-extent foo
))
340 (assert (eql x
(foo1-x foo
)))))
343 (x 0.0 :type single-float
)
344 (y 0.0d0
:type double-float
)
349 (defmacro assert-eql
(expected got
)
350 `(let ((exp ,expected
)
352 (unless (eql exp got
)
353 (error "Expected ~S, got ~S!" exp got
))))
355 (defun-with-dx make-foo2-on-stack
(x y
)
356 (let ((foo (make-foo2 :y y
:c
'c
)))
357 (declare (dynamic-extent foo
))
358 (assert-eql 0.0 (foo2-x foo
))
359 (assert-eql y
(foo2-y foo
))
360 (assert-eql 'c
(foo2-c foo
))
361 (assert-eql nil
(foo2-b foo
))))
363 ;;; Check that constants work out as argument for all relevant
368 (c 2 :type sb-vm
:word
)
369 (d 3.0 :type single-float
)
370 (e 4.0d0
:type double-float
))
371 (defun-with-dx make-foo3-on-stack
()
372 (let ((foo (make-foo3)))
373 (declare (dynamic-extent foo
))
374 (assert (eql 0 (foo3-a foo
)))
375 (assert (eql 1 (foo3-b foo
)))
376 (assert (eql 2 (foo3-c foo
)))
377 (assert (eql 3.0 (foo3-d foo
)))
378 (assert (eql 4.0d0
(foo3-e foo
)))))
382 (defun-with-dx nested-dx-lists
()
383 (let ((dx (list (list 1 2) (list 3 4))))
384 (declare (dynamic-extent dx
))
388 (defun-with-dx nested-dx-conses
()
389 (let ((dx (cons 1 (cons 2 (cons 3 (cons (cons t t
) nil
))))))
390 (declare (dynamic-extent dx
))
394 (defun-with-dx nested-dx-not-used
(x)
396 (let ((l (setf (car x
) (list x x x
))))
397 (declare (dynamic-extent l
))
402 (defun-with-dx nested-evil-dx-used
(x)
404 (let ((l (list x x x
)))
405 (declare (dynamic-extent l
))
413 (defparameter *bar
* nil
)
414 (declaim (inline make-nested-bad make-nested-good
))
415 (defstruct (nested (:constructor make-nested-bad
(&key bar
&aux
(bar (setf *bar
* bar
))))
416 (:constructor make-nested-good
(&key bar
)))
419 (defun-with-dx nested-good
(y)
420 (let ((x (list (list (make-nested-good :bar
(list (list (make-nested-good :bar
(list y
)))))))))
421 (declare (dynamic-extent x
))
424 (defun-with-dx nested-bad
(y)
425 (let ((x (list (list (make-nested-bad :bar
(list (list (make-nested-bad :bar
(list y
)))))))))
426 (declare (dynamic-extent x
))
427 (unless (equalp (caar x
) (make-nested-good :bar
*bar
*))
428 (error "got ~S, wanted ~S" (caar x
) (make-nested-good :bar
*bar
*)))
431 (with-test (:name
:conservative-nested-dx
)
432 ;; NESTED-BAD should not stack-allocate :BAR due to the SETF.
433 (assert (equalp (nested-bad 42) (make-nested-good :bar
*bar
*)))
434 (assert (equalp *bar
* (list (list (make-nested-bad :bar
(list 42)))))))
436 ;;; multiple uses for dx lvar
438 (defun-with-dx multiple-dx-uses
()
439 (let ((dx (if (true t
)
442 (declare (dynamic-extent dx
))
446 ;;; handler-case and handler-bind should use DX internally
448 (defun dx-handler-bind (x)
449 (handler-bind ((error
450 (lambda (c) (break "OOPS: ~S caused ~S" x c
)))
451 ((and serious-condition
(not error
))
452 #'(lambda (c) (break "OOPS2: ~S did ~S" x c
))))
455 (defun dx-handler-case (x)
456 (assert (zerop (handler-case (/ 2 x
)
458 (break "OOPS: ~S caused ~S" x c
))
462 ;;; with-spinlock and with-mutex should use DX and not cons
464 (defvar *slock
* (sb-thread::make-spinlock
:name
"slocklock"))
466 (defun test-spinlock ()
467 (sb-thread::with-spinlock
(*slock
*)
470 (defvar *mutex
* (sb-thread::make-mutex
:name
"mutexlock"))
473 (sb-thread:with-mutex
(*mutex
*)
476 ;;; not really DX, but GETHASH and (SETF GETHASH) should not cons
478 (defvar *table
* (make-hash-table))
480 (defun test-hash-table ()
481 (setf (gethash 5 *table
*) 13)
484 (defmacro assert-no-consing
(form &optional times
)
485 `(%assert-no-consing
(lambda () ,form
) ,times
))
486 (defun %assert-no-consing
(thunk &optional times
)
487 (let ((before (get-bytes-consed))
488 (times (or times
10000)))
489 (declare (type (integer 1 *) times
))
492 (assert (< (- (get-bytes-consed) before
) times
))))
494 (defmacro assert-consing
(form &optional times
)
495 `(%assert-consing
(lambda () ,form
) ,times
))
496 (defun %assert-consing
(thunk &optional times
)
497 (let ((before (get-bytes-consed))
498 (times (or times
10000)))
499 (declare (type (integer 1 *) times
))
502 (assert (not (< (- (get-bytes-consed) before
) times
)))))
504 (defvar *a-cons
* (cons nil nil
))
507 #+stack-allocatable-closures
508 (assert-no-consing (dxclosure 42))
509 #+stack-allocatable-lists
511 (assert-no-consing (dxlength 1 2 3))
512 (assert-no-consing (dxlength t t t t t t
))
513 (assert-no-consing (dxlength))
514 (assert-no-consing (dxcaller 1 2 3 4 5 6 7))
515 (assert-no-consing (test-nip-values))
516 (assert-no-consing (test-let-var-subst2 17))
517 (assert-no-consing (test-lvar-subst 11))
518 (assert-no-consing (nested-dx-lists))
519 (assert-consing (nested-dx-not-used *a-cons
*))
520 (assert-no-consing (nested-evil-dx-used *a-cons
*))
521 (assert-no-consing (multiple-dx-uses)))
522 (assert-no-consing (dx-value-cell 13))
523 #+stack-allocatable-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)))
531 #+stack-allocatable-vectors
533 (assert-no-consing (force-make-array-on-stack 128))
534 (assert-no-consing (make-array-on-stack-1))
535 (assert-no-consing (make-array-on-stack-2 5 '(1 2.0 3 4.0 5)))
536 (assert-no-consing (make-array-on-stack-3 9 8 7))
537 (assert-no-consing (make-array-on-stack-4))
538 (assert-no-consing (make-array-on-stack-5))
539 (assert-no-consing (vector-on-stack :x
:y
)))
541 (setf a
1.24 b
1.23d0
)
542 (#+raw-instance-init-vops assert-no-consing
543 #-raw-instance-init-vops progn
544 (make-foo2-on-stack a b
)))
545 (#+raw-instance-init-vops assert-no-consing
546 #-raw-instance-init-vops progn
547 (make-foo3-on-stack))
549 (assert-no-consing (test-hash-table))
552 (assert-no-consing (test-spinlock))
553 (assert-no-consing (test-mutex))))
556 ;;; Bugs found by Paul F. Dietz
563 (declare (optimize (speed 2) (space 0) (safety 0)
564 (debug 1) (compilation-speed 3)))
565 (let* ((v5 (cons b b
)))
566 (declare (dynamic-extent v5
))
574 ;;; bug reported by Svein Ove Aas
575 (defun svein-2005-ii-07 (x y
)
576 (declare (optimize (speed 3) (space 2) (safety 0) (debug 0)))
577 (let ((args (list* y
1 2 x
)))
578 (declare (dynamic-extent args
))
579 (apply #'aref args
)))
583 #3A
(((1 1 1) (1 1 1) (1 1 1))
584 ((1 1 1) (1 1 1) (4 1 1))
585 ((1 1 1) (1 1 1) (1 1 1))))
588 ;;; bug reported by Brian Downing: stack-allocated arrays were not
589 ;;; filled with zeroes.
590 (defun-with-dx bdowning-2005-iv-16
()
591 (let ((a (make-array 11 :initial-element
0)))
592 (declare (dynamic-extent a
))
593 (assert (every (lambda (x) (eql x
0)) a
))))
594 (with-test (:name
:bdowning-2005-iv-16
)
595 #+(or hppa mips x86 x86-64
)
596 (assert-no-consing (bdowning-2005-iv-16))
597 (bdowning-2005-iv-16))
599 (declaim (inline my-nconc
))
600 (defun-with-dx my-nconc
(&rest lists
)
601 (declare (dynamic-extent lists
))
602 (apply #'nconc lists
))
603 (defun-with-dx my-nconc-caller
(a b c
)
604 (let ((l1 (list a b c
))
607 (with-test (:name
:rest-stops-the-buck
)
608 (let ((list1 (my-nconc-caller 1 2 3))
609 (list2 (my-nconc-caller 9 8 7)))
610 (assert (equal list1
'(1 2 3 1 2 3)))
611 (assert (equal list2
'(9 8 7 9 8 7)))))
613 (defun-with-dx let-converted-vars-dx-allocated-bug
(x y z
)
614 (let* ((a (list x y z
))
617 (declare (dynamic-extent c
))
618 (values (first c
) (second c
))))
619 (with-test (:name
:let-converted-vars-dx-allocated-bug
)
620 (multiple-value-bind (i j
) (let-converted-vars-dx-allocated-bug 1 2 3)
621 (assert (and (equal i j
)
622 (equal i
(list 1 2 3))))))
624 ;;; workaround for bug 419 -- real issue remains, but check that the
626 (defun-with-dx bug419
(x)
627 (multiple-value-call #'list
628 (eval '(values 1 2 3))
630 (declare (dynamic-extent x
))
635 (declare (dynamic-extent #'mget
#'mset
))
636 ((lambda (f g
) (eval `(progn ,f
,g
(values 4 5 6)))) #'mget
#'mset
)))))
637 (assert (equal (bug419 42) '(1 2 3 4 5 6)))
639 ;;; Multiple DX arguments in a local function call
640 (defun test-dx-flet-test (fun n f1 f2 f3
)
641 (let ((res (with-output-to-string (s)
642 (assert (eql n
(ignore-errors (funcall fun s
)))))))
643 (multiple-value-bind (x pos
) (read-from-string res nil
)
644 (assert (equalp f1 x
))
645 (multiple-value-bind (y pos2
) (read-from-string res nil nil
:start pos
)
646 (assert (equalp f2 y
))
647 (assert (equalp f3
(read-from-string res nil nil
:start pos2
))))))
648 #+(or hppa mips x86 x86-64
)
649 (assert-no-consing (assert (eql n
(funcall fun nil
))))
650 (assert (eql n
(funcall fun nil
))))
651 (macrolet ((def (n f1 f2 f3
)
652 (let ((name (sb-pcl::format-symbol
:cl-user
"DX-FLET-TEST.~A" n
)))
654 (defun-with-dx ,name
(s)
656 (declare (dynamic-extent x
))
665 (test-dx-flet-test #',name
,n
,f1
,f2
,f3
)))))
666 (def 0 (list :one
) (list :two
) (list :three
))
667 (def 1 (make-array 128) (list 1 2 3 4 5 6 7 8) (list 'list
))
668 (def 2 (list 1) (list 2 3) (list 4 5 6 7)))
670 ;;; Test that unknown-values coming after a DX value won't mess up the stack analysis
671 (defun test-update-uvl-live-sets (x y z
)
672 (declare (optimize speed
(safety 0)))
674 (declare (dynamic-extent a
))
675 (eval `(list (length ',a
) ',b
))))
677 (bar (list x y z
) ; dx push
679 (multiple-value-call 'list
680 (eval '(values 1 2 3)) ; uv push
685 (assert (equal '((0 4) (3 ((1 2 3 5) 14))) (test-update-uvl-live-sets #() 4 5)))
687 (with-test (:name
:regression-1.0
.23.38)
688 (compile nil
'(lambda ()
690 (let ((res (cons x x
)))
693 (declaim (inline make
))
694 (let ((z (make 1 2)))
695 (declare (dynamic-extent z
))
698 (compile nil
'(lambda ()
700 (let ((res (cons x x
)))
703 (declaim (inline make
))
704 (let ((z (make 1 2)))
705 (declare (dynamic-extent z
))
709 ;;; On x86 and x86-64 upto 1.0.28.16 LENGTH and WORDS argument
710 ;;; tns to ALLOCATE-VECTOR-ON-STACK could be packed in the same
711 ;;; location, leading to all manner of badness. ...reproducing this
712 ;;; reliably is hard, but this it at least used to break on x86-64.
713 (defun length-and-words-packed-in-same-tn (m)
714 (declare (optimize speed
(safety 0) (debug 0) (space 0)))
715 (let ((array (make-array (max 1 m
) :element-type
'fixnum
)))
716 (declare (dynamic-extent array
))
717 (array-total-size array
)))
718 (with-test (:name
:length-and-words-packed-in-same-tn
)
719 (assert (= 1 (length-and-words-packed-in-same-tn -
3))))
721 (with-test (:name
:handler-case-bogus-compiler-note
)
722 (handler-bind ((compiler-note #'error
))
723 ;; Taken from SWANK, used to signal a bogus stack allocation
726 `(lambda (files fasl-dir load
)
727 (let ((needs-recompile nil
))
729 (let ((dest (binary-pathname src fasl-dir
)))
732 (when (or needs-recompile
733 (not (probe-file dest
))
734 (file-newer-p src dest
))
735 (setq needs-recompile t
)
736 (ensure-directories-exist dest
)
737 (compile-file src
:output-file dest
:print nil
:verbose t
))
739 (load dest
:verbose t
)))
740 (serious-condition (c)
741 (handle-loadtime-error c dest
))))))))))
743 (declaim (inline foovector barvector
))
744 (defun foovector (x y z
)
745 (let ((v (make-array 3)))
750 (defun barvector (x y z
)
751 (make-array 3 :initial-contents
(list x y z
)))
752 (with-test (:name
:dx-compiler-notes
)
753 (flet ((assert-notes (j lambda
)
755 (handler-bind ((compiler-note (lambda (c)
756 (declare (ignore cc
))
760 (error "Wanted ~S notes, got ~S for~% ~S"
762 ;; These ones should complain.
763 (assert-notes 1 `(lambda (x)
764 (let ((v (make-array x
)))
765 (declare (dynamic-extent v
))
767 (assert-notes 2 `(lambda (x)
768 (let ((y (if (plusp x
)
771 (declare (dynamic-extent y
))
774 (assert-notes 1 `(lambda (x)
775 (let ((y (foovector x x x
)))
776 (declare (sb-int:truly-dynamic-extent y
))
779 ;; These ones should not complain.
780 (assert-notes 0 `(lambda (name)
782 ((posix-getenv (function c-string c-string
)
785 (alien-funcall posix-getenv name
)))))
786 (assert-notes 0 `(lambda (x)
787 (let ((y (barvector x x x
)))
788 (declare (dynamic-extent y
))
791 (assert-notes 0 `(lambda (list)
792 (declare (optimize (space 0)))
794 (assert-notes 0 `(lambda (other)
796 (ignore-errors (funcall other s c n
)))))))
798 ;;; Stack allocating a value cell in HANDLER-CASE would blow up stack
799 ;;; in an unfortunate loop.
800 (defun handler-case-eating-stack ()
802 (do ((n 0 (logand most-positive-fixnum
(1+ n
))))
804 (multiple-value-bind (value error
) (ignore-errors)
805 (when (and value error
) nil
))
807 (assert (= sp
(sb-c::%primitive sb-c
:current-stack-pointer
)))
808 (setf sp
(sb-c::%primitive sb-c
:current-stack-pointer
))))))
809 (with-test (:name
:handler-case-eating-stack
)
810 (assert-no-consing (handler-case-eating-stack)))
812 ;;; A nasty bug where RECHECK-DYNAMIC-EXTENT-LVARS thought something was going
813 ;;; to be stack allocated when it was not, leading to a bogus %NIP-VALUES.
814 ;;; Fixed by making RECHECK-DYNAMIC-EXTENT-LVARS deal properly with nested DX.
816 `(simple-array single-float
(3)))
817 (declaim (ftype (function (t t t
) vec
) vec
))
818 (declaim (inline vec
))
820 (make-array 3 :element-type
'single-float
:initial-contents
(list a b c
)))
822 (declare (type vec vec
))
824 (let ((vec (vec (aref vec
0) (aref vec
1) (aref vec
2))))
825 (declare (dynamic-extent vec
))
827 (with-test (:name
:recheck-nested-dx-bug
)
828 (assert (funcall (bad-boy (vec 1.0 2.0 3.3))
829 (lambda (vec) (equalp vec
(vec 1.0 2.0 3.3)))))
830 (flet ((foo (x) (declare (ignore x
))))
831 (let ((bad-boy (bad-boy (vec 2.0 3.0 4.0))))
832 (assert-no-consing (funcall bad-boy
#'foo
)))))