+
+(declaim (inline inlined-function-in-source-path))
+(defun inlined-function-in-source-path (x)
+ (+ x x))
+
+(with-test (:name :inlined-function-in-source-path)
+ (let ((output
+ (with-output-to-string (*error-output*)
+ (compile nil `(lambda (x)
+ (declare (optimize speed))
+ (funcall #'inlined-function-in-source-path x))))))
+ ;; We want the name
+ (assert (search "INLINED-FUNCTION-IN-SOURCE-PATH" output))
+ ;; ...not the leaf.
+ (assert (not (search "DEFINED-FUN" output)))))
+
+(defmacro bug-795705 ()
+ t)
+
+(with-test (:name :bug-795705)
+ (assert (macro-function 'bug-795705))
+ (fmakunbound 'bug-795705)
+ (assert (not (macro-function 'bug-795705))))
+
+(with-test (:name (load-time-value :type-derivation))
+ (let ((name 'load-time-value-type-derivation-test))
+ (labels ((funtype (fun)
+ (sb-kernel:type-specifier
+ (sb-kernel:single-value-type
+ (sb-kernel:fun-type-returns
+ (sb-kernel:specifier-type
+ (sb-kernel:%simple-fun-type fun))))))
+ (test (type1 type2 form value-cell-p)
+ (let* ((lambda-form `(lambda ()
+ (load-time-value ,form)))
+ (core-fun (compile nil lambda-form))
+ (core-type (funtype core-fun))
+ (core-cell (ctu:find-value-cell-values core-fun))
+ (defun-form `(defun ,name ()
+ (load-time-value ,form)))
+ (file-fun (progn
+ (ctu:file-compile (list defun-form) :load t)
+ (symbol-function name)))
+ (file-type (funtype file-fun))
+ (file-cell (ctu:find-value-cell-values file-fun)))
+ (if value-cell-p
+ (assert (and core-cell file-cell))
+ (assert (not (or core-cell file-cell))))
+ (unless (subtypep core-type type1)
+ (error "core: wanted ~S, got ~S" type1 core-type))
+ (unless (subtypep file-type type2)
+ (error "file: wanted ~S, got ~S" type2 file-type)))))
+ (let ((* 10))
+ (test '(integer 11 11) 'number
+ '(+ * 1) nil))
+ (let ((* "fooo"))
+ (test '(integer 4 4) 'unsigned-byte
+ '(length *) nil))
+ (test '(integer 10 10) '(integer 10 10) 10 nil)
+ (test 'cons 'cons '(cons t t) t))))
+
+(with-test (:name (load-time-value :errors))
+ (multiple-value-bind (warn fail)
+ (ctu:file-compile
+ `((defvar *load-time-value-error-value* 10)
+ (declaim (fixnum *load-time-value-error-value*))
+ (defun load-time-value-error-test-1 ()
+ (the list (load-time-value *load-time-value-error-value*))))
+ :load t)
+ (assert warn)
+ (assert fail))
+ (handler-case (load-time-value-error-test-1)
+ (type-error (e)
+ (and (eql 10 (type-error-datum e))
+ (eql 'list (type-error-expected-type e)))))
+ (multiple-value-bind (warn2 fail2)
+ (ctu:file-compile
+ `((defun load-time-value-error-test-2 ()
+ (the list (load-time-value 10))))
+ :load t)
+ (assert warn2)
+ (assert fail2))
+ (handler-case (load-time-value-error-test-2)
+ (type-error (e)
+ (and (eql 10 (type-error-datum e))
+ (eql 'list (type-error-expected-type e))))))
+
+;;;; tests for compiler output
+(with-test (:name :unexpected-compiler-output)
+ (let* ((*error-output* (make-string-output-stream))
+ (output (with-output-to-string (*standard-output*)
+ (compile-file "compiler-output-test.lisp"
+ :print nil :verbose nil))))
+ (unless (zerop (length output))
+ (error "Unexpected output: ~S" output))))
+
+(with-test (:name :bug-493380)
+ (flet ((test (forms)
+ (catch 'debug
+ (let ((*debugger-hook* (lambda (condition if)
+ (throw 'debug
+ (if (typep condition 'serious-condition)
+ :debug
+ :oops)))))
+ (multiple-value-bind (warned failed) (ctu:file-compile forms)
+ (when (and warned failed)
+ :failed))))))
+ (assert (eq :failed (test "(defun")))
+ (assert (eq :failed (test "(defun no-pkg::foo ())")))
+ (assert (eq :failed (test "(cl:no-such-sym)")))
+ (assert (eq :failed (test "...")))))
+
+(defun cmacro-signals-error () :fun)
+(define-compiler-macro cmacro-signals-error () (error "oops"))
+
+(with-test (:name :cmacro-signals-error)
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-signals-error)))
+ (assert (and fun warn fail))
+ (assert (eq :fun (funcall fun)))))
+
+(defun cmacro-with-simple-key (&key a)
+ (format nil "fun=~A" a))
+(define-compiler-macro cmacro-with-simple-key (&whole form &key a)
+ (if (constantp a)
+ (format nil "cmacro=~A" (eval a))
+ form))
+
+(with-test (:name (:cmacro-with-simple-key :no-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-with-simple-key)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "cmacro=NIL" (funcall fun)))))
+
+(with-test (:name (:cmacro-with-simple-key :constant-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-with-simple-key :a 42)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "cmacro=42" (funcall fun)))))
+
+(with-test (:name (:cmacro-with-simple-key :variable-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda (x) (cmacro-with-simple-key x 42)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "fun=42" (funcall fun :a)))))
+
+(defun cmacro-with-nasty-key (&key ((nasty-key var)))
+ (format nil "fun=~A" var))
+(define-compiler-macro cmacro-with-nasty-key (&whole form &key ((nasty-key var)))
+ (if (constantp var)
+ (format nil "cmacro=~A" (eval var))
+ form))
+
+(with-test (:name (:cmacro-with-nasty-key :no-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-with-nasty-key)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "cmacro=NIL" (funcall fun)))))
+
+(with-test (:name (:cmacro-with-nasty-key :constant-key))
+ ;; This bogosity is thanks to cmacro lambda lists being /macro/ lambda
+ ;; lists.
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-with-nasty-key 'nasty-key 42)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "fun=42" (funcall fun)))))
+
+(with-test (:name (:cmacro-with-nasty-key :variable-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda (nasty-key) (cmacro-with-nasty-key nasty-key 42)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "fun=42" (funcall fun 'nasty-key)))))
+
+(defconstant tricky-key 'tricky-key)
+(defun cmacro-with-tricky-key (&key ((tricky-key var)))
+ (format nil "fun=~A" var))
+(define-compiler-macro cmacro-with-tricky-key (&whole form &key ((tricky-key var)))
+ (if (constantp var)
+ (format nil "cmacro=~A" (eval var))
+ form))
+
+(with-test (:name (:cmacro-with-tricky-key :no-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-with-tricky-key)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "cmacro=NIL" (funcall fun)))))
+
+(with-test (:name (:cmacro-with-tricky-key :constant-quoted-key))
+ ;; This bogosity is thanks to cmacro lambda lists being /macro/ lambda
+ ;; lists.
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-with-tricky-key 'tricky-key 42)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "fun=42" (funcall fun)))))
+
+(with-test (:name (:cmacro-with-tricky-key :constant-unquoted-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda () (cmacro-with-tricky-key tricky-key 42)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "cmacro=42" (funcall fun)))))
+
+(with-test (:name (:cmacro-with-tricky-key :variable-key))
+ (multiple-value-bind (fun warn fail)
+ (compile nil `(lambda (x) (cmacro-with-tricky-key x 42)))
+ (assert (and (not warn) (not fail)))
+ (assert (string= "fun=42" (funcall fun 'tricky-key)))))
+
+(defun test-function-983 (x) x)
+(define-compiler-macro test-function-983 (x) x)
+
+(with-test (:name :funcall-compiler-macro)
+ (assert
+ (handler-case
+ (and (compile nil
+ `(lambda ()
+ (funcall (function test-function-983 junk) 1)))
+ nil)
+ (sb-c:compiler-error () t))))
+
+(defsetf test-984 %test-984)
+
+(with-test (:name :setf-function-with-setf-expander)
+ (assert
+ (handler-case
+ (and
+ (defun (setf test-984) ())
+ nil)
+ (style-warning () t))))
+
+(with-test (:name :compile-setf-function)
+ (defun (setf compile-setf) ())
+ (assert (equal (compile '(setf compile-setf))
+ '(setf compile-setf))))
+