Opened 5 years ago

Last modified 5 years ago

#1354 assigned defect

Array element not set if array is declared

Reported by: rtoy Owned by: gb
Priority: normal Milestone:
Component: Compiler Version: trunk
Keywords: Cc:


Found this while modifying some code in maxima:

(defvar *z* (make-array 2 :element-type '(complex double-float)
			:initial-contents '(#C(2.0 3.0) #C(-1.0 -1.0))))

(defun $rfft (z)
  (declare (type (simple-array (complex double-float) (*)) z))
  (let* ((n (ash (length z) 1))
	 (result (make-array (1+ (length z)) :element-type '(complex double-float)
			     :initial-element #c(42d0 0))))
    (declare (type (simple-array (complex double-float) (*)) result))

    (when (< n 3)
      (return-from $rfft ($fft input)))
	;;(declare (optimize (speed 3) (safety 0 )))
      ;; Compute FFT of shorter complex vector.  NOTE: the result
      ;; returned by fft has scaled the output by the length of
      ;; z.  That is, divided by n/2.  For our final result, we want to
      ;;     divide by n, so in the following bits of code, we have an
      ;;     extra factor of 2 to divide by.
      ;;(setf z (fft-r2-nn z))

      (format t "z = ~A~%" z)
      ;; Reconstruct the FFT of the original from the parts
      (setf (aref result 0)
	    (complex (* 0.5
			(+ (realpart (aref z 0))
			   (imagpart (aref z 0))))

      (format t "result = ~A~%" result)

After compiling this, run ($rfft *z*). The printed output for result doesn't change, even though set explicitly set the first element to something different from #c(42.0 0).

Remove the declaration, and the output is correct.

(lisp-implementation-version) is Version 1.11-R16635 (Darwinx8664), on OSX 10.11.3

Change History (2)

comment:1 Changed 5 years ago by gb

  • Owner set to gb
  • Status changed from new to assigned

comment:2 Changed 5 years ago by rme

I think that r16720 and r16721 try to fix this in the trunk for x86-64.

I need to see if I can merge a fix for this to 1.11.

Note: See TracTickets for help on using tickets.