[Ecls-list] Miscompiled function

Waldek Hebisch hebisch at math.uni.wroc.pl
Mon Feb 6 14:43:27 UTC 2012


At safety 0 ECL 12.2.1 miscompiles the following file:

------------<cut here>----------------

(defun |c_to_rf| (c) (realpart c))

(DEFUN %D (|t|)
         (DECLARE (DOUBLE-FLOAT |t|))
         (|c_to_rf|
          (/
           (+
            (* 0.5
               (EXP
                (/ (* (* 1.0 |t|) (EXPT (/ -1.0 1.0) (/ 1 (/ 2.0 1.0)))) 1.0)))
            (* 0.5
               (EXP
                (/ (* (* -1.0 |t|) (EXPT (/ -1.0 1.0) (/ 1 (/ 2.0 1.0))))
                   1.0))))
           1.0)))

-------------<cut here>--------------

To reproduce store in a file "ttt.lisp" and do what the transcript shows:

[hebisch at quad1 pp]$ (export ECL_PRESERVE_FILES=true; /mnt/a5/fricas/usrt2/bin/ec
l)
ECL (Embeddable Common-Lisp) 12.2.1 (git:UNKNOWN)
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.  
Top level.
> (require 'cmp)

;;; Loading #P"/mnt/a5/fricas/usrt2/lib/ecl-12.2.1/cmp.fas"
("CMP")
> (proclaim '(optimize (safety 0)))

NIL
> (setf *read-default-float-format* 'double-float)

DOUBLE-FLOAT
> (compile-file "ttt.lisp")

DOUBLE-FLOAT
> (compile-file "ttt.lisp")

;;;
;;; Compiling ttt.lisp.
;;; OPTIMIZE levels: Safety=0, Space=0, Speed=3, Debug=0
;;;
;;; Compiling (DEFUN |c_to_rf| ...).
;;; Compiling (DEFUN %D ...).
;;; End of Pass 1.
;;; Emitting code for |c_to_rf|.
;;; Emitting code for %D.
;;; Finished compiling ttt.lisp.
;;;
#P"/mnt/a5/fricas/axp19/pp1/pp19/pp/ttt.fas"
NIL
NIL
> (load "ttt.fas")
;;; Loading "/mnt/a5/fricas/axp19/pp1/pp19/pp/ttt.fas"
#P"/mnt/a5/fricas/axp19/pp1/pp19/pp/ttt.fas"
> (%d 0.0)

Condition of type: SIMPLE-TYPE-ERROR
In function COERCE, the value of the first argument is
  #C(6.123233995736766d-17 1.0d0)
which is not of the expected type REAL

Available restarts:

1. (RESTART-TOPLEVEL) Go back to Top-Level REPL.

Broken at COERCE.
>> (quit)


Start of generated code is:

/*      function definition for %D                                    */
/*      optimize speed 3, debug 0, space 0, safety 0                  */
static cl_object L2_d(cl_object V1)
{ VT3 VLEX3 CLSR3 STCK3
        const cl_env_ptr cl_env_copy = ecl_process_env();
        cl_object value0;
        double V2;
        V2= ecl_to_double(V1);
TTL:
        {double V3;
        V3= (    1.    )*(V2);
        T0= ecl_expt(VV[3],VV[1]);
        {double V4;
        V4= (V3)*(ecl_to_double(T0));
        {double V5;
        V5= (V4)/(    1.    );
        T1= ecl_exp(ecl_make_doublefloat(V5));


As you can see ECL thinks that

'(EXPT (/ -1.0 1.0) (/ 1 (/ 2.0 1.0)))'

produces value of type 'double-float', but of course this is complex.
Since the only declaration is about '|t|' ECL has no reason to
make such an assumption.

-- 
                              Waldek Hebisch
hebisch at math.uni.wroc.pl 




More information about the ecl-devel mailing list