1 ;;;; various compiler tests without side effects
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 ;;;; This file of tests was added because the tests in 'compiler.pure.lisp'
15 ;;;; are a total hodgepodge- there is often no hugely compelling reason for
16 ;;;; their being tests of the compiler per se, such as whether
17 ;;;; INPUT-ERROR-IN-COMPILED-FILE is a subclass of SERIOUS-CONDITION;
18 ;;;; in addition to which it is near impossible to wade through the
19 ;;;; ton of nameless, slow, and noisy tests.
21 ;;;; This file strives to do better on all fronts:
22 ;;;; the tests should be fast, named, and not noisy.
24 (enable-test-parallelism)
26 (defun compiles-with-warning (lambda)
27 (assert (nth-value 2 (checked-compile lambda
:allow-warnings t
))))
29 (with-test (:name
:duplicate-labels
)
30 (dolist (operator '(labels flet macrolet
))
31 (multiple-value-bind (fun warn err
)
32 (let ((*error-output
* (make-broadcast-stream)))
33 (compile nil
`(lambda (x)
34 (declare (ignorable x
))
35 (,operator
((f (z) z
2)
38 ;; I'm not asserting on the result of calling FUN
39 ;; because I don't really care what it is.
40 (declare (ignore fun
))
41 (assert (and warn err
)))))
43 (with-test (:name
(position :derive-type
))
44 (checked-compile '(lambda (x)
45 (ash 1 (position (the (member a b c
) x
) #(a b c
)))))
46 (checked-compile '(lambda (x)
47 (ash 1 (position x
#(a b c
))))
48 :allow-style-warnings t
)
49 ;; The sequence must contain a mixture of symbols and non-symbols
50 ;; to call %FIND-POSITION. If only symbols, it makes no calls.
51 (let ((calls (ctu:ir1-funargs
'(lambda (x) (position x
'(1 2 3 a b c
4 5 6 d e f g
))))))
52 ;; Assert that the default :TEST of #'EQL was strength-reduced to #'EQ
53 (assert (equal calls
'((sb-kernel:%find-position identity eq
)))))
54 (checked-compile-and-assert ()
56 (position x
'(a b c d e d c b a
) :from-end t
))
60 (with-test (:name
(ldb :recognize-local-macros
))
61 ;; Should not call %LDB
65 (declare (optimize speed
))
66 (macrolet ((b () '(byte 2 2)))
67 (ldb (b) (the fixnum x
)))))
68 '(sb-c::check-ds-list
)))) ; why does this remain in the IR?
70 (with-test (:name
(dpb :eval-order
:lp-1458190
))
71 (sb-int:collect
((calls))
73 (dpb (progn (calls 'eval-new
) new
)
74 (progn (calls 'eval-byte
) (byte 10 10))
75 (progn (calls 'eval-old
) old
))))
77 (assert (equal (calls)
78 '(eval-new eval-byte eval-old
))))))
80 ;; Best practice treats TRULY-THE as a special operator, not a macro,
81 ;; in a context such as (DPB X (TRULY-THE SB-KERNEL:BYTE-SPECIFIER ...) Y).
82 ;; DPB used to expand its second argument using MACROEXPAND and lose
83 ;; the nuance of TRULY-THE. Strictly speaking, byte-specifier is not a
84 ;; type specifier that users are supposed to know about, so portable code
85 ;; should not care, but this might affect internal code.
86 (with-test (:name
(dpb :inner-macro
))
87 (flet ((source-xform (sexpr)
88 (funcall (sb-int:info
:function
:source-transform
(car sexpr
))
89 sexpr
(sb-kernel:make-null-lexenv
))))
90 (assert (equal-mod-gensyms
92 '(dpb (new) (truly-the sb-kernel
:byte-specifier bspec
) (old)))
94 (byte (truly-the sb-kernel
:byte-specifier bspec
)))
95 (sb-kernel:%dpb new
(byte-size byte
) (byte-position byte
)
98 (with-test (:name
:inline-satisfies-predicate
)
99 ;; If we remove the indirections in these functions,
100 ;; this test should visibly break so that we can write a new test
101 ;; that asserts that inlining F works in (THE (SATISFIES F) obj).
102 (assert (equal (sb-ext:typexpand
'sb-impl
::function-name
)
103 '(satisfies sb-int
:legal-fun-name-p
)))
104 (let ((f `(lambda (x) (the sb-impl
::function-name x
))))
105 (assert (equal (ctu:ir1-named-calls f
) '(sb-int:valid-function-name-p
))))
106 (let ((f `(lambda (x)
107 (declare (notinline sb-int
:legal-fun-name-p
))
108 (the sb-impl
::function-name x
))))
109 (assert (equal (ctu:ir1-named-calls f
) '(sb-int:legal-fun-name-p
)))))
111 (with-test (:name
(make-array :untestable-type
:no-warning
))
112 (checked-compile `(lambda () (make-array '(2 2)
113 :element-type
`(satisfies foofa
)))))
115 (with-test (:name
(make-array nil
:no-warning
))
116 (checked-compile '(lambda () (make-array '(2 2) :element-type nil
))))
118 (with-test (:name
(nth-value :huge-n
:works
))
119 (flet ((return-a-ton-of-values ()
120 (values-list (loop for i below
5000 collect i
))))
121 (assert (= (nth-value 1 (return-a-ton-of-values)) 1))
122 (assert (= (nth-value 4000 (return-a-ton-of-values)) 4000))))
124 (with-test (:name
:internal-name-p
:skipped-on
:sb-xref-for-internals
)
125 (assert (sb-c::internal-name-p
'sb-int
:neq
)))
127 (with-test (:name
(:coerce-callable-to-fun
:note
))
128 (flet ((try (form what
)
129 (multiple-value-bind (fun failure-p warnings style-warnings notes
)
130 (checked-compile `(lambda (x)
131 (declare (optimize speed
))
133 (declare (ignore fun failure-p warnings style-warnings
))
134 (assert (search (format nil
"~A is not known to be" what
)
135 (princ-to-string (first notes
)))))))
137 (try '(eval `(work-with ,x
)) "callable expression")
139 ;; For this I'd accept either Z or X in the message.
140 (try '(progn (let ((z x
)) (identity z
))) "X")))
142 (with-test (:name
(princ-to-string :unflushable
))
143 ;; Ordinary we'll flush it
144 (assert (not (ctu:ir1-named-calls
'(lambda (x) (princ-to-string x
) x
))))
145 ;; But in high safety it should be called for effect
146 (let ((f `(lambda (x)
147 (declare (optimize safety
)) (princ-to-string x
) x
)))
148 (assert (equal (ctu:ir1-named-calls f
) '(princ-to-string)))))
150 (with-test (:name
:space-bounds-no-consing
152 :skipped-on
:interpreter
)
153 ;; Asking for the size of a heap space should not cost anything!
154 (ctu:assert-no-consing
(sb-vm:%space-bounds
:static
))
155 (ctu:assert-no-consing
(sb-vm:space-bytes
:static
)))
157 (with-test (:name
(sb-vm:map-allocated-objects
:no-consing
)
159 :fails-on
(or :cheneygc
(not :sb-thread
))
160 :skipped-on
:interpreter
)
162 (sb-int:dx-flet
((f (obj type size
)
163 (declare (ignore obj type size
))
165 (ctu:assert-no-consing
166 (sb-vm:map-allocated-objects
#'f
:dynamic
)
169 (with-test (:name
:pack-varints-as-bignum
170 :skipped-on
:interpreter
) ; too slow
171 (dotimes (i 500) ; do some random testing this many times
172 (let* ((random-numbers (loop repeat
(+ (random 20) 3)
173 collect
(1+ (random 4000))))
174 (test-list (sort (delete-duplicates random-numbers
) #'<))
175 (packed-int (sb-c:pack-code-fixup-locs test-list nil nil
))
176 (result (make-array 1 :element-type
'(unsigned-byte 32))))
177 (sb-sys:with-pinned-objects
(packed-int result
)
178 ;; Now exercise the C unpacker.
179 ;; This hack of allocating 4 longs is terrible, but whatever.
180 (let ((unpacker (make-alien long
4))
182 (alien-funcall (extern-alien "varint_unpacker_init"
183 (function void
(* long
) unsigned
))
185 (sb-kernel:get-lisp-obj-address packed-int
))
186 (sb-int:collect
((unpacked))
190 (extern-alien "varint_unpack"
191 (function int
(* long
) system-area-pointer
))
192 unpacker
(sb-sys:vector-sap result
))))
193 (let ((val (aref result
0)))
194 ;; status of 0 is EOF, val = 0 means a decoded value was 0,
195 ;; which can't happen, so it's effectively EOF.
196 (when (or (eql status
0) (eql val
0)) (return))
197 (let ((loc (+ prev-loc val
)))
199 (setq prev-loc loc
)))))
200 (assert (equal (unpacked) test-list
))))))))
202 (with-test (:name
(symbol-value symbol-global-value
:quoted-constant
))
203 (let ((f (checked-compile '(lambda () (symbol-value 'char-code-limit
)))))
204 (assert (not (ctu:find-code-constants f
:type
'symbol
))))
205 (let ((f (checked-compile '(lambda () (symbol-global-value 'char-code-limit
)))))
206 (assert (not (ctu:find-code-constants f
:type
'symbol
)))))
208 (with-test (:name
(:set symbol-value
:of defglobal
))
209 (let ((s 'sb-c
::*recognized-declarations
*))
210 (assert (eq (sb-int:info
:variable
:kind s
) :global
)) ; verify precondition
211 (let ((f (checked-compile `(lambda () (setf (symbol-value ',s
) nil
)))))
212 ;; Should not have a call to SET-SYMBOL-GLOBAL-VALUE>
213 (assert (not (ctu:find-code-constants f
:type
'sb-kernel
:fdefn
))))))
215 (with-test (:name
:alien-linkage-table-bogosity
)
216 (let ((strings (map 'list
(lambda (x) (if (consp x
) (car x
) x
))
217 sb-vm
::+required-foreign-symbols
+)))
218 (assert (= (length (remove-duplicates strings
:test
'string
=))
221 (with-test (:name
(:no style-warning
:for inline
:cl-fun
))
222 (checked-compile '(lambda (x)
223 (declare (optimize (speed 3)) (inline length
)
224 (muffle-conditions compiler-note
))
227 (with-test (:name
:deleted-return-use
)
228 (checked-compile-and-assert ()
232 (let ((a (catch 'x
)))
233 (flet ((%f
(a &optional b
)
238 (with-test (:name
:shift-right-transform-nil-type
)
239 (checked-compile-and-assert (:optimize nil
)
241 (declare (type (integer -
10 -
6) c
)
242 (optimize (debug 2)))
244 (flet ((f1 (a &optional
(b (shiftf b
0)) c d
)
245 (declare (ignore a b c d
))
257 (with-test (:name
:move-lvar-result-through-unused-cast
)
258 (checked-compile-and-assert (:optimize nil
)
260 (declare (optimize (debug 0)))
264 (apply #'f
(list 2 3))))
265 (declare (notinline f
))
270 (with-test (:name
(:type-conflict funcall
:external-lambda
))
271 (compiles-with-warning `(lambda ()
272 (let ((x (lambda (x) (declare (fixnum x
)) x
)))
275 (with-test (:name
(:type-conflict
:callable
:external-lambda
))
276 (compiles-with-warning `(lambda ()
277 (let ((x (lambda (x) (declare (fixnum x
)) x
)))
278 (find-if x
"abca")))))
280 (with-test (:name
(:type-conflict map
:result-type
))
281 (compiles-with-warning `(lambda (str)
282 (map 'string
(lambda (x) (declare (ignore x
)) nil
)
285 (with-test (:name
(:type-conflict
:by-name
))
286 (compiles-with-warning `(lambda (str)
287 (map 'string
'evenp str
))))
289 (with-test (:name
(:type-conflict
:callable
:reporting
))
290 (multiple-value-bind (fun failure-p warnings
)
291 (checked-compile '(lambda (x) (map-into (make-string 10) #'evenp x
))
292 :allow-warnings
'warning
)
293 (declare (ignore fun
))
295 (assert (= (length warnings
) 1))
296 (search "Derived type of EVENP is"
297 (princ-to-string (first warnings
)))))
299 (with-test (:name
(:type-conflict string
:union-type
))
300 (compiles-with-warning `(lambda (x)
301 (find-if #'evenp
(the string x
)))))
303 (with-test (:name
(:type-conflict map-into
:let
))
304 (compiles-with-warning `(lambda (z)
306 (map-into z
#'evenp x
)))))
308 (with-test (:name
(:type-conflict map-into
:result
))
309 (compiles-with-warning `(lambda (z)
310 (map-into (make-string 10) #'evenp z
))))
312 (with-test (:name
(:type-conflict complement
))
316 (find z
"l" :test
(complement #'=)))
317 :allow-style-warnings t
))))
319 (with-test (:name
:type-across-hairy-lambda-transforms
)
320 (assert (subtypep (sb-kernel:%simple-fun-type
321 (checked-compile `(lambda (x) (find 1 (the vector x
)))))
322 '(function * (values (or (integer 1 1) null
) &optional
)))))
324 (with-test (:name
:lea-type-derivation
)
325 (checked-compile-and-assert ()
327 (declare ((integer -
3755795408964870057 -
3391381516052960895)
329 (ldb (byte 22 10) (* b
9)))
330 ((-3391381516052980893) 2826685)))
332 (with-test (:name
(:unused
&optional
:and
&key
))
333 (checked-compile-and-assert (:allow-style-warnings t
)
334 `(lambda (&optional x
&key
)
339 (with-test (:name
(:unknown values
:coercion
))
340 (checked-compile-and-assert ()
342 (declare (notinline values typep
))
343 (the integer
(values a
2305843009213693946 a -
207)))
344 ((123) (values 123 2305843009213693946 123 -
207))))
346 (with-test (:name
:deleted-block-during-generate-type-checks
)
347 (checked-compile-and-assert (:allow-warnings t
)
349 (declare (notinline min ash conjugate oddp
>=))
350 (if (and (or t
(>= a
)) (oddp 0))
353 (labels ((f (a b c
&key
)
354 (declare (ignore a b c
))
363 (ignore-errors (throw 'c
1))))
367 (with-test (:name
:block-delete-twice
)
368 (checked-compile-and-assert ()
370 (declare (notinline >=))
372 (lambda (x &key
(key (if (>= 0 1)
373 (return (catch 'ct5
0)))))
374 (declare (ignore key
))
376 (() 123 :test
(lambda (values expected
)
377 (equal (multiple-value-list
378 (funcall (first values
) (first expected
)))
381 (with-test (:name
:dead-lvars-and-stack-analysis
)
382 (checked-compile-and-assert ()
387 (multiple-value-prog1 19
389 (return-from b5
333)))))))
392 (with-test (:name
:mv-call-more-values
)
393 (checked-compile-and-assert ()
395 (multiple-value-call (lambda (&optional x y
&rest args
)
396 (declare (ignore args
))
401 (with-test (:name
:unused-casts-at-ir2-convert
)
402 (checked-compile-and-assert ()
406 (labels ((%f
(x &key
)
409 (unwind-protect (%f
(%f
0)))))))
412 (with-test (:name
:cmov-constants-different-primitive-type
)
413 (checked-compile-and-assert ()
416 ((2030) 4611686018427387908)
421 ((2030) 4611686018427387908)))
423 (with-test (:name
:mv-bind-skipping-vars-on-reoptimize
)
424 (checked-compile-and-assert ()
427 (apply (lambda (&rest args
)
428 (declare (ignore args
)))
434 (with-test (:name
:transform-on-a-nil-arg
)
435 (checked-compile-and-assert ()
439 (multiple-value-prog1
440 (unwind-protect (return 32))
441 (catch 'tag
(return 33)))
446 (with-test (:name
:nesteted-dx-deleted-uses
)
447 (checked-compile-and-assert ()
450 (let* ((v1 (make-array nil
:initial-element
452 (return-from b2 a
)))))
453 (declare (dynamic-extent v1
))
457 (with-test (:name
:deleted-during-locall-analyze-fun-1
)
458 (checked-compile-and-assert (:allow-warnings t
)
463 (() (condition 'program-error
))))
465 (with-test (:name
:delete-return-without-flush-dest
)
468 (funcall (checked-compile
471 (multiple-value-prog1 *
477 (with-test (:name
:let-conversion-inside-deleted-lambda
.1)
478 (checked-compile-and-assert ()
490 (with-test (:name
:let-conversion-inside-deleted-lambda
.2)
491 (checked-compile-and-assert ()
495 (lambda () (return)))
504 (with-test (:name
:assignment-conversion-inside-deleted-lambda
)
505 (checked-compile-and-assert
506 (:allow-style-warnings t
)
509 (labels ((%f13
(&optional
(f13-1 0) &key
&allow-other-keys
)
510 (declare (ignore f13-1
))
518 (with-test (:name
:nil-type-derived-before-assignment-conversion
)
519 (checked-compile-and-assert ()
527 (apply #'f
(catch 'ct
(go tag1
)) (list)))
531 (with-test (:name
:assignment-convert-untail-outside-calls
)
532 (checked-compile-and-assert ()
534 (flet ((%f17
(&optional f17-1
)
535 (declare (ignore f17-1
))
539 (return-from block606
)))
540 (declare (dynamic-extent #'h0
))
541 (return-from block608
543 (print #'h0
(make-broadcast-stream))
552 (with-test (:name
:assignment-convert-lambda-with-deleted-bind-block
)
553 (checked-compile-and-assert ()
556 (flet ((%f2
(&optional
(f2-2 (return-from %f5
1)))
566 (with-test (:name
:unconvert-tail-calls
)
567 (checked-compile-and-assert ()
570 (labels ((f (&optional
(a (return))
574 (declare (ignore a b c args
))
583 (with-test (:name
:deleting-exits-with-multiple-users
)
584 (checked-compile-and-assert ()
587 (multiple-value-prog1 b
588 (tagbody (return (multiple-value-prog1 3
589 (if a
(go z
)))) z
))))
593 (with-test (:name
:merge-tail-sets-deleted-functional
)
594 (checked-compile-and-assert ()
602 (let ((x (progn (lambda (&optional
(x a
)) x
)
604 (return-from b3 a
))))
605 (unwind-protect x
)))))))
608 (with-test (:name
:float-remainders-rounding-errors
)
609 (loop for fun in
'(ceiling truncate floor
610 fceiling ftruncate ffloor
613 (assert (member (second
614 (third (sb-kernel:%simple-fun-type
617 (nth-value 1 (,fun
(the double-float x
) 1/2)))))))
618 '(double-float real
)))))
620 (with-test (:name
:complex-float-contagion
)
621 (checked-compile-and-assert ()
623 (declare (type (or double-float integer
) p1
))
625 ((1d0) #c
(1d0 2d0
))))
627 (with-test (:name
:equal-transform-member-types
)
630 (checked-compile-and-assert ()
632 (declare (type (member ,s1
) p1
)
633 (type (member ,s2
#*10) p2
))
637 (with-test (:name
:equalp-transform-numeric-types
)
638 (checked-compile-and-assert ()
640 (declare (type (or fixnum list
) p1
)
641 (type double-float p2
))
645 (with-test (:name
:equalp-transform-zero-array
)
646 (checked-compile-and-assert ()
648 (declare (simple-string a
)
649 (simple-bit-vector b
))
653 (with-test (:name
:equalp-transform-zero-string
)
654 (checked-compile-and-assert
661 (with-test (:name
:fill-transform-returning-array-data
)
662 (let ((vector (make-array 10 :fill-pointer
2)))
663 (checked-compile-and-assert ()
665 (declare (type (vector t
) v
))
669 (with-test (:name
:missing-error-context
)
672 (with-output-to-string (*error-output
*)
673 (compile nil
'(sb-int:named-lambda bob
() (otherfun) 3)))))
674 (assert (search "in: SB-INT:NAMED-LAMBDA BOB" string
)))))
676 ;; Unrepeatability is confusing:
677 ;; The first compiler invocation used to leave *last-format-string*
678 ;; with a toplevel value, so the second would not print enough context
679 ;; because the format control and args were the same.
682 (with-test (:name
:cast-deletion-notes
)
683 (checked-compile-and-assert
686 (setf m
(list 1 2 3))
689 ((nil) #(1 2 3) :test
#'equalp
)))
691 (with-test (:name
:cast-deletion-notes
.2)
692 (multiple-value-bind (fun fail warn style notes
)
695 (setf m
(list 1 2 3))
700 (declare (ignore fail warn style
))
701 (assert (equalp (funcall fun nil
)
703 (assert (= (length notes
) 1))
704 (assert (typep (car notes
) 'code-deletion-note
))))
706 (with-test (:name
:array-call-type-deriver
)
707 (checked-compile-and-assert
710 (funcall (the (function (t t
)) #'aref
)
713 (((vector 333)) 333)))
715 (with-test (:name
:function-designator-cast-removal
)
716 (let ((fun (checked-compile
718 (declare (list vectors x
))
719 (map 'list
#'svref vectors x
)))))
720 (assert (notany (lambda (c)
723 (eq (sb-c::fdefn-name c
) 'svref
))
726 (ctu:find-code-constants fun
)))
727 (assert (equal (funcall fun
'(#(44)) '(0)) '(44)))))
729 (with-test (:name
:zombie-casts
)
730 (checked-compile-and-assert
736 (multiple-value-call #'f
737 (values (the integer
(unwind-protect (f 10 20)))
741 (with-test (:name
:zombie-casts
.2)
742 (let ((sb-c::*max-optimize-iterations
* 1))
743 (checked-compile-and-assert
746 (declare (type fixnum a b
))
747 (elt '(167992664 119771479)
750 (if (typep b
'(integer -
52))
756 (with-test (:name
:find-dfo-on-deleted-lambda
)
758 (funcall (checked-compile
760 (declare (notinline <))
766 (return (catch 'c
))))))
770 (with-test (:name
:ir1-ir2-dead-code-consistency
)
771 (checked-compile-and-assert
775 count
(zerop (min x x x x x x x x x x
))))
778 (with-test (:name
:ir1-ir2-dead-code-consistency
)
779 (checked-compile-and-assert
783 count
(zerop (min x x x x x x x x x x
))))
786 (with-test (:name
(setf svref
:constant-modification
))
788 (= (length (nth-value 2
791 (setf (svref #(a b c
) 1) x
))
792 :allow-warnings
'sb-int
:constant-modified
)))
795 (with-test (:name
(debug :constant-modification
))
797 (= (length (nth-value 2
800 (declare (optimize (debug 2)))
803 :allow-warnings
'sb-int
:constant-modified
)))
806 (with-test (:name
(debug :constant-modification
.2))
808 (= (length (nth-value 2
811 (declare (optimize (debug 2)))
816 :allow-warnings
'sb-int
:constant-modified
)))
819 (with-test (:name
(debug :unused-tn-long-arglist
))
820 (checked-compile-and-assert
823 (declare (sb-vm:word n
))
825 (nth-value 33 (funcall x .
#.
(loop for i to
35 collect i
))))
826 ((10 (lambda (&rest args
) (values-list args
))) 33)))
828 (with-test (:name
(debug :unused-tn-very-long-arglist
))
829 (checked-compile-and-assert
832 (declare (sb-vm:word n
))
834 (nth-value 33 (funcall x .
#.
(loop for i to
350 collect i
))))
835 ((10 (lambda (&rest args
) (values-list args
))) 33)))
837 (with-test (:name
(dynamic-extent :recursive-local-functions
))
840 (let ((s (labels ((%f
() (%f
)))
842 (declare (dynamic-extent s
))
845 (with-test (:name
(:ctypep
:hairy-types
))
848 (the (cons (satisfies error
)) '("a"))))
852 `(lambda () (the (array abc
) #()))
853 :allow-style-warnings t
))))
855 (with-test (:name
(catch :evaluate-tag-before-%catch
))
856 (checked-compile-and-assert
857 (:allow-style-warnings t
)
859 (catch (multiple-value-call #'+
860 (if z
1 (values 1 2)))
865 (with-test (:name
:nested-catch-progv-compile
)
869 (flet ((f (x &key
) x
(throw 'ct b
)))
871 (if (< (progv '() (f a
) 1) a
)
873 (catch 'ct
(f a
)))))))))
875 (with-test (:name
(tagbody :tag-dynamic-extent
))
876 (checked-compile-and-assert
877 (:optimize
'(:safety
3 :debug
2))
879 (declare (optimize (safety 3) (debug 2)))
881 (labels ((f (x &key
) x
(go tag6
)))
885 (dotimes (i 1) (f 1))
890 (with-test (:name
:fewer-cast-conversions
)
891 (multiple-value-bind (fun failed
)
894 (let* ((v (cons 0 (catch 'ct
(the integer nil
)))))
895 (declare (dynamic-extent v
))
900 (handler-bind ((error (lambda (c) c
(throw 'ct
33))))
901 (assert (= (funcall fun
) 33)))))
903 (with-test (:name
:constant-folding-with-callable-args
)
904 (checked-compile '(lambda () (count #'%f
'(a)))
905 :allow-style-warnings t
))
907 (with-test (:name
:flushable-with-callable-args
)
908 (assert (not (ctu:ir1-named-calls
909 '(lambda (y) (let ((x (count y
'(1 2 3))))
910 (declare (ignore x
))))))))
912 (with-test (:name
(remove :count
))
913 (checked-compile-and-assert
916 (remove x
"aaa" :count
2))
918 (checked-compile-and-assert
921 (remove-if (lambda (y) (eql y x
)) "aaa" :count
2))
924 (with-test (:name
(:constant-fold
:allow-other-keys
))
925 (checked-compile-and-assert
928 (reduce #'+ '(1 2 3) :allow-other-keys t
:bad x
))
931 (with-test (:name
(:constant-fold
:allow-other-keys
.2))
932 (checked-compile-and-assert
935 (reduce #'+ '(1 2 3) :allow-other-keys x
))
938 (with-test (:name
(:constant-fold
:repeat-keys
))
939 (checked-compile-and-assert
942 (member nil
'(1 2 3) :key
#'evenp
:key x
))
943 ((1) '(1 2 3) :test
#'equal
)))
947 (with-test (:name
:function-and-instance-primitive-type
)
948 (checked-compile-and-assert
951 (declare (function f
))
952 (the standard-object f
)
953 (funcall f
#'list t
))
954 ((#'documentation
) (documentation #'list t
))))
956 (with-test (:name
:mv-call-safety-0
)
957 (checked-compile-and-assert
960 (flet ((%f1
(x y
) (+ x y
)))
961 (apply #'%f1 a
(list 0))))
964 (with-test (:name
:cast-type-check-external
)
965 (checked-compile-and-assert
968 (declare (notinline +))
970 (loop for lv2 below
1
978 (with-test (:name
:flush-combination-non-fun-type
)
979 (checked-compile-and-assert
982 (rassoc-if-not #'values
'((1 . a
)) :allow-other-keys t
)
986 (with-test (:name
:symeval-nil
)
987 (checked-compile-and-assert
993 (with-test (:name
(:environment-analyze
:deleted-lambda
))
994 (checked-compile-and-assert
1000 (ignore-errors (format log
""))))
1003 (with-test (:name
(:ensure-lvar-fun-form
:lvar-uses
))
1004 (checked-compile-and-assert
1006 `(lambda (op) (funcall (case op
(equal '=) (t '=)) 1 2))
1010 (with-test (:name
:substitute-let-funargs-during-find-initial-dfo
)
1016 (%r
(lambda ()))))))
1018 (with-test (:name
:split-ir2-blocks-cmov
)
1019 (checked-compile-and-assert
1029 (with-test (:name
:=-rational-complex-rational-fold
)
1030 (let ((fun (checked-compile '(lambda (x)
1031 (declare ((complex integer
) x
))
1033 (fun2 (checked-compile '(lambda (x)
1034 (declare ((complex rational
) x
))
1036 (assert (equal (sb-kernel:%simple-fun-type fun
)
1037 '(function ((complex integer
)) (values null
&optional
))))
1038 (assert (not (funcall fun
#C
(10 10))))
1039 (assert (equal (sb-kernel:%simple-fun-type fun2
)
1040 '(function ((complex rational
)) (values null
&optional
))))
1041 (assert (not (funcall fun2
#C
(10 10))))))
1043 (with-test (:name
(:numeric float rational
:contagion
))
1044 (flet ((check (operator type argument
)
1045 (let ((fun (checked-compile
1047 (declare (type ,type x
))
1049 (1 `(,operator x
1/2))
1050 (2 `(,operator
1/2 x
)))))))
1051 (assert (null (ctu:find-code-constants fun
:type
'ratio
))))))
1052 (dolist (operator '(+ * / -
= < > <= >=))
1053 (dolist (type '(single-float double-float
))
1054 (check operator type
1)
1055 (check operator type
2)
1056 (when (member operator
'(+ * / -
=))
1057 (check operator
`(complex ,type
) 1)
1058 (check operator
`(complex ,type
) 2))))))
1060 (with-test (:name
(:numeric float float
:contagion
))
1061 (flet ((check (operator type argument
)
1062 (let ((fun (checked-compile
1064 (declare (type ,type x
))
1066 (1 `(,operator x
1.0f0
))
1067 (2 `(,operator
1.0f0 x
)))))))
1068 (assert (null (ctu:find-code-constants fun
:type
'single-float
))))))
1069 (dolist (operator '(+ * / -
= < > <= >=))
1070 (check operator
'double-float
1)
1071 (check operator
'double-float
2)
1072 (when (member operator
'(+ * / -
=))
1073 (check operator
'(complex double-float
) 1)
1074 (check operator
'(complex double-float
) 2)))))
1076 (with-test (:name
:find-type-deriver
)
1077 (checked-compile-and-assert
1080 (find 1 x
:key
#'values
))
1083 (with-test (:name
:tail-call-ltn-annotation
)
1084 (checked-compile-and-assert
1088 (multiple-value-call #'print
1093 (identity (ff1))))))
1095 (with-test (:name
(:substitute-lvar-uses
:deleted-code-and-dx-lvars
))
1096 (assert (nth-value 1
1103 (unwind-protect 1))))
1104 (declare (dynamic-extent v
))
1106 :allow-warnings t
))))
1108 (with-test (:name
(restart-case :declaration-processing
))
1109 (checked-compile-and-assert
1112 (restart-case (list)
1113 (my-restart (x) "foo" "bar" x
)))
1115 (checked-compile-and-assert
1118 (restart-case (list)
1119 (my-restart () (declare))))
1122 (with-test (:name
(handler-case :declaration-processing
))
1123 (checked-compile-and-assert
1126 (handler-case (list 1 2) (error (e) "foo" "bar" e
)))
1128 (assert (nth-value 1
1131 (handler-case (declare)))
1132 :allow-failure t
))))
1134 (with-test (:name
(:unconvert-tail-calls
:deleted-call
))
1135 (assert (nth-value 1
1138 (labels ((%f
(&optional
(x (* 2 nil
(%f
)))) x
))
1141 :allow-warnings t
))))
1143 (with-test (:name
(:equal-transform
:nil-types
))
1144 (assert (nth-value 1
1149 (not (or (>= y y
) (equal y -
787357528)))
1150 (the integer
(or (>= y y
) (equal y -
787357528))))))
1151 :allow-warnings t
))))
1155 (with-test (:name
(:delete-recursive-optional
))
1156 (checked-compile '(lambda (x)
1158 (labels ((f (&optional a
) (values x a
#'f
))))))))
1160 (with-test (:name
(:combination-args-flow-cleanly-p
:unused-result
))
1161 (checked-compile-and-assert
1164 (let ((v (flet ((%f
(x)
1168 (declare (dynamic-extent v
))
1172 (with-test (:name
(:delete-ref
:maintain-lambda-calls-or-closes
))
1173 (checked-compile `(lambda (c y
)
1189 (with-test (:name
(the :nil-type
))
1192 (flet ((f () (the nil
0)))
1195 (with-test (:name
:concatenate-transform-hairy-type
)
1198 (concatenate '(and string
(satisfies eval
)) x
))))
1200 (with-test (:name
:make-array-transform-deletion-notes
)
1203 (let* ((length (length vector
))
1204 (new (make-array length
:adjustable t
1205 :fill-pointer length
)))
1209 (with-test (:name
:ltn-analyze-cast-unlink
)
1210 (assert (nth-value 1 (checked-compile
1213 (let ((p (make-array n
:element-type
'double-float
)))
1216 (ignore-errors i
)))))
1217 :allow-warnings t
))))
1219 (with-test (:name
:call-type-validation
)
1222 (funcall (the (or cons function
) *debugger-hook
*)))))
1224 (with-test (:name
:setf-schar-hairy-types
)
1225 (checked-compile-and-assert
1228 (setf (schar (the (satisfies eval
) s
) 0) v
)
1230 (((copy-seq "abc") #\m
) "mbc" :test
#'equal
)))
1232 (with-test (:name
:replace-zero-elements
)
1233 (checked-compile-and-assert
1236 (declare ((simple-vector 2) x
))
1237 (replace x x
:start1
2))
1238 (((vector 1 2)) #(1 2) :test
#'equalp
))
1239 (checked-compile-and-assert
1242 (replace x x
:start1
2))
1243 (((vector 1 2)) #(1 2) :test
#'equalp
)))
1245 (with-test (:name
:error-in-xep
)
1246 (checked-compile-and-assert
1249 (declare (type (satisfies error
) x
))
1251 (("") (condition 'error
))))
1253 (with-test (:name
:lifetime-analyze-tn-overflow-unused-tns
)
1254 (checked-compile-and-assert
1257 (multiple-value-bind (a b c
)
1258 (funcall x
1 2 3 ,@(make-list 58))
1259 (declare (ignore b
))
1261 ((#'values
) (values 1 3))))
1263 (with-test (:name
:constraints-not-enough-args
)
1264 (checked-compile-and-assert
1267 (delete-if #'> (the list list
)))
1270 (with-test (:name
:%coerce-callable-for-call-removal-order-mv-call
)
1271 (checked-compile-and-assert
1275 (let ((result (apply fun args
)))
1278 (setf args result
))))
1279 (('list
'(1)) '(1) :test
#'equal
)))
1281 (with-test (:name
:constraint-loop
)
1282 (checked-compile-and-assert
1287 (mapcar #'identity a
)
1288 (loop for c from
0 do
(loop for d in b do
1289 (loop for e in a
)))))))
1291 (with-test (:name
:primitive-type-fun-designator
)
1292 (checked-compile-and-assert
1295 (map 'vector fun
'(1 2 3)))
1296 (('1+) #(2 3 4) :test
#'equalp
)))
1298 (with-test (:name
:mv-call-lambda-type-derivation
)
1300 (equal (sb-kernel:%simple-fun-type
1303 (multiple-value-call
1306 '(function (t) (values (integer 133 133) &optional
)))))
1308 (with-test (:name
:mv-call-lambda-type-derivation.closure
)
1310 (equal (sb-kernel:%simple-fun-type
1313 (multiple-value-call
1314 (lambda () (print x
) 133)
1316 '(function (t) (values (integer 133 133) &optional
)))))
1318 (with-test (:name
:constant-folding-and-hairy-types
)
1319 (checked-compile-and-assert
1322 (> 0 (the (satisfies eval
) (- 1))))
1325 (with-test (:name
:type-approximate-interval-and-hairy-types
)
1326 (checked-compile-and-assert
1329 (declare (fixnum x
))
1330 (<= (the (satisfies eval
) 65) x
))
1333 (with-test (:name
:remove-equivalent-blocks-constraints
)
1334 (checked-compile-and-assert
1337 (declare (integer c
))
1344 (with-test (:name
:typep-singleton-intersect-types
)
1345 (checked-compile-and-assert
1351 (with-test (:name
:constants-and-cmp
)
1352 (checked-compile-and-assert
1355 (declare (fixnum l
))
1362 (checked-compile-and-assert
1365 (declare (fixnum l
))
1373 (with-test (:name
:inlining-and-substituted-block-lvars
)
1374 (checked-compile-and-assert
1380 (declare (inline f
))
1381 (funcall (the function
#'f
) t
)
1382 (funcall (the function
#'f
) t
)))))
1387 (with-test (:name
:inlining-reanlyzing-optionals
)
1388 (checked-compile-and-assert
1398 (declare (inline w
))
1401 (with-test (:name
:vector-fill
/t-fast-safe
)
1402 (let ((sb-c::*policy-min
* sb-c
::*policy-min
*))
1403 (sb-ext:restrict-compiler-policy
'safety
1)
1404 (checked-compile-and-assert
1407 (make-array 2 :initial-element
10))
1408 (() #(10 10) :test
#'equalp
))))
1410 (with-test (:name
:deleted-tail-sets
)
1411 (checked-compile-and-assert
1414 (labels ((f (&optional
(a (catch t
6))
1416 (c (unwind-protect 1)))
1418 (unwind-protect (f 4))))
1419 (() (condition 'error
))))
1421 ;;; The SLEEP source transform barfed on float positive infinity
1423 (with-test (:name
(compile sleep float
:infinity
:lp-1754081
))
1424 (checked-compile '(lambda () (sleep single-float-positive-infinity
)))
1425 (checked-compile '(lambda () (sleep double-float-positive-infinity
))))
1426 ;;; And it didn't work at all after the fix for aforementioned
1427 (with-test (:name
:sleep-float-transform
1428 :skipped-on
(and :win32
(not :sb-thread
)))
1429 (let* ((xform (car (sb-c::fun-info-transforms
(sb-int:info
:function
:info
'sleep
))))
1430 (type (car (sb-kernel:fun-type-required
(sb-c::transform-type xform
)))))
1431 (assert (sb-kernel:constant-type-p type
))
1432 ;; CONSTANT-TYPE isn't actually testable through CTYPEP.
1433 ;; So pull out the actual type as the compiler would do.
1434 (assert (sb-kernel:ctypep
1.5 (sb-kernel:constant-type-type type
)))))
1436 (with-test (:name
:atanh-type-derivation
)
1437 (checked-compile-and-assert
1440 (atanh (coerce x
'(double-float * (0.0d0
)))))))
1442 (with-test (:name
:ir1-optimize-combination-unknown-keys
)
1443 (checked-compile-and-assert
1446 (let ((f (when p
#'string-equal
)))
1448 (funcall f
"a" "b" x y
))))
1449 ((t :start1
0) nil
)))
1451 (with-test (:name
:member-transform
)
1452 (let ((list '(2 1 3)))
1453 (checked-compile-and-assert
1455 '(lambda (list &key key
)
1456 (member 1 list
:key key
))
1457 ((list) (cdr list
)))))
1459 (with-test (:name
:note-no-stack-allocation-casts
)
1460 (checked-compile-and-assert
1463 (let ((*s
* (the integer
(catch 'ct1
0))))
1464 (declare (dynamic-extent *s
*)
1467 (with-test (:name
:dxify-downward-funargs-variable-name
)
1468 (checked-compile-and-assert
1470 '(lambda () ((lambda (map) (funcall map
)) #'list
))))
1472 (with-test (:name
:dxify-downward-funargs-malformed
)
1474 '(lambda () (sb-debug:map-backtrace
))
1475 :allow-style-warnings t
))
1477 (with-test (:name
:dxify-downward-funargs-casts
)
1478 (checked-compile-and-assert
1481 (flet ((f (y) (funcall f y
)))
1482 (funcall (the (satisfies eval
) #'every
) #'f x
)))
1483 ((#'evenp
'(2 2 4)) t
)))
1485 (with-test (:name
:array-call-type-deriver-non-fun-type
)
1486 (checked-compile-and-assert
1488 '(lambda (x) (funcall (the compiled-function
#'aref
) x
))
1491 (with-test (:name
:nth-
&rest-overflow
)
1492 (checked-compile-and-assert
1494 '(lambda (&rest s
) (nth 536870908 s
))
1498 (with-test (:name
:array-in-bounds-p-transform-hairy-types
)
1499 (checked-compile-and-assert
1502 (let ((a (the (satisfies eval
) (make-array 4 :fill-pointer
0))))
1503 (and (array-in-bounds-p a
0)
1504 (array-in-bounds-p a
1))))
1507 (with-test (:name
:array-type-dimensions-or-give-up-hairy-types
)
1508 (checked-compile-and-assert
1511 (declare ((or (array * (1)) (satisfies eval
)) a
))
1512 (array-row-major-index a i
))
1515 (with-test (:name
:array-type-dimensions-0-rank
)
1516 (checked-compile-and-assert
1519 (declare ((or (array bit
1) (array * 0)) p1
))
1520 (array-total-size p1
))
1523 (with-test (:name
:type-derivation-hairy-types
)
1524 (checked-compile-and-assert
1527 (declare (fixnum n
))
1528 (ash (the (satisfies eval
) n
)
1529 (the (integer * 0) s
)))
1531 (checked-compile-and-assert
1534 (declare (type (member #c
(0.5d0
4.0d0
) #c
(0 -
1)) p
))
1535 (/ (the (satisfies eval
) p
)))
1536 ((#c
(0 -
1)) #C
(0 1))))
1538 (with-test (:name
:assert-lvar-type-intersection
)
1539 (checked-compile-and-assert
1542 (write-sequence nil
(the standard-object x
) y nil
))))
1544 (with-test (:name
:or-bignum-single-float-no-notes
1545 :skipped-on
(not (or :arm64 ppc
:x86
:x86-64
)))
1547 '(lambda (x) (declare (optimize speed
)) (typep x
'(or bignum single-float
)))
1551 (with-test (:name
:vertices-best-color
/general-default-value
)
1552 (checked-compile-and-assert
1555 (declare ((simple-array (complex double-float
)) a
))
1557 (let ((z (aref a
0)))
1558 (complex (realpart z
) (imagpart z
)))))))
1560 (with-test (:name
:copy-list-inlined
)
1561 (let ((f (checked-compile
1562 `(lambda (x) (declare (optimize speed
)) (copy-list x
)))))
1563 ;; Should not have a call to COPY-LIST (or anything)
1564 (assert (not (ctu:find-code-constants f
:type
'sb-kernel
:fdefn
)))))
1566 (with-test (:name
:move-from-fixnum
+-
1)
1567 (checked-compile-and-assert
1570 (declare (fixnum x
))
1573 ((most-positive-fixnum) (1- most-positive-fixnum
))
1574 ((most-negative-fixnum) (1- most-negative-fixnum
)))
1575 (checked-compile-and-assert
1578 (declare (fixnum x
))
1581 ((most-positive-fixnum) (1+ most-positive-fixnum
))
1582 ((most-negative-fixnum) (1+ most-negative-fixnum
)))
1583 (checked-compile-and-assert
1586 (declare (fixnum x
))
1592 ((nil most-positive-fixnum
) (1+ most-positive-fixnum
))
1593 ((nil most-negative-fixnum
) (1+ most-negative-fixnum
))))
1595 (with-test (:name
:coalesce-more-ltn-numbers-constants
)
1596 (checked-compile-and-assert
1599 (list 1 1 ,@(make-list 100 :initial-element
'x
)))
1600 ((1) (make-list 102 :initial-element
1) :test
#'equal
)))
1602 (with-test (:name
(:lambda-var-ref-lvar
:multiple-refs
))
1603 (checked-compile-and-assert
1605 `(lambda (vector index
)
1606 (labels ((update (index)
1607 (let ((old (svref vector index
)))
1616 (with-test (:name
:string-type-unparsing
)
1617 (checked-compile-and-assert
1620 (declare (type (string 1) s
))
1621 (the (or simple-array
(member 1/2 "ba" 0 #\
3)) s
))
1624 (with-test (:name
:primitive-type-function
)
1625 (checked-compile-and-assert
1628 (funcall (the (and atom
(not null
)) x
))
1633 (with-test (:name
:copyprop-sc-mismatch-between-moves
1635 :skipped-on
:interpreter
)
1636 (let ((f (checked-compile
1638 (let ((x (the double-float x
)))
1639 (values (funcall f x
) (> x
1d0
)))))))
1640 (ctu:assert-no-consing
(funcall f
#'identity
1d0
))))
1642 (with-test (:name
(:infer-iteration-var-type
:step-is-range
))
1643 (let ((f (checked-compile
1645 (declare ((integer 1 2) s
))
1647 (loop for i from
16 below
32 by s
1650 (assert (equal (sb-impl::%simple-fun-type f
)
1651 '(function ((integer 1 2)) (values (integer 16 31) &optional
))))))
1653 (with-test (:name
(:infer-iteration-var-type
:multiple-sets
))
1654 (let ((f (checked-compile
1656 (declare (optimize speed
)
1657 (type (integer 3 10) x
))
1668 (assert (equal (sb-impl::%simple-fun-type f
)
1669 '(function ((integer 3 10)) (values (integer 0 0) &optional
))))))
1671 (with-test (:name
(:infer-iteration-var-type
:incompatible-sets
))
1672 (checked-compile-and-assert ()
1673 '(lambda (input-total missing-amount
)
1674 (declare (fixnum input-total
) (fixnum missing-amount
))
1677 do
(let ((difference input-total
))
1678 (setq difference
(max difference
0))
1679 (setq tot
(+ tot difference
)))
1680 finally
(when (plusp missing-amount
)
1681 (decf tot missing-amount
))
1682 (return (if (plusp tot
) :good
:bad
))))
1688 (with-test (:name
:delay-transform-until-constraint-loop
)
1689 (checked-compile-and-assert
1692 (declare (string str
))
1693 (when (plusp (length str
))
1694 (make-array (1- (length str
))
1695 :element-type
(array-element-type str
)
1696 :displaced-to str
)))
1697 (("abc") "ab" :test
#'equal
)))
1699 (with-test (:name
:lambda-var-ref-lvar-loop
)
1700 (checked-compile-and-assert
1704 (when (>= 0 (the integer a
))
1708 (with-test (:name
:vector-length-fill-pointer-type-derivation
)
1709 (checked-compile-and-assert
1712 (= (length (the (string 1) s
)) 1))
1713 (((make-array 1 :element-type
'character
:fill-pointer
0)) nil
)))
1715 (with-test (:name
:function-designator-loop
)
1716 (checked-compile-and-assert
1719 (declare (type (or (eql #.
#'oddp
)
1720 (satisfies eval
)) p1
))
1721 (find-if-not p1 nil p3 p4
))
1722 ((#'oddp
:from-end t
) nil
)))
1724 (with-test (:name
:lvar-constants-nested-funs
)
1725 (checked-compile-and-assert
1728 (labels ((f (x &optional result
)
1731 (nreverse result
))))
1735 (with-test (:name
:nested-indirect-var-fp-coalescence
)
1736 (checked-compile-and-assert
1748 (declare (notinline m
))
1751 (declare (notinline m
))
1754 (() (values 65 48))))
1756 (with-test (:name
:non-returning-functions-conflict
)
1757 (checked-compile-and-assert
1759 `(lambda (x) (map nil
#'error x
))
1762 (with-test (:name
:array-typep-other-pointer-widetag
)
1763 (checked-compile-and-assert
1766 (typep x
'(and base-string
(not simple-array
))))
1768 (((make-array 10 :element-type
'base-char
:adjustable t
)) t
)))
1770 (with-test (:name
:constraint-after-checkgen
)
1772 (checked-compile-and-assert
1774 `(lambda (p1 p2 p3 p4
)
1775 (declare (type (satisfies eval
) p2
)
1776 (type (member :from-end
2) p3
))
1778 (the (member ,v
3) p2
)
1779 (the (member 1 :from-end
) p3
) nil
1781 ((20 v
:from-end
#'/=) 1))))
1783 (with-test (:name
:cast-multiple-uses-no-dest
)
1784 (checked-compile-and-assert
1785 (:allow-style-warnings t
)
1792 (checked-compile-and-assert
1793 (:allow-style-warnings t
)
1795 (declare (optimize (debug 1)))
1798 (if (> (the integer a
) 0) 10 20))
1804 (with-test (:name
:maybe-delete-exit-after-let-conversion
)
1805 (checked-compile-and-assert
1814 (labels ((f (&optional
(a m
))
1822 (checked-compile-and-assert
1826 (flet ((f (a b
&optional c
)
1829 (() (values 1 2 0))))
1831 (with-test (:name
:make-array-hairy-cons
)
1832 (checked-compile-and-assert
1835 (make-array 4 :element-type type
:initial-element
0))
1836 (('(or (cons (satisfies eval
)) atom
)) #(0 0 0 0) :test
#'equalp
)))
1838 (with-test (:name
:substitute-single-use-lvar-exit-cleanups
)
1839 (checked-compile-and-assert
1843 (let ((b (1+ (funcall z
))))
1844 (catch 'c
(return b
)))))
1845 (((constantly 33)) 34)))
1847 (with-test (:name
:substitute-single-use-lvar-unknown-exits
)
1848 (checked-compile-and-assert
1852 (let ((x (evenp (funcall f
)))
1854 (return (catch 'c
(block nil
11))))))
1855 (declare (ignore y
))
1857 (((constantly 33)) 11)))
1859 (with-test (:name
:substitute-single-use-lvar-unknown-exits
.2)
1860 (checked-compile-and-assert
1866 (let ((x (the real b
)))
1868 (declare (dynamic-extent *))
1870 (if t
(return 34))))
1875 (with-test (:name
:substitute-single-use-lvar-unknown-exits
.3)
1876 (checked-compile-and-assert
1882 (declare (dynamic-extent *))
1886 (declare (dynamic-extent *))
1893 (with-test (:name
:substitute-single-use-lvar-unknown-exits
.4)
1894 (checked-compile-and-assert
1901 (declare (dynamic-extent *))
1906 (return (eval a
)))))
1910 (with-test (:name
:substitute-single-use-lvar-unknown-exits
.5)
1911 (checked-compile-and-assert
1916 (return (catch 'c
(block b b
)))))
1925 (let ((x o
)) x
)))))))
1928 (with-test (:name
:substitute-single-use-lvar-unknown-exits
.6)
1929 (checked-compile-and-assert
1934 (let ((lv3 (random 10))
1939 (let ((x (list '*)))
1940 (declare (dynamic-extent x
))
1941 (return-from b
(eval x
))))))))))
1944 (with-test (:name
:lambda-let-inline
)
1945 (let ((fun (checked-compile
1947 (let ((x (lambda () 1)))
1949 (assert (null (ctu:find-anonymous-callees fun
)))
1950 (assert (= (funcall fun
) 1))))
1952 (with-test (:name
:external-cast-deletion
)
1953 (checked-compile-and-assert
1956 (declare (notinline elt logior
))
1959 (the integer
(elt '(10 20) a
))
1960 (let ((v1 (loop repeat
3 count t
)))
1961 (declare (dynamic-extent v1
))
1966 (with-test (:name
:fixnump-instance-ref-immediately-used
)
1967 (checked-compile-and-assert
1973 (let ((y (let ((s (cons a b
)))
1974 (declare (dynamic-extent s
))
1978 (declare (dynamic-extent s
))
1985 (with-test (:name
:fixnump-instance-ref-immediately-used
.2)
1986 (checked-compile-and-assert
1989 (let* ((l (cons a b
))
1992 (typep cdr
'fixnum
)))
1995 (with-test (:name
:round-numeric-bound
)
1996 (checked-compile-and-assert
1999 (declare (type (integer -
1111868182375 1874303539234) a
))
2000 (- (rem (funcall f
) (max 23 (* 45092832376540563 a -
4469591966)))
2002 ((1874303539234 2 (constantly 123)) 7)))
2004 (with-test (:name
:ir2-optimize-jumps-to-nowhere
)
2005 (checked-compile-and-assert
2008 (declare (type fixnum a
))
2010 (block a
(shiftf a
1))
2014 (with-test (:name
:double-float-bits-stub
)
2015 (checked-compile-and-assert
2018 (float-sign 5.0d0
(the double-float x
)))
2021 (with-test (:name
:typep-word
)
2022 (checked-compile-and-assert
2025 (typep x
'sb-vm
:word
))
2027 (((1- (expt 2 sb-vm
:n-word-bits
))) t
)
2028 (((expt 2 sb-vm
:n-word-bits
)) nil
)
2032 (((1- most-negative-fixnum
)) nil
)))
2034 (with-test (:name
:fixnum-mod-p-word-descriptor
)
2035 (checked-compile-and-assert
2038 (declare (type sb-vm
:signed-word a
))
2039 (typep a
'(integer 0 ,(1- most-positive-fixnum
))))
2040 (((1- most-positive-fixnum
)) t
)
2043 ((most-positive-fixnum) nil
)
2044 (((1+ most-positive-fixnum
)) nil
)
2045 ((most-negative-fixnum) nil
)
2046 (((1+ most-negative-fixnum
)) nil
)
2047 (((1- (expt 2 (1- sb-vm
:n-word-bits
)))) nil
)
2050 (with-test (:name
:check-bound-zero-safety-notes
)
2051 (checked-compile-and-assert
2053 :optimize
'(:speed
3 :safety
0))
2055 (declare (fixnum x y z
)
2056 ((simple-array t
(*)) a
)
2057 (optimize (speed 3) (safety 0)))
2058 (aref a
(+ x
(- y z
))))
2059 ((#(1 2 3) 1 0 0) 2)))
2061 (with-test (:name
:convert-mv-bind-to-let-multiple-uses
)
2062 (checked-compile-and-assert
2067 (multiple-value-bind (x y
) (if f
2072 ((nil) (values 2 2))))
2074 (with-test (:name
:substitute-single-use-lvar-multiple-uses
)
2075 (checked-compile-and-assert
2087 (with-test (:name
:tn-ref-type-multiple-moves
)
2088 (checked-compile-and-assert
2091 (declare (type (integer 546181490258163 937632934000433) c
))
2093 (multiple-value-bind (v9 v6
)
2095 (values 0 10983313414045189807)
2097 (declare (ignore v9
))
2101 ((0 571816791704489) 10983313414045189807)))
2103 (with-test (:name
:substitute-single-use-lvar-cast-chains
)
2104 (checked-compile-and-assert
2109 ;; delays type derivation of FUN as FIXNUM until constraint propagation
2110 ;; making sure SUBSTITUTE-SINGLE-USE-LVAR runs first.
2111 (if (typep m
'fixnum
)
2114 (declare (inline fun
))
2119 (the fixnum
(the integer a
))
2120 (the fixnum
(the integer b
)))))
2125 (with-test (:name
:m-v-bind-multi-use-unused-values
.1)
2126 (multiple-value-bind (calls f
)
2127 (ctu:ir1-named-calls
2129 (multiple-value-bind (a b
)
2132 (values (sxhash m
) m
))
2133 (declare (ignore a
))
2135 (assert (eql (funcall f t
33) nil
))
2136 (assert (eql (funcall f nil
33) 33))
2137 (assert (not calls
))))
2139 (with-test (:name
:m-v-bind-multi-use-unused-values
.2)
2140 (multiple-value-bind (calls f
)
2141 (ctu:ir1-named-calls
2143 (multiple-value-bind (a b c
)
2146 (values (sxhash m
) m
))
2147 (declare (ignore a
))
2149 (assert (equal (funcall f t
33) '(nil nil
)))
2150 (assert (equal (funcall f nil
33) '(33 nil
)))
2151 (assert (not calls
))))
2153 (with-test (:name
:m-v-bind-multi-use-unused-values
.3)
2154 (multiple-value-bind (calls f
)
2155 (ctu:ir1-named-calls
2157 (multiple-value-bind (a b
)
2160 (values m
(sxhash m
)))
2161 (declare (ignore b
))
2163 (assert (eql (funcall f t
33) 10))
2164 (assert (eql (funcall f nil
33) 33))
2165 (assert (not calls
))))
2167 (with-test (:name
:m-v-bind-multi-use-unused-values
.4
2169 (multiple-value-bind (calls f
)
2170 (ctu:ir1-named-calls
2174 (funcall (the function z
))
2175 (values (sxhash m
) m
)))))
2176 (assert (eql (funcall f
(lambda () (values 1 22)) 33) 22))
2177 (assert (eql (funcall f nil
34) 34))
2178 (assert (not calls
))))
2180 (with-test (:name
:m-v-bind-multi-use-unused-values
.5
2182 (multiple-value-bind (calls f
)
2183 (ctu:ir1-named-calls
2187 (funcall (the function z
))
2189 (assert (eql (funcall f
(lambda () (values 1 22)) 33) 22))
2190 (assert (eql (funcall f nil
34) nil
))
2191 (assert (not calls
))))
2193 (with-test (:name
:m-v-bind-multi-use-variable-type-change
)
2194 (checked-compile-and-assert
2197 (when (position #\a (the (or (simple-string 1) (simple-string 2)) p
))
2202 (with-test (:name
:array-element-type-cons
.1)
2203 (checked-compile-and-assert
2206 (declare ((or (simple-array (unsigned-byte 32) (2))
2207 (simple-array (unsigned-byte 32) (4))) vector
))
2208 (make-array 10 :element-type
(array-element-type vector
)))
2209 (((make-array 2 :element-type
'(unsigned-byte 32)))
2210 '(unsigned-byte 32) :test
(lambda (x y
)
2211 (equal (array-element-type (car x
)) (car y
))))))
2213 (with-test (:name
:array-element-type-cons
.2)
2214 (checked-compile-and-assert
2217 (declare ((and (simple-array (unsigned-byte 32) (2))
2218 (satisfies eval
)) vector
))
2219 (make-array 10 :element-type
(array-element-type vector
)))
2220 (((make-array 2 :element-type
'(unsigned-byte 32)))
2221 '(unsigned-byte 32) :test
(lambda (x y
)
2222 (equal (array-element-type (car x
)) (car y
))))))
2224 (with-test (:name
:about-to-modify-symbol-value-relax-fun-type
)
2225 (let* ((compiled-lambda (compile nil
'(lambda (&rest x
) x
'hi
)))
2226 (sb-c::*compiler-error-bailout
*
2227 (lambda (&optional c
) (error c
))))
2228 (declare (notinline set
))
2229 (set 'sb-c
::*compiler-error-bailout
* compiled-lambda
)))
2231 (with-test (:name
:self-evaluating-p-not
)
2236 (assert (not (sb-int:self-evaluating-p s
)))))
2238 (with-test (:name
:lea-modfx-constant-folding
)
2239 (checked-compile-and-assert
2253 (ash most-positive-fixnum -
2)))
2258 (with-test (:name
:setup-environment-tn-conflicts
)
2259 (checked-compile-and-assert
2264 (let ((m (eval :bad
)))
2267 (declare (notinline bar
))
2275 (with-test (:name
:setup-environment-tn-conflicts
.2)
2276 (checked-compile-and-assert
2284 (let ((m (eval :bad
)))
2289 (multiple-value-list (bar))))
2290 (declare (notinline bar
2299 ((t) '(10 10 10 10) :test
#'equal
)
2302 (with-test (:name
:setup-environment-tn-conflicts
.3)
2303 (checked-compile-and-assert
2309 (declare (dynamic-extent #'%f10
))
2310 (funcall (eval #'%f10
)))))
2311 (declare (notinline %f7
))
2315 (with-test (:name
:dead-sets
)
2316 (checked-compile-and-assert
2320 ((lambda (v &rest args
)
2321 (declare (ignore args
))
2323 ((lambda (&rest args
) (declare (ignore args
)) (error "")) v
)))
2326 (() (condition 'simple-error
))))
2328 (with-test (:name
:inlining-multiple-refs
)
2331 (labels ((%s
(y &rest r
)
2333 (lambda (r) (apply #'%s
(1+ y
) r
))
2334 (apply #'eql x r
))))
2337 (with-test (:name
:update-lvar-dependencies-delete-lvar
)
2338 (checked-compile-and-assert
2343 (flet ((proc (thing)
2345 (return (eval thing
)))))
2346 (declare (inline proc
))
2353 (with-test (:name
:car-type-on-or-null
)
2355 (equal (sb-kernel:%simple-fun-type
2358 (declare (type (or null
(cons fixnum
)) x
))
2362 '(function ((or null
(cons fixnum t
))) (values fixnum
&optional
)))))
2364 (with-test (:name
:nlx-entry-zero-values
)
2365 (checked-compile-and-assert
2368 (multiple-value-call (lambda (&optional x
) x
)
2370 (funcall (eval (lambda ()
2377 (with-test (:name
:find-test-to-eq-with-key
)
2378 (checked-compile-and-assert
2381 (position (1- (expt x
64)) '((#xFFFFFFFFFFFFFFFF
)) :key
#'car
))
2385 (with-test (:name
:maybe-infer-iteration-var-type-on-union
)
2386 (checked-compile-and-assert
2387 (:allow-notes nil
:optimize
'(:speed
3 :compilation-speed
1 :space
1))
2389 (loop repeat
(if a
2 0) count
1))
2393 (with-test (:name
:maybe-infer-iteration-var-type-on-union
.2)
2394 (checked-compile-and-assert
2397 (let ((v4 (the (or (single-float (1.0
) (3.0
)) (single-float 4.0 5.0)) a
)))
2401 (with-test (:name
:derive-array-rank-negation
)
2402 (checked-compile-and-assert
2405 (declare ((not (simple-array * (* *))) a
))
2406 (eql (array-rank a
) 2))
2407 (((make-array '(2 2) :adjustable t
)) t
))
2408 (checked-compile-and-assert
2411 (declare ((not (simple-array fixnum
(* *))) a
))
2412 (eql (array-rank a
) 2))
2413 (((make-array '(2 2))) t
))
2414 (checked-compile-and-assert
2417 (declare ((not (and (array * (* *)) (not simple-array
))) a
))
2418 (eql (array-rank a
) 2))
2419 (((make-array '(2 2))) t
)))
2421 (with-test (:name
:derive-array-rank-negation
.2)
2423 (type-specifiers-equal
2424 (sb-kernel:%simple-fun-type
2427 (declare ((and simple-array
2428 (not (simple-array * (* *))))
2430 (eql (array-rank x
) 2))))
2431 '(function ((and simple-array
(not (simple-array * (* *)))))
2432 (values null
&optional
)))))
2434 (with-test (:name
:known-fun-no-fdefn
)
2435 (assert (equal (ctu:find-code-constants
(checked-compile '(lambda () #'+))
2439 (with-test (:name
:double-float-p-weakening
)
2440 (checked-compile-and-assert
2441 (:optimize
'(:speed
3 :safety
1))
2443 (declare (double-float x
))
2445 ((0.0
) (condition 'type-error
))
2448 (declaim (inline inline-fun-arg-mismatch
))
2449 (defun inline-fun-arg-mismatch (x)
2450 (declare (optimize (debug 0)))
2453 (with-test (:name
:inline-fun-arg-mismatch
)
2454 (checked-compile-and-assert
2455 (:allow-warnings
'(or sb-int
:local-argument-mismatch
2456 #+interpreter simple-warning
)) ;; why?
2458 (multiple-value-call #'inline-fun-arg-mismatch
1 2))
2459 (() (condition 'program-error
))))
2461 (with-test (:name
:principal-lvar-ref-use-loop
)
2462 (checked-compile-and-assert ()
2465 (when (< (aref vector
0) count
)
2469 (with-test (:name
(:mv-call
:more-arg
))
2470 (checked-compile-and-assert
2472 '(lambda (&rest rest
)
2473 (multiple-value-bind (a b c
) (values-list rest
)
2474 (declare (ignore c
))
2476 ((1 3) '(1 3) :test
#'equal
)))
2478 (with-test (:name
(:mv-call
:more-arg-unused
))
2479 (checked-compile-and-assert
2481 '(lambda (&rest rest
)
2482 (multiple-value-bind (a b
) (values-list rest
)
2484 (() '(nil nil
) :test
#'equal
)
2485 ((1) '(1 nil
) :test
#'equal
)
2486 ((1 3) '(1 3) :test
#'equal
)))
2488 (with-test (:name
:truncate-deriver-on-number-type
)
2489 (checked-compile-and-assert
2493 (labels ((f (&optional
(o i
))
2494 (declare (ignore o
))
2496 (declare (dynamic-extent (function f
)))
2498 (multiple-value-call #'f
(values))))
2500 ((0) (values 0 0))))
2502 (with-test (:name
:signum-type-deriver
)
2503 (checked-compile-and-assert
2506 (typep (signum n
) 'complex
))
2511 (with-test (:name
:array-header-p-derivation
)
2512 (checked-compile-and-assert
2515 (and (typep q
'(not simple-array
))
2516 (sb-kernel:array-header-p q
)))
2518 (((make-array 10 :adjustable t
)) t
)))
2520 (with-test (:name
:phase-type-derivation
)
2521 (checked-compile-and-assert
2524 (= (phase (the (integer -
1 0) x
))
2525 (coerce pi
'single-float
)))
2529 (with-test (:name
:maybe-negate-check-fun-type
)
2530 (checked-compile-and-assert
2533 (declare ((or (function (number)) (eql #.
#'symbolp
)) m
))
2534 (the (member 3/4 4/5 1/2 #.
#'symbolp
) m
))
2535 ((#'symbolp
) #'symbolp
)))
2537 (with-test (:name
:equal-to-eql
)
2538 (let ((f (checked-compile
2540 (equal (the hash-table x
) y
)))))
2541 (assert (not (ctu:find-code-constants f
:type
'sb-kernel
:fdefn
))))
2542 (let ((f (checked-compile
2544 (equalp (the function x
) y
)))))
2545 (assert (not (ctu:find-code-constants f
:type
'sb-kernel
:fdefn
)))))
2547 (with-test (:name
:multiway-branch-duplicate-case
)
2548 (let ((f (checked-compile '(lambda (b)
2552 :allow-style-warnings t
)))
2553 (assert (eq (funcall f
2) :good
))))
2555 (with-test (:name
:modular-arith-type-derivers
2557 (let ((f (checked-compile
2559 (declare ((and fixnum
2563 (assert (not (ctu:find-code-constants f
:type
'bignum
)))))
2565 (with-test (:name
:deduplicated-fdefns
)
2566 (flet ((scan-range (c start end
)
2567 (let (dup-fdefns names
)
2568 (loop for i from start below end
2569 do
(let ((obj (sb-kernel:code-header-ref c i
)))
2570 (when (sb-kernel:fdefn-p obj
)
2571 (let ((name (sb-kernel:fdefn-name obj
)))
2572 (when (member name names
)
2573 (push obj dup-fdefns
))
2574 (push name names
)))))
2575 (assert (not dup-fdefns
)))))
2576 (dolist (c (sb-vm:list-allocated-objects
:all
:type sb-vm
:code-header-widetag
))
2577 (sb-int:binding
* (((start count
) (sb-kernel:code-header-fdefn-range c
))
2578 (end (+ start count
)))
2579 ;; Within each subset of FDEFNs there should be no duplicates
2580 ;; by name. But there could be an fdefn that is in the union of the two sets.
2581 (scan-range c start end
)
2582 (scan-range c end
(sb-kernel:code-header-words c
))))))
2584 (with-test (:name
:map-all-lvar-dests
)
2585 (checked-compile-and-assert
2587 `(lambda (&key
(pred (constantly 44)))
2588 (declare (type function pred
))
2592 (with-test (:name
(:lvar-fun-name
:constant-leaf-not-constant-lvar-p
))
2593 (assert (nth-value 1
2597 (the (function (t) t
)
2598 ,(checked-compile '(lambda ())))))
2600 :allow-style-warnings t
))))
2602 (with-test (:name
(:%logbitp
:signed-and-unsigned
))
2603 (checked-compile-and-assert
2606 (declare (type (integer ,(expt -
2 (1- sb-vm
:n-word-bits
))
2607 ,(1- (expt 2 sb-vm
:n-word-bits
))) p2
))
2612 (with-test (:name
:vop-return-constant-boxing
)
2615 (declare (optimize speed
))
2616 (setf (aref (the (simple-array double-float
(*)) x
) 0)
2621 (declare (optimize speed
))
2622 (setf (aref (the (simple-array sb-vm
:word
(*)) x
) 0)
2623 (1- (expt 2 sb-vm
:n-word-bits
))))
2627 (declare (optimize speed
))
2629 (setf (aref (the (simple-array double-float
(*)) x
) 0)
2634 (declare (optimize speed
))
2635 (funcall (the function f
)
2636 1 2 3 4 5 6 7 8 9 10
2637 (setf (aref (the (simple-array double-float
(*)) a
) 0)
2641 (with-test (:name
:make-constant-tn-force-boxed
)
2642 (checked-compile-and-assert
2645 (declare (type character c
))
2646 (list 1 1 1 1 1 1 1 1 1 1 1 (the (eql #\
() c
)))
2647 ((#\
() '(1 1 1 1 1 1 1 1 1 1 1 #\
() :test
#'equal
)))
2649 (with-test (:name
:jump-over-move-coercion
2651 :skipped-on
:interpreter
)
2652 (let ((f (checked-compile
2654 (declare ((or fixnum double-float single-float
) number
))
2655 (cond ((typep number
'double-float
)
2657 ((typep number
'single-float
)
2658 (coerce number
'double-float
))
2659 ((typep number
'fixnum
)
2660 (coerce number
'double-float
)))))))
2661 (ctu:assert-no-consing
(funcall f
1d0
)))
2662 (let ((f (checked-compile
2664 (declare ((or fixnum double-float single-float
) number
))
2666 (cond ((typep number
'double-float
)
2668 ((typep number
'single-float
)
2669 (coerce number
'double-float
))
2670 ((typep number
'fixnum
)
2671 (coerce number
'double-float
))))))))
2672 (let ((v (vector 0)))
2673 (ctu:assert-no-consing
(funcall f v
1d0
)))))
2675 (with-test (:name
:jump-over-move-coercion-match-type
)
2676 (checked-compile-and-assert
2679 (declare (type (or sb-vm
:word sb-vm
:signed-word
) a
))
2680 (declare (type (and fixnum unsigned-byte
) b
))
2681 (lognand (max 0 a
) b
))
2682 (((expt 2 (1- sb-vm
:n-word-bits
)) #xFFFFFF
) -
1)
2683 (((1- (expt 2 (1- sb-vm
:n-word-bits
))) #xFFFFFF
) -
16777216)))
2685 #+#.
(cl:if
(cl:gethash
'sb-c
:jump-table sb-c
::*backend-template-names
*)
2688 (with-test (:name
:typecase-to-case-preserves-type
)
2689 (let ((f (checked-compile
2691 ;; This illustrates another possible improvement-
2692 ;; there are not actually 6 different slot indices
2693 ;; that we might load. Some of them are the same
2695 (sb-pretty:pprint-dispatch-table
(sb-pretty::pp-dispatch-entries x
))
2696 (sb-impl::comma
(sb-impl::comma-expr x
))
2697 (sb-vm:primitive-object
(sb-vm:primitive-object-slots x
))
2698 (sb-kernel:defstruct-description
(sb-kernel::dd-name x
))
2699 (sb-kernel:lexenv
(sb-c::lexenv-vars x
))
2700 (broadcast-stream (broadcast-stream-streams x
))
2702 ;; There should be no #<layout> referenced directly from the code header
2703 ;; (which implies that no type-check occurs when accessing a structure instance).
2704 ;; There is of course a vector of layouts in there to compare against.
2705 (assert (not (ctu:find-code-constants f
:type
'sb-kernel
:layout
)))
2706 ;; The function had better work.
2707 (assert (eq (funcall f
'wat
) :none
))
2708 (assert (equal (funcall f
(make-broadcast-stream *error-output
*))
2709 (list *error-output
*)))))
2712 (with-test (:name
:=-interval-derivation-and-complex
)
2713 (checked-compile-and-assert
2716 (declare ((complex (integer -
1 -
1)) p1
))
2720 (with-test (:name
:cmov-move-hoisting
)
2721 (checked-compile-and-assert
2724 (declare ((or (eql 0.0)
2730 ((#1=(1- (expt 2 sb-vm
:n-word-bits
))) #1#))
2731 (checked-compile-and-assert
2734 (declare (type (member 4801112936349103672 -
9474680540642044437) p
))
2736 ((4801112936349103672) 4801112936349103672)
2737 ((-9474680540642044437) 0)))
2739 (with-test (:name
:logior-derive-type-widening-tail-set-types
)
2740 (checked-compile-and-assert
2744 (let ((* (lambda () x y
)))
2747 (logior (apply #'q
(list a b
))
2749 (return-from p
(q b c
))
2758 (with-test (:name
:if-eq-optimization-consistency
)
2759 (let ((sb-c::*check-consistency
* t
))
2760 (checked-compile-and-assert
2763 (eval (and (if (eval 0) (eval 0) (eval 0)) t
)))
2766 (with-test (:name
:make-array-half-finished-transform
)
2767 (checked-compile-and-assert
2770 (make-array 6 :fill-pointer
33))
2771 (() (condition '(not program-error
)))))
2773 (with-test (:name
:nested-if
+let
)
2774 (checked-compile-and-assert
2789 (with-test (:name
:let-var-immediately-used-p-deleted-lambda
)
2790 (checked-compile-and-assert
2795 (zerop (count (unwind-protect 1) '(1)))
2801 (with-test (:name
:dce-local-functions
)
2802 (checked-compile-and-assert
2806 (labels ((mmm (z vars
)
2810 (dotimes (a 1) (return-from out
10))
2811 (dotimes (b 3) (catch 'b
))))
2812 (dotimes (c 3) (catch 'c
)))))
2815 (with-test (:name
:dce-more-often
)
2816 (checked-compile-and-assert
2826 (let ((a (lambda () (go o
))))
2827 (declare (special a
)))
2833 (:return-type
(values (integer 1 1) &optional
))))
2835 (with-test (:name
:dce-more-often
.2)
2836 (checked-compile-and-assert
2839 (declare (fixnum b
))
2842 (dotimes (i 1 b
) (ignore-errors)))
2845 (:return-type
(values (integer 0 0) &optional
))))
2847 (with-test (:name
:ir1-optimize-constant-fold-before-giving-up
)
2848 (checked-compile-and-assert
2851 (+ 2 (- (let ((sum 0))
2852 (declare (type fixnum sum
))
2859 (ceiling 1 (unwind-protect 2))
2866 (with-test (:name
:position-case-otherwise
)
2867 (checked-compile-and-assert
2870 (position x
'(a otherwise b t nil
)))
2876 (with-test (:name
:unreachable-component-propagate-let-args
)
2877 (checked-compile-and-assert
2882 (flet ((g (&optional
2884 (return-from f
(+ (dotimes (i 0 0)) p
))))
2889 (with-test (:name
:dce-through-optional-dispatch
)
2890 (checked-compile-and-assert
2893 (flet ((z (&optional a
)
2894 (declare (ignore a
))
2904 (with-test (:name
:values-list
+cons
)
2906 (equal (sb-kernel:%simple-fun-type
2909 (values-list (cons 1 nil
)))))
2910 '(function () (values (integer 1 1) &optional
))))
2912 (equal (sb-kernel:%simple-fun-type
2914 `(lambda (x) (values-list (list* x
1 x nil
)))))
2915 '(function (t) (values t
(integer 1 1) t
&optional
)))))
2917 (with-test (:name
:xeps-and-inlining
)
2918 (checked-compile-and-assert
2921 (flet ((fun () args
))
2922 (declare (inline fun
))
2923 (multiple-value-call #'fun
(values-list args
))
2926 (with-test (:name
:split-let-ctran-kind
)
2927 (checked-compile-and-assert
2930 (let ((a-n (null a
))
2938 (with-test (:name
:dead-component-unused-closure
)
2939 (checked-compile-and-assert
2946 (return-from %f2
(%f1
)))))))
2950 (with-test (:name
:references-to-inline-funs-copied
)
2951 (checked-compile-and-assert
2954 (and (inline-fun-arg-mismatch t
)
2955 #'inline-fun-arg-mismatch
))
2956 (() #'inline-fun-arg-mismatch
)))
2958 (with-test (:name
:eliminate-dead-code-before-initial-dfo
)
2959 (checked-compile-and-assert
2963 (flet ((f (&key
(k1 (catch 'c
)))
2969 (with-test (:name
:%coerce-callable-to-fun-movement
)
2970 (checked-compile-and-assert
2973 (let ((x (sb-kernel:%coerce-callable-to-fun x
)))
2976 ((nil (make-symbol "UNDEF")) (condition 'undefined-function
))))
2978 (with-test (:name
:jump-table-use-labels
)
2979 (checked-compile-and-assert
2993 (with-test (:name
:dfo-deleted-lambda-home
)
2995 (nth-value 5 (checked-compile
2997 (flet ((f (&optional
(o c
))
2999 (+ (restart-bind nil
(go missing-tag
))
3000 (progv nil nil o
)))))))
3001 :allow-failure t
))))
3004 (with-test (:name
:split-let-unused-vars
)
3005 (checked-compile-and-assert
3014 (declare (ignore b
))
3021 (with-test (:name
:sequence-lvar-dimensions-on-arrays
)
3022 (checked-compile-and-assert
3025 (count a
(make-string x
:initial-element a
)))
3028 (with-test (:name
:length-transform-on-arrays
)
3029 (checked-compile-and-assert
3031 `(lambda () (length (make-sequence '(string *) 10 :initial-element
#\a)))
3034 (with-test (:name
:constant-fold-unknown-types
)
3035 (checked-compile-and-assert
3036 (:allow-style-warnings t
)
3038 (oddp (the (or a b
) -
1)))))
3040 (with-test (:name
:dead-code-no-constant-fold-errors
)
3048 '(cons sb-ext
:code-deletion-note null
))))
3050 (with-test (:name
:unused-assignment
)
3051 (flet ((try (expr &aux
(warned 0))
3052 (handler-bind ((style-warning
3054 (if (search "assigned but never read" (princ-to-string c
))
3056 (error "That's unexpected")))))
3057 (multiple-value-bind (fun warn error
)
3058 (let ((*error-output
* (make-broadcast-stream))) (compile nil expr
))
3059 (declare (ignore fun
))
3060 (assert (and warn
(not error
) (eql warned
1)))))))
3061 (try '(lambda (x) (let* ((a (+ x
5)) (b a
)) (setq b
3) (eval ''z
))))
3062 ;; Even if the initializer is necessary to call, it's still warning-worthy.
3063 (try '(lambda (x) (let* ((a (+ x
5))
3064 (b (opaque-identity a
)))
3067 (try '(lambda (x) (let* ((a (+ x
5)) (b a
))
3068 (setq b
(opaque-identity 3))
3070 ;; This one uses the value of B
3071 (checked-compile '(lambda (x) (let* ((a (+ x
5)) (b a
))
3072 (setq b
(opaque-identity 3))))))
3074 (with-test (:name
:unconvert-tail-calls-terminate-block
)
3075 (checked-compile-and-assert
3090 ((t t
) (condition 'error
))))
3092 (with-test (:name
:unconvert-tail-calls-terminate-block
.2)
3093 (checked-compile-and-assert
3111 ((t t
) (condition 'error
))))
3113 (with-test (:name
:fixnum-checking-boxing
3114 :skipped-on
(not :x86-64
))
3117 (declare (optimize speed
)
3119 (the fixnum
(+ x y
)))
3122 (with-test (:name
:ltn-analyze-mv-bind
)
3123 (checked-compile-and-assert
3126 (multiple-value-call #'list
3127 10 (apply #'values
'(44 33d0
))))
3128 (() '(10 44 33d0
) :test
#'equal
)))
3131 (with-test (:name
:lp719585
)
3132 ;; Iteration variables are always "used"
3133 (checked-compile '(lambda () (do (var) (t))))
3134 (checked-compile '(lambda () (do* (var) (t))))
3135 (checked-compile '(lambda () (do-all-symbols (var))))
3136 (checked-compile '(lambda () (do-external-symbols (var))))
3137 (checked-compile '(lambda () (do-symbols (var))))
3138 (checked-compile '(lambda () (dolist (var '(1 2 3))))))
3140 (with-test (:name
:key-default-type
)
3141 (let ((name (gensym)))
3142 (proclaim `(ftype (function (double-float &key
(:y double-float
))) ,name
))
3143 (checked-compile-and-assert
3144 (:optimize
:default
)
3145 `(sb-int:named-lambda
,name
(x &key
(y x
))
3147 ((1d0 :y nil
) (condition 'error
)))))
3149 (with-test (:name
:deleting-unreachable-floats
)
3150 (let ((name (gensym)))
3151 (proclaim `(inline ,name
))
3152 (eval `(defun ,name
(&key
(k (eval 0f0
)))
3154 (checked-compile-and-assert
3160 (with-test (:name
:no-
*-as-type
)
3161 (multiple-value-bind (fun errorp warnings
)
3162 (checked-compile '(lambda (x) (the * x
))
3163 :allow-failure t
:allow-warnings t
)
3164 (declare (ignore fun
))
3166 (assert (= (length warnings
) 1)))
3167 ;; (values t) parses into *wild-type* and has to be allowed
3168 ;; even though * which parses into *wild-type* isn't.
3169 (checked-compile '(lambda () (the (values t
) t
))))
3171 (with-test (:name
:hairy-data-vector-set-t-upgrade
)
3173 '(lambda (x) (sb-kernel:hairy-data-vector-set
3174 (the (simple-array symbol
) x
) 1 'hey
))))
3176 (with-test (:name
:ir2-convert-reffer-no-lvar
)
3177 (checked-compile-and-assert
3178 (:allow-style-warnings t
)
3180 (/ (unwind-protect (if a
3181 (values nil
(cdr a
))
3187 (with-test (:name
:%eql-integer-fold
)
3188 (checked-compile-and-assert
3191 (declare (type fixnum d
))
3192 (or (find d
'(-98 27749116333474161060))
3197 (with-test (:name
:svref-with-addend
+if-eq-immediate
)
3198 (checked-compile-and-assert
3201 (eql (svref a d
) -
276932090860495638))
3203 ((#(-276932090860495638) 0) t
)))
3205 (with-test (:name
:zeroize-stack-tns
)
3206 (checked-compile-and-assert
3209 (declare (type fixnum a
))
3212 (truncate 562949953421316 (max 97 d
))
3213 (min 81 (expt (boole boole-and e b
) 2)))
3216 (count i
#(61) :test
'>=))))
3219 (with-test (:name
:logtest-derive-type-nil
)
3220 (checked-compile-and-assert
3224 (evenp (the integer
(ignore-errors (return c
))))))
3227 (with-test (:name
:cast-filter-lvar
)
3228 (checked-compile-and-assert
3233 (the integer
(tagbody
3234 (let ((* (lambda () (go tag
))))
3237 (the integer
(block nil
3241 ;;; EXPLICIT-CHECK + ETYPECASE should not produce a error message
3242 ;;; which reveals whether type-checking on entry to a standard function
3243 ;;; was performed this way or that way.
3244 (with-test (:name
:etypecase-error-simplify
)
3245 (let ((x (nth-value 1 (ignore-errors (logcount (opaque-identity #\a)))))
3246 (y (nth-value 1 (ignore-errors (oddp (opaque-identity #\a))))))
3247 (assert (string= (princ-to-string x
) (princ-to-string y
)))))
3249 (with-test (:name
:set-exclusive-or-inlined
)
3250 (checked-compile-and-assert
3252 `(lambda (set1 set2
)
3253 (declare (inline set-exclusive-or
))
3254 (set-exclusive-or set1 set2
))))
3256 (declaim (inline inline-deletion-note
))
3257 (defun inline-deletion-note (x y
)
3262 (with-test (:name
:inline-deletion-note
)
3263 (checked-compile-and-assert
3266 (inline-deletion-note x t
))
3269 (with-test (:name
:inline-type-mismatch
)
3270 (checked-compile-and-assert
3273 (car (inline-deletion-note x y
)))
3275 (checked-compile-and-assert
3278 (1+ (position x
(the list y
))))
3281 (with-test (:name
:lvar-annotation-inline-type-mismatch
)
3282 (checked-compile-and-assert
3285 (sb-kernel:the
* (float :use-annotations t
) (inline-deletion-note x y
)))
3288 (with-test (:name
:cast-type-preservation
)
3291 (sb-kernel:%simple-fun-type
3294 (declare ((integer 1 1000) b
))
3295 (declare (optimize (space 0)))
3297 '(values (integer 1 2) &optional
))))
3299 (with-test (:name
:lvar-substituting-non-deletable-casts
)
3300 (checked-compile-and-assert
3308 (truncate (the (integer -
10 0) b
) -
4)))
3316 (with-test (:name
:convert-mv-bind-to-let-no-casts
)
3317 (checked-compile-and-assert
3320 (declare (type (integer 7693489 168349189459797431) a
))
3324 (loop for lv3 below
3
3325 sum
(mod 77196223293181
3326 (max 75 (mod a
(min -
57 lv3
)))))))))
3327 ((8000000) -
571429)))
3329 (with-test (:name
:values-length-mismatch
)
3330 (checked-compile-and-assert
3331 (:allow-style-warnings t
:optimize
:default
)
3333 (declare (values t
&optional
))
3337 ((t) (condition 'type-error
))))
3339 (with-test (:name
:substitute-single-use-lvar-type-cast-movement
)
3340 (checked-compile-and-assert
3344 (let ((x (multiple-value-prog1 a
)))
3353 (with-test (:name
:fold-ash-mod-0
)
3354 (checked-compile-and-assert
3357 (loop for i below
3 sum
3359 (ash i
(mask-field (byte 5 8) i
)))))
3362 (with-test (:name
:substitute-single-use-lvar-type-multiple-uses
)
3363 (checked-compile-and-assert
3378 (with-test (:name
:division-by-multiplication-type-derivation
)
3380 (type-specifiers-equal
3382 (sb-kernel:%simple-fun-type
3385 (declare (optimize speed
))
3393 '(values (or (integer -
21 -
21) (integer 0 0)) (integer #+(or arm64 x86-64
) -
21
3394 #-
(or arm64 x86-64
) -
38 0)
3397 (type-specifiers-equal
3399 (sb-kernel:%simple-fun-type
3402 (declare (optimize speed
))
3410 '(values (or (integer 22 22) (integer 337 337)) (integer -
38 -
1) &optional
))))
3412 (with-test (:name
:boundp-ir2-optimizer
)
3413 (checked-compile-and-assert
3424 (with-test (:name
:nfp-in-unwinding
)
3426 (checked-compile-and-assert
3429 (declare (double-float x y
))
3432 (unwind-protect (funcall f
)
3433 (return (+ z
1d0
))))))
3434 ((4d0 1d0
(lambda () (throw 'z
1))) 6d0
))))
3436 (with-test (:name
:ir1-optimize-if-same-target-type-derivation
)
3437 (checked-compile-and-assert
3440 (declare (notinline equal
))
3441 (multiple-value-bind (v7 v2
)
3445 (declare (ignore v2
))
3446 (tagbody (progn v7
))
3450 (with-test (:name
:delete-let-source-paths
)
3451 (checked-compile-and-assert
3454 (declare (type (member -
3 -
54972 3) a
))
3455 (values (floor -
98740440 a
)))
3460 (with-test (:name
:unused-debug-tns
)
3461 (checked-compile-and-assert
3468 (f (1+ most-positive-fixnum
)))))
3471 (with-test (:name
:exit-becomes-single-value
)
3472 (checked-compile-and-assert
3477 (flet ((x () (return (floor 1020 z
))))
3481 (((lambda (x) (funcall x
)) 4) 255)))
3483 (with-test (:name
:principal-lvar-single-valuify-exit
)
3484 (checked-compile-and-assert
3490 (block nil
(truncate (flet ((b ()
3491 (return (block b3
(values 1 v3
)))))
3492 (declare (inline b
))
3494 (declare (inline a
))
3499 (with-test (:name
:%coerce-callable-for-call-with-casts
3500 :skipped-on
(not :call-symbol
))
3501 (multiple-value-bind (calls f
)
3502 (ctu:ir1-named-calls
3505 (assert (equal (funcall f
#'list
'(3)) '(1 2 3)))
3506 (assert (equal calls
'(x)))))
3508 (with-test (:name
:local-fun-type-check-eliminatetion
)
3509 (let ((fun (checked-compile '(lambda ()
3511 (declare (fixnum x
))
3513 (declare (inline f
))
3515 (the (function (&optional fixnum
)) #'f
)
3517 (assert (= (sb-kernel:code-n-entries
(sb-kernel:fun-code-header fun
))
3520 (with-test (:name
:%cleanup-point-transform
)
3521 (checked-compile-and-assert
3524 (declare ((integer -
14 49702337) a
)
3525 ((integer -
5376440588342 5921272101558) b
)
3526 ((integer 3395101368955 8345185767296289) c
))
3527 (if (and (< c b
) (> a b
))
3529 (list 288230376151711735 c
)
3530 (restart-bind nil a
))
3532 ((49702337 5921272101558 8345185767296289) 8345185767296289)))
3534 ;;; Test from git rev e47ffa8855d4139f88f5982fe4b82a05c3498ed3.
3535 ;;; I have absolutely zero understanding of what this was doing,
3536 ;;; but the are bunch of "undefined variable" warnings, so it can't
3537 ;;; go at toplevel in a .cload test.
3538 (with-test (:name
:bug-226
)
3539 (with-scratch-file (lisp "lisp")
3540 (with-open-file (f lisp
:direction
:output
)
3541 (write '(defun bug226 ()
3542 (declare (optimize (speed 0) (safety 3) (debug 3)))
3543 (flet ((safe-format (stream string
&rest r
)
3544 (unless (ignore-errors (progn
3545 (apply #'format stream string r
)
3547 (format stream
"~&foo ~S" string
))))
3549 ((eq my-result
:ERROR
)
3551 ((ignore-errors (typep condition result
))
3552 (safe-format t
"~&bar ~S" result
))
3554 (safe-format t
"~&baz ~S (~A) ~S" condition condition result
)))))))
3555 :stream f
:readably t
))
3556 (with-scratch-file (fasl "fasl")
3557 (compile-file lisp
:output-file fasl
))))
3559 ;;; I think these tests had to be present in a COMPILE-FILE (as opposed to COMPILE)
3560 ;;; to prove that the bug was fixed.
3561 ;;; Anway it's no longer going to be allowed to have deliberately bad code in '.cload'
3562 ;;; files, because any condition of type warnings or error is considered failure
3563 ;;; of the compile step.
3564 (with-test (:name
:lp-1276282
)
3565 (with-scratch-file (lisp "lisp")
3566 (with-open-file (f lisp
:direction
:output
)
3567 ;; from git rev feb31fb6cfc8f89e2d75b5f2cc2ee569ac975033
3568 (format f
"(lambda () (the string (+ 1 x)))~%")
3569 ;; from git rev fbea35e879891723259dfa55589b498228390bb9
3572 (macrolet ((x (&rest args)
3573 (declare (ignore args))
3576 (declare (type vector a))
3577 (x #.#'list))))~%"))
3578 (with-scratch-file (fasl "fasl")
3579 (compile-file lisp
:output-file fasl
))))
3581 (with-test (:name
:substitute-single-use-lvar-mv-cast
)
3582 (checked-compile-and-assert
3585 (let ((r (random 10))
3587 (declare (special x
)
3589 (throw 'c
(the (integer 0 10) r
))))))
3591 (with-test (:name
:list-ir2-convert
)
3592 (checked-compile '(lambda ()
3593 (declare (notinline list
+))
3594 (list (loop for i below
2 count t
)))))
3596 (with-test (:name
:bignump-integer-
<)
3597 (checked-compile-and-assert
3600 (declare (type integer a
))
3601 (if (and (typep a
'bignum
) (< a
0))
3605 (((- (expt 2 300))) t
)))
3607 (with-test (:name
:cmov-branch
)
3608 (checked-compile-and-assert
3613 (when x
(setf res
(not res
)))
3614 (when y
(setf res
(not res
)))
3619 (with-test (:name
:constant-type-proclamation
)
3621 `((defconstant +foo
+ 4)
3623 (defun bar () +foo
+)
3625 (declaim (type integer
+foo
+)))
3627 (assert (eq (funcall 'bar
) 4)))
3629 (with-test (:name
:if-split-let-blocks
)
3630 (checked-compile-and-assert
3649 (with-test (:name
:duplicate-more-local-tn-overflow
)
3650 (let ((vars (loop repeat
200 collect
(gensym)))
3651 (args (loop repeat
201 for i from
(random 30000)
3661 (cons (car args
) args
)))))
3663 (with-test (:name
:aref-single-value-type
)
3664 (checked-compile-and-assert
3667 (aref (the (values (and (not simple-array
) vector
)) x
) 0))
3668 (((make-array 10 :adjustable t
:initial-element
3)) 3)))
3670 (with-test (:name
:restoring-tns-after-cleanups
)
3671 (checked-compile-and-assert
3674 (declare (notinline values
))
3676 (let ((a (list 'list
)))
3677 (declare (dynamic-extent a
))
3678 (unwind-protect 1 (eval a
)))
3683 (defun noflush-symbol-function ()
3684 (declare (optimize safety
))
3685 (if (functionp (symbol-function '#:notathing
)) 1))
3686 (defun flush-symbol-function ()
3687 (if (functionp (symbol-function '#:notathing
)) 1))
3688 (with-test (:name
:flush-symbol-function
:skipped-on
:interpreter
)
3689 (assert (ctu:find-code-constants
#'noflush-symbol-function
))
3690 (assert (not (ctu:find-code-constants
#'flush-symbol-function
))))
3692 (with-test (:name
:symbolp-other-pointer
)
3693 (checked-compile-and-assert
3696 (declare ((or symbol bit-vector
) x
))
3700 (with-test (:name
:non-nil-symbolp-other-pointer
)
3701 (checked-compile-and-assert
3704 (declare ((or bignum symbol
) x
))
3705 (sb-kernel:non-null-symbol-p x
))
3707 (((1+ most-positive-fixnum
)) nil
)
3710 (with-test (:name
:list-constant-coalesce
)
3711 (checked-compile-and-assert
3714 (list -
13303942049971317088
3716 -
13303942049971317088))
3717 (() '(-13303942049971317088 -
6714119381493 -
13303942049971317088) :test
#'equal
)))
3719 (with-test (:name
:list-constant-coalesce
.2)
3720 (checked-compile-and-assert
3723 (list -
3819610816126750017 -
7639221632253500034))
3724 (() '(-3819610816126750017 -
7639221632253500034) :test
#'equal
))
3725 (checked-compile-and-assert
3728 (list -
7639221632253500034 -
3819610816126750017))
3729 (() '(-7639221632253500034 -
3819610816126750017) :test
#'equal
)))
3731 (with-test (:name
:constraint-loop
)
3732 (checked-compile-and-assert
3735 (let ((v (elt '(2444 2740 3237 8155 3296 7304 7612 2949) b
)))
3736 (progv '(*) (list (ceiling v
40))
3740 (with-test (:name
:unused-local-fun-results
)
3741 (let ((f `(lambda (x)
3747 (assert (not (ctu:ir1-named-calls f
)))))
3749 (with-test (:name
:ir2opt-tns-without-sc
)
3750 (checked-compile-and-assert
3753 (boole boole-set
(the rational a
) a
))
3756 (with-test (:name set-slot-old-p-optionals
)
3757 (checked-compile-and-assert
3760 (let ((list (list 1)))
3763 ((2) '(2) :test
#'equal
)))
3765 (with-test (:name
:tn-ref-type-ir2opt
)
3766 (checked-compile-and-assert
3770 (the (or (array * (1)) real
) p
)))
3773 (with-test (:name
:qword-to-dword-cut
)
3774 (checked-compile-and-assert
3777 (declare (fixnum b
))
3779 (lognor (setq a -
336272099380508247)
3780 (shiftf b
(logorc1 1073741832 a
)))
3781 (the (integer -
504635362412860905 -
99686857090873309) (lognand b
11))))))
3783 (with-test (:name
:not-folded-vops
)
3785 (type-specifiers-equal
3787 (sb-kernel:%simple-fun-type
3794 (loop for lv below
1 count
3797 (- (floor f1 f1
) (return-from b -
9))))
3798 (multiple-value-call #'%f
(values (block b3 lv
))))
3801 '(values (integer -
99734 -
99734) (integer 19 19) &optional
))))
3803 (with-test (:name
:bit-ir2opt
)
3804 (checked-compile-and-assert
3807 (declare (fixnum c
))
3810 (shiftf a
(bit #*01 (max 0 c
)))
3814 (with-test (:name
:find-initial-dfo-ignore-let-converted-funs
)
3815 (checked-compile-and-assert
3820 &optional
(f7-4 (go tag5
))
3821 (f7-5 ((lambda (&rest args
) (go tag5
))))
3824 ((lambda (v10) (%f7
(go tag5
) -
63522127 v10
)) c
))
3828 (with-test (:name
:find-initial-dfo-ignore-assignment-converted-funs
)
3829 (checked-compile-and-assert
3834 (labels ((%f
(&optional
(x 0) (y 0)) y
))
3838 (() (values 0 nil
))))
3840 (with-test (:name
:find-initial-dfo-ignore-assignment-converted-funs
.2)
3841 (checked-compile-and-assert
3842 (:allow-style-warnings t
)
3844 (let ((v (make-array 1 :initial-element
(catch 'ct
42))))
3845 (labels ((f (&optional
(x 4) &key
(k a
)) x
))
3846 (if nil
(f) (f a
)))))
3849 (with-test (:name
:if-eq-optimizer-nil
)
3850 (checked-compile-and-assert
3859 (with-test (:name
:assignment-convert-check-same-lvar
)
3860 (checked-compile-and-assert
3861 (:allow-style-warnings t
)
3863 (flet ((%f9
(f9-1 f9-2
&optional
(key1 0))
3865 (multiple-value-prog1 (%f9
701021570480035 c
)
3869 (%f9
1048572 2385880201)
3871 (%f9
777238289903386671 -
15131644893)
3875 (with-test (:name
:range
<)
3876 (checked-compile-and-assert
3879 (declare (fixnum l h
))
3887 (with-test (:name
:range
<.2)
3888 (checked-compile-and-assert
3891 (declare (fixnum h
))
3897 (with-test (:name
:range
<.3)
3898 (checked-compile-and-assert
3901 (and (or (not b
) (< 0 c
)) (<= c
0)))
3906 (with-test (:name
:range
<.4)
3907 (checked-compile-and-assert
3910 (declare (fixnum f
))
3911 (<= (truncate 10 f
) m
0))
3916 (with-test (:name
:range
<-equal-bounds
)
3917 (checked-compile-and-assert
3920 (sb-kernel:range
< l x h
))
3926 (checked-compile-and-assert
3929 (sb-kernel:range
<<= l x h
))
3935 (checked-compile-and-assert
3938 (sb-kernel:range
<=< l x h
))
3944 (checked-compile-and-assert
3947 (sb-kernel:range
<= l x h
))
3954 (with-test (:name
:move-from-word
/fixnum-ir2opt
)
3955 (checked-compile-and-assert
3958 (declare (type (integer -
10 10) c
))
3959 (let ((v5 (logior 2305843195621877482 c
)))
3961 (abs (shiftf v5
(+ v5
1))))))
3962 ((-10) (values -
2 2))))
3964 (with-test (:name
:values-list-type-check
3965 :skipped-on
(not (or :x86-64
:arm64
)))
3966 (assert (find-if (lambda (line)
3967 (search "BOGUS-ARG-TO-VALUES-LIST-ERROR" line
:test
#'equal
))
3968 (ctu:disassembly-lines
3972 (values-list l
)))))))
3973 (assert (not (find-if (lambda (line)
3974 (search "BOGUS-ARG-TO-VALUES-LIST-ERROR" line
:test
#'equal
))
3975 (ctu:disassembly-lines
3978 (declare (optimize (safety 0)))
3980 (values-list l
)))))))))
3982 (with-test (:name
:explicit-value-cell-top-level
)
3988 (setf *x
* (lambda () (incf v
)))))
3989 (assert (eql (funcall *x
*) 1))
3990 (assert (eql (funcall *x
*) 2)))
3993 (with-test (:name
:load-store-two-words-reused-load-tn
)
3994 (checked-compile-and-assert
3997 (funcall x
1 2 3 4 'a t t
))
3998 (('list
) '(1 2 3 4 a t t
) :test
#'equal
)))
4000 (with-test (:name
:closures-unreachable-components
)
4001 (checked-compile-and-assert
4010 (return #'f11
)))))))))
4012 (with-test (:name
:flushable-nil-funs
)
4013 (checked-compile-and-assert
4016 (eq (the (or) (car a
))
4017 (the (or) (car b
))))))
4019 (with-test (:name
:cmov-modifying-input
)
4020 (checked-compile-and-assert
4023 (declare (double-float d
))
4024 (values (if (not (> d
10d0
))
4028 ((1 2 1d0
) (values 2 1))))
4030 (with-test (:name
:ir1-optimize-return-type-widening
)
4031 (checked-compile-and-assert
4036 (values (the integer
(f)))))
4039 (with-test (:name
:reuse-coercion
)
4040 (multiple-value-bind (fun fail warn style notes
)
4041 (checked-compile `(lambda (x d
)
4042 (declare (double-float d
)
4051 (declare (ignore fail warn style
))
4052 (assert (= (length notes
) 1))
4053 (assert (= (funcall fun
1 0d0
) 1d0
))
4054 (assert (= (funcall fun
2 0d0
) 2d0
))
4055 (assert (= (funcall fun
3 0d0
) 3d0
))
4056 (assert (null (funcall fun
4 0d0
)))))
4058 (with-test (:name
:reorder-keywordp
)
4059 (checked-compile-and-assert
4073 (with-test (:name
:reorder-same-block
)
4074 (checked-compile-and-assert
4084 (((1+ most-positive-fixnum
)) 3)
4087 (with-test (:name
:unlink-node-in-delete-block
)
4088 (checked-compile-and-assert
4093 (declare (ignore v
))
4094 ((lambda (a b
&rest c
)
4098 (case b
((-424 -
278) b
) (t 0))))
4099 ((lambda () (go 7))))
4102 (with-test (:name
:multiple-call-unboxed-calls
)
4103 (checked-compile-and-assert
4106 (declare (double-float m
))
4111 ((1d0 nil
) (values 1 0d0
))
4112 ((4d38 nil
) (values 399999999999999990995239293824136118272 0d0
)))
4113 (checked-compile-and-assert
4120 (coerce m
'double-float
))))
4122 (checked-compile-and-assert
4125 (declare (double-float m
))
4129 (scale-float m
2))))
4133 (with-test (:name
:structure-typep
*-deleted-branch
)
4134 (checked-compile-and-assert
4138 ((typep x
'random-state
)
4140 ((typep x
'hash-table
)
4143 ((*random-state
*) 1)
4144 (((make-hash-table)) 2)
4147 (with-test (:name
:deleted-call-type
)
4148 (checked-compile-and-assert
4158 (:return-type
(values (integer 1 2) &optional
))))
4160 (with-test (:name
:optional-type-propagation
)
4161 (checked-compile-and-assert
4164 (labels ((foo (&optional x
)
4168 (:return-type
(values (integer 1 2) &optional
)))
4169 (checked-compile-and-assert
4172 (labels ((foo (&key x
)
4176 (:return-type
(values (integer 1 2) &optional
))))
4178 (with-test (:name
:local-function-declaration
)
4179 (checked-compile-and-assert
4182 (declare ((function * fixnum
) n
))
4183 (typep (funcall n
) 'fixnum
))
4184 ((#'list
) (condition 'type-error
))))
4186 (declaim (inline member-type-derivation
))
4187 (defun member-type-derivation (x)
4188 (member x
'(a b c d
)))
4190 (with-test (:name
:member-type-derivation
)
4191 (checked-compile-and-assert
4194 (when (member-type-derivation n
)
4202 (with-test (:name
:equal-not-null-transform
)
4203 (checked-compile-and-assert
4206 (declare (atom x
) (list y
))
4211 (checked-compile-and-assert
4214 (declare (atom x
) (list y
))
4220 (with-test (:name
:optimize-return-deleted-lambda
)
4221 (checked-compile-and-assert
4225 (case x
(:star
(f1))))
4227 (case x
(:open
(f1))))
4230 (:backquote
(f4 d
0))
4240 (:backquote
(f4 d
0))
4244 (with-test (:name
:type-derivers-type-widening
)
4245 (checked-compile-and-assert
4250 (max (ignore-errors c
) 0)
4255 (with-test (:name
:propagate-to-refs-hairy
)
4256 (checked-compile-and-assert
4259 (declare (fixnum y
))
4260 (let ((d (max 1 (the (satisfies eval
) y
))))
4261 (the fixnum
(* d
8))))
4264 (with-test (:name
:complicated-cons-function-unions
)
4265 (checked-compile-and-assert
4268 (car (member w
'#.
(list #'< #'= #'eql
#'equalp
))))
4272 (with-test (:name
:tail-calls-terminated-blocks
)
4273 (prog* ((f (checked-compile `(lambda (f)
4274 (declare (optimize (debug 1)))
4280 (assert (funcall f
(lambda () (when (= (incf x
) 2) (return t
)))))))
4282 (with-test (:name
:the
*-exits
)
4283 (checked-compile-and-assert
4289 (hash-table-test (return)))))
4293 (with-test (:name
:inlining-deleted-go-tag
)
4294 (checked-compile-and-assert
4298 (labels ((f () (go t
)))
4299 (declare (inline f
))
4301 (multiple-value-call #'f
(values)))
4306 (with-test (:name
:inling-non-convertible-locals
)
4307 (checked-compile-and-assert
4310 (labels ((f (&key m
)
4312 (declare (inline f
))
4315 ((:m
) (values 30 :m
))
4316 ((:allow-other-keys
) (values nil
:allow-other-keys
))))
4318 (with-test (:name
:undeleted-exits
)
4319 (checked-compile-and-assert
4323 (flet ((f (a) a
(go 5)))
4324 (print (list #'f
(loop for i in
(f 1)
4329 (with-test (:name
:unused-initial-values
)
4330 (checked-compile-and-assert
4331 (:allow-notes nil
:optimize
'(:debug
2 :speed
3 :safety
1))
4333 (declare ((simple-array double-float
(*)) v
))
4334 (loop for e across v count
(> e
0)))
4335 (((make-array 9 :element-type
'double-float
:initial-element
1d0
)) 9)))
4337 (with-test (:name
:consecutive-cast
)
4338 (checked-compile-and-assert
4341 (the fixnum
(the integer
(funcall f
))))
4343 (checked-compile-and-assert
4346 (abs (catch 'c
(the (satisfies eval
) a
))))
4348 (checked-compile-and-assert
4357 (checked-compile-and-assert
4360 (the vector
(the array x
)))
4361 ((1) (condition 'type-error
)))
4362 (checked-compile-and-assert
4365 (let ((m (the array x
)))
4366 (values (the vector m
)
4368 ((1) (condition 'type-error
)))
4369 (checked-compile-and-assert
4372 (declare (type fixnum c d m
))
4373 (the (unsigned-byte 62)
4375 (let ((v (logxor c -
7322529 d
9223372036854775805)))
4377 (the unsigned-byte m
)
4378 (logior 80827861226 v
))))))
4379 ((-3462512952 -
77 0) (condition 'type-error
)))
4380 (checked-compile-and-assert
4385 (let ((j (the integer m
)))
4388 ((nil 'a
) (condition 'type-error
))
4389 ((t 1d0
) (condition 'type-error
))
4392 (checked-compile-and-assert
4395 (the (values fixnum
&optional
) (the (values integer
&rest t
) (funcall f x
))))
4396 ((#'identity
.0) (condition 'type-error
))
4398 ((#'identity
(expt 2 1000)) (condition 'type-error
))))
4400 (with-test (:name
:pop-values-unused
)
4401 (checked-compile-and-assert
4404 (declare ((function (fixnum &rest t
)) j
))