1 (with-test (:name
(compile eval the type-error
))
2 (checked-compile-and-assert (:optimize
:safe
)
4 (list (the fixnum
(the (real 0) (eval v
)))))
5 ((0.1
) (condition 'type-error
))
6 ((-1) (condition 'type-error
))))
8 (defun pick-acceptable-default (specifier)
9 (let ((parse (sb-kernel:specifier-type specifier
)))
10 ; (format t "~&testcase: ~s~%" specifier)
12 (sb-kernel:character-set-type
#\a)
13 (sb-kernel:numeric-type
14 (cond ((eq (sb-kernel:numeric-type-class parse
) 'float
)
15 (ecase (sb-kernel:numeric-type-complexp parse
)
17 (ecase (sb-kernel:numeric-type-format parse
)
21 (ecase (sb-kernel:numeric-type-format parse
)
22 (single-float #c
(101f0 -
1f0
))
23 (double-float #c
(2d0 3.5d0
))))))
27 (cond ((equal specifier
'(or (eql 1.0d0
) (eql 10.0d0
))) ; KLUDGE
29 ((equal specifier
'(member 1 2 10))
31 ((equal specifier
'(complex (member 10.0 20.0)))
36 (with-test (:name
:array-type-predicates
)
37 (dolist (et (list* '(integer -
1 200) '(integer -
256 1)
40 '(double-float 0d0
(1d0))
41 '(single-float (0s0) (1s0))
42 '(or (eql 1d0
) (eql 10d0
))
44 '(complex (member 10 20))
45 '(complex (member 10d0
20d0
))
46 '(complex (member 10s0
20s0
))
47 '(or integer double-float
)
51 #+sb-unicode
'extended-char
52 #+sb-unicode
'(eql #\cyrillic_small_letter_yu
)
53 (map 'list
'sb-vm
:saetp-specifier
54 sb-vm
:*specialized-array-element-type-properties
*)))
56 (let* ((v (make-array 3 :element-type et
57 ;; Pick an initial element because of the (ELT ,v 0)
58 :initial-element
(pick-acceptable-default et
))))
59 (checked-compile-and-assert ()
61 (list (if (typep ,v
'(simple-array ,et
(*)))
64 (if (typep (elt ,v
0) '(simple-array ,et
(*)))
67 (() '(:good
:good
)))))))
69 (with-test (:name
(compile equal equalp
:transforms
))
71 (bit-vector #*11001100)
72 (values `(nil 1 2 "test"
73 ;; Floats duplicated here to ensure we get newly created instances
74 (read-from-string "1.1") (read-from-string "1.2d0")
75 (read-from-string "1.1") (read-from-string "1.2d0")
76 1.1 1.2d0
'("foo" "bar" "test")
77 #(1 2 3 4) #*101010 (make-broadcast-stream) #p
"/tmp/file"
78 ,s
(copy-seq ,s
) ,bit-vector
(copy-seq ,bit-vector
)
79 ,(make-hash-table) #\a #\b #\A
#\C
80 ,(make-random-state) 1/2 2/3)))
82 (dolist (predicate '(equal equalp
))
83 ;; Test all permutations of different types
85 do
(loop for y in values
86 do
(checked-compile-and-assert (:optimize nil
)
88 (,predicate
(the ,(type-of x
) x
)
89 (the ,(type-of y
) y
)))
90 ((x y
) (funcall predicate x y
)))))
91 (checked-compile-and-assert ()
93 (,predicate
(the (cons (or simple-bit-vector simple-base-string
))
95 (the (cons (or (and bit-vector
(not simple-array
))
96 (simple-array character
(*))))
98 (((list (string 'list
)) (list "LIST")) t
)))))
100 (with-test (:name
(sb-c::mask-signed-field
:randomized
))
103 (let* ((ool (checked-compile '(lambda (s i
)
104 (sb-c::mask-signed-field s i
))))
105 (size (random (* sb-vm
:n-word-bits
2)))
106 (constant (checked-compile `(lambda (i)
107 (sb-c::mask-signed-field
,size i
))))
108 (arg (- (random (* most-positive-fixnum
8)) (* most-positive-fixnum
4)))
109 (declared (checked-compile `(lambda (i)
110 (declare (type (integer ,(- (abs arg
)) ,(abs arg
)) i
))
111 (sb-c::mask-signed-field
,size i
))))
112 (ool-answer (funcall ool size arg
))
113 (constant-answer (funcall constant arg
))
114 (declared-answer (funcall declared arg
)))
115 (unless (= ool-answer constant-answer declared-answer
)
116 (push (list size arg ool-answer constant-answer declared-answer
) result
))))
117 (assert (null result
))))
119 (with-test (:name
(multiple-value-call :type-checking-rest
))
120 (checked-compile-and-assert (:allow-warnings t
124 (lambda (&optional a
&rest r
)
125 (declare ((satisfies eval
) r
)
130 (('(1)) (condition 'type-error
))))
132 (with-test (:name
(multiple-value-call :type-checking-rest
.2))
133 (checked-compile-and-assert (:allow-warnings t
137 (lambda (&optional a
&rest r
)
142 (('(1 list
2)) (condition 'type-error
))
145 (with-test (:name
(multiple-value-call :type-checking-rest
:type-derivation
))
146 (checked-compile-and-assert (:allow-warnings t
150 (lambda (&optional a
&rest r
)
156 (('(1)) (condition 'type-error
))))
158 (declaim (maybe-inline inline-recursive
))
159 (defun inline-recursive (x)
160 (declare (muffle-conditions compiler-note
164 (inline-recursive (1- x
))))
165 (declaim (inline inline-recursive
))
167 (with-test (:name
:reanalyze-functionals-when-inlining
)
168 (checked-compile-and-assert
172 (inline-recursive x
))
175 (with-test (:name
:interval-div-zero
)
176 (checked-compile-and-assert (:optimize
:safe
)
178 (truncate (the (integer 0 0) x
)
179 (the (rational (1) (2)) y
)))
180 ((0 3/2) (values 0 0))))
182 (with-test (:name
:float-quotient-rounding-errors
183 :skipped-on
:x86
) ;; x87 has different precision loss
184 (checked-compile-and-assert (:optimize
:safe
)
186 (floor -
114658225103614 84619.58))
187 (() (values -
1354984705 8473228.0)))
188 (checked-compile-and-assert (:optimize
:safe
)
190 (floor -
302254842 50510.5))
191 (() (eval '(floor -
302254842 50510.5))))
192 (checked-compile-and-assert (:optimize
:safe
)
194 (ceiling 114658225103614 84619.58))
195 (() (values 1354984705 -
8473228.0)))
196 (checked-compile-and-assert (:optimize
:safe
)
198 (ceiling 285493348393 94189.93))
199 (() (values 3031039 0.0))))
201 (with-test (:name
:check-function-designator-cast-key-lambda-var
)
202 (checked-compile-and-assert
203 (:optimize
'(:speed
3 :space
0))
206 ((member ,#'car
"x" cdr
) p4
))
207 (stable-sort p1
#'<= :key p4
))
208 (((vector '(2) '(3) '(1)) #'car
) #((1) (2) (3)) :test
#'equalp
)))
210 (with-test (:name
:functional-may-escape-p
211 ;; INVALID-UNWIND-ERROR crashes fatally on ppc32. Not sure as of when.
213 (checked-compile-and-assert
218 (flet ((x () (let (*)
222 (() (condition 'control-error
))))
224 (with-test (:name
:lvar-fun-type-on-literal-funs
)
225 (checked-compile-and-assert
228 (declare (type (or null string
) p
))
229 (locally (declare (optimize (space 0)))
230 (stable-sort p
,#'string
<)))
231 (((copy-seq "acb")) "abc" :test
#'equal
)))
233 (with-test (:name
:ir2-optimize-jumps-multiway-branch-if-eq-delete-branch
)
234 (checked-compile-and-assert
237 (declare (type (integer -
345 1) a
))
238 (case (ldb (byte 24 5) a
)
239 ((4 47 61 17 10 39) 1)
241 ((42 48 16 33 40 20) A
)
243 ((15 1 44 29 57 41 52) 32771)
244 ((46 64 3 18 36 49 37) 1)