0.8.3.39:
[sbcl.git] / tests / compiler.test.sh
index 409e0b9..264f474 100644 (file)
 # absolutely no warranty. See the COPYING and CREDITS files for
 # more information.
 
-# FIXME: the functions below should be in their own file, sourced by
-# each of the *.test.sh scripts.
-
-# Check that compiling and loading the file $1 generates an error
-# at load time; also that just loading it directly (into the
-# interpreter) generates an error.
-expect_load_error ()
-{
-    # Test compiling and loading.
-    $SBCL <<EOF
-       (compile-file "$1")
-       ;;; But loading the file should fail.
-       (multiple-value-bind (value0 value1) (ignore-errors (load *))
-           (assert (null value0))
-           (format t "VALUE1=~S (~A)~%" value1 value1)
-           (assert (typep value1 'error)))
-       (sb-ext:quit :unix-status 52)
-EOF
-    if [ $? != 52 ]; then
-       echo compile-and-load $1 test failed: $?
-       exit 1
-    fi
-
-    # Test loading into the interpreter.
-    $SBCL <<EOF
-       (multiple-value-bind (value0 value1) (ignore-errors (load "$1"))
-           (assert (null value0))
-           (format t "VALUE1=~S (~A)~%" value1 value1)
-           (assert (typep value1 'error)))
-       (sb-ext:quit :unix-status 52)
-EOF
-    if [ $? != 52 ]; then
-       echo load-into-interpreter $1 test failed: $?
-       exit 1
-    fi
-}
-
-# Test that a file compiles cleanly, with no ERRORs, WARNINGs or
-# STYLE-WARNINGs.
-expect_clean_compile () 
-{
-    $SBCL <<EOF
-        (multiple-value-bind (pathname warnings-p failure-p)
-            (compile-file "$1")
-          (declare (ignore pathname))
-          (assert (not warnings-p))
-          (assert (not failure-p))
-          (sb-ext:quit :unix-status 52))
-EOF
-    if [ $? != 52 ]; then
-        echo clean-compile $1 test failed: $?
-        exit 1
-    fi
-}
-
-expect_warned_compile ()
-{
-    $SBCL <<EOF
-        (multiple-value-bind (pathname warnings-p failure-p)
-            (compile-file "$1")
-          (declare (ignore pathname))
-          (assert warnings-p)
-          (assert (not failure-p))
-          (sb-ext:quit :unix-status 52))
-EOF
-    if [ $? != 52 ]; then
-        echo warn-compile $1 test failed: $?
-        exit 1
-    fi
-}
-
-expect_failed_compile ()
-{
-    $SBCL <<EOF
-        (multiple-value-bind (pathname warnings-p failure-p)
-            (compile-file "$1")
-          (declare (ignore pathname warnings-p))
-          (assert failure-p)
-          (sb-ext:quit :unix-status 52))
-EOF
-    if [ $? != 52 ]; then
-        echo fail-compile $1 test failed: $?
-        exit 1
-    fi
-}
+. ./expect.sh
 
 base_tmpfilename="compiler-test-$$-tmp"
 tmpfilename="$base_tmpfilename.lisp"
@@ -155,7 +71,8 @@ cat > $tmpfilename <<EOF
 EOF
 expect_clean_compile $tmpfilename
 
-# This in an ideal world would fail, but at present it doesn't.
+# This in an ideal world would fail (that is, return with FAILURE-P
+# set), but at present it doesn't.
 cat > $tmpfilename <<EOF
     (in-package :cl-user)
     (defun foo (x) (list x))
@@ -167,6 +84,52 @@ cat > $tmpfilename <<EOF
 EOF
 # expect_failed_compile $tmpfilename
 
+# This used to not warn, because the VALUES derive-type optimizer was
+# insufficiently precise.
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (defun foo (x) (declare (ignore x)) (values))
+    (defun bar (x) (1+ (foo x)))
+EOF
+expect_failed_compile $tmpfilename
+
+# Even after making the VALUES derive-type optimizer more precise, the
+# following should still be clean.
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (defun foo (x) (declare (ignore x)) (values))
+    (defun bar (x) (car x))
+EOF
+expect_clean_compile $tmpfilename
+
+# NOTINLINE on known functions shouldn't inhibit type inference
+# (spotted by APD sbcl-devel 2003-06-14)
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (defun foo (x)
+      (declare (notinline list))
+      (1+ (list x)))
+EOF
+expect_failed_compile $tmpfilename
+
+# ERROR wants to check its format string for sanity...
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (defun foo (x)
+      (when x
+        (error "~S")))
+EOF
+expect_failed_compile $tmpfilename
+
+# ... but it (ERROR) shouldn't complain about being unable to optimize
+# when it's uncertain about its argument's type
+cat > $tmpfilename <<EOF
+    (in-package :cl-user)
+    (defun foo (x)
+      (error x))
+EOF
+fail_on_compiler_note $tmpfilename
+
 rm $tmpfilename
 rm $compiled_tmpfilename