Incorrect value returned from intertwined block/return and multiple-value-prog1 forms

Bug #1730699 reported by Paul F. Dietz on 2017-11-07
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

(defun f14 (a b)
  (block b5
    (multiple-value-prog1 b
      (block b7
        (return-from b5
          (multiple-value-prog1 3
            (when a (return-from b7 4))

(f t :good) ==> 3 ;; should be :good

Paul F. Dietz (paul-f-dietz) wrote :

typo: should be (f14 t :good)

Stas Boukarev (stassats) on 2017-11-07
Changed in sbcl:
status: New → Triaged
importance: Undecided → High

This is the same underlying bug as #1723993, but a beautifully nasty expression of it.

The first MULTIPLE-VALUE-PROG1 destroys the value semantics of BLOCK B7 / RETURN-FROM B7. The second destroys the value semantics of WHEN. The BLOCK B5 / RETURN-FROM B5 generates a vestigial exit, but the BLOCK B7 / RETURN-FROM B7 does not, and the result is that the ENTRY for BLOCK B7 has its only EXIT deleted without a trace (other than the CFG edge still existing). MAY-DELETE-VESTIGIAL-EXIT looks at the vestigial exit for BLOCK B5 / RETURN-FROM B5, doesn't see any unusual control flow leading through BLOCK B7, and signals the vestigial exit for deletion. The exit being deleted causes the result LVAR for BLOCK B5 to be assigned to by the RETURN-FROM before the WHEN is evaluated, and it's all downhill from there, since the old value is B and just got unconditionally overwritten.

The beautiful part of this is the much simpler IR1 structure. The nasty part of this is that it doesn't cause a compilation failure, it just silently produces incorrect code.

Stas Boukarev (stassats) wrote :


Changed in sbcl:
status: Triaged → Fix Released
Paul F. Dietz (paul-f-dietz) wrote :

This wasn't actually released yet?

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

Other bug subscribers