(CONCATENATE 'string ...) very broken if speed>space

Bug #1334794 reported by Douglas Katzman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

(defun foo () (declare (optimize (speed 3) (safety 0))) (concatenate 'string "a" "b"))
(foo) => "b^@"

Likely culprit is http://sourceforge.net/p/sbcl/sbcl/ci/8e4ec430504f0f563280be26034af590dff50d34

The bad transform is
(concatenate 'string "a" "b") ->
(APPLY
 (LAMBDA (#:G1 #:G2)
   (DECLARE (IGNORABLE #:G1 #:G2))
   (DECLARE (OPTIMIZE (INSERT-ARRAY-BOUNDS-CHECKS 0)))
   (LET* ((.LENGTH. (+ 1 1)) (.POS. 2) (.STRING. (MAKE-STRING .LENGTH. :ELEMENT-TYPE 'CHARACTER)))
     (DECLARE (IGNORABLE .POS.))
     (DECLARE (TYPE INDEX .LENGTH. .POS.)
              (MUFFLE-CONDITIONS COMPILER-NOTE))
     (PROGN (SETF (AREF .STRING. (TRULY-THE INDEX 0)) #\a) NIL)
     (PROGN (SETF (AREF .STRING. (TRULY-THE INDEX 0)) #\b) NIL)
     .STRING.))

Ironically I had mentioned to Christophe in email that the lack of (declare (ignore .POS.)) in the transform had caused us some problems about spurious warnings in the case of only a single string due to our build system consider style-warning to be fatal even in cases that aren't completely broken, e.g.

(concatenate 'string "Hi") ->
(APPLY
 (LAMBDA (#:G1)
   (DECLARE (IGNORABLE #:G1))
   (DECLARE (OPTIMIZE (INSERT-ARRAY-BOUNDS-CHECKS 0)))
   (LET* ((.LENGTH. (+ 2)) (.POS. 2) (.STRING. (MAKE-STRING .LENGTH. :ELEMENT-TYPE 'CHARACTER)))
     (DECLARE (IGNORABLE .POS.))
     (DECLARE (TYPE INDEX .LENGTH. .POS.)
              (MUFFLE-CONDITIONS COMPILER-NOTE))
     (PROGN (SETF (AREF .STRING. (TRULY-THE INDEX 0)) #\H) (SETF (AREF .STRING. (TRULY-THE INDEX 1)) #\i) NIL)
     .STRING.))
 LVARS)

Stas Boukarev (stassats)
Changed in sbcl:
status: New → Fix Committed
Stas Boukarev (stassats)
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.