Another failure in CASE form

Bug #1850705 reported by Paul F. Dietz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Douglas Katzman

Bug Description

(lambda (b)
  (case b
    ((4 1 2 3) 0)
    ((2 4) (mod b (min -49 0)))
    (t 0)))

==>

The value
  NIL
is not of type
  SB-C:TN-REF
   [Condition of type TYPE-ERROR]

Restarts:
 0: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: (SB-C::DELETE-TN-REF #<SB-C:TN-REF :TN #<SB-C:TN t1 :UNUSED> :WRITE-P T :VOP SB-C:CALL-NAMED>)
  1: (SB-C::DELETE-VOP #<SB-C::VOP :INFO SB-C:CALL-NAMED :ARGS #<SB-C:TN-REF :TN #<SB-C:TN t2[RSP] :NORMAL> :WRITE-P NIL :VOP SB-C:CALL-NAMED> :RESULTS #<SB-C:TN-REF :TN #<SB-C:TN t1 :UNUSED> :WRITE-P T :V..
  2: (SB-C::DELETE-UNUSED-IR2-BLOCKS #<SB-C:COMPONENT :NAME (LAMBDA (B)) {1009DFB9F3}>)
  3: (SB-C::IR2-OPTIMIZE #<SB-C:COMPONENT :NAME (LAMBDA (B)) {1009DFB9F3}>)
[…]

Revision history for this message
Paul F. Dietz (paul-f-dietz) wrote :

Similar failure on

(lambda (s1 s2 c)
  (case s2
    ((2) s2)
    ((2) (mod s1 (max 9 0)))
    ((1 4) 0)
    ((-1) c)
    (t 0)))

Douglas Katzman (dougk)
Changed in sbcl:
assignee: nobody → Douglas Katzman (dougk)
Revision history for this message
Douglas Katzman (dougk) wrote :

this is interesting because it essentially is performing dead-code elimination that was not otherwise performed. The disassembly prior the new feature of multiway branch contains a ton of garbage.

... serial comparisons here, fine ... but then TRUNCATE and GENERIC= ?

; 29C: L2: 48837DF002 CMP QWORD PTR [RBP-16], 2
; 2A1: 74F1 JEQ L0
; 2A3: 48837DF004 CMP QWORD PTR [RBP-16], 4
; 2A8: 74EA JEQ L0
; 2AA: 48837DF006 CMP QWORD PTR [RBP-16], 6
; 2AF: 74E3 JEQ L0
; 2B1: 48837DF004 CMP QWORD PTR [RBP-16], 4
; 2B6: 0F85F2000000 JNE L13
; 2BC: L3: 488B45F0 MOV RAX, [RBP-16]
; 2C0: 8D70F1 LEA ESI, [RAX-15]
; 2C3: 40F6C601 TEST SIL, 1
; 2C7: 751A JNE L4
; 2C9: 4080FE0A CMP SIL, 10
; 2CD: 7414 JEQ L4
; 2CF: 40F6C60F TEST SIL, 15
; 2D3: 0F85CE000000 JNE L12
; 2D9: 8078F11D CMP BYTE PTR [RAX-15], 29
; 2DD: 0F87C4000000 JNBE L12
; 2E3: L4: 488B55F0 MOV RDX, [RBP-16]
; 2E7: 4883EC10 SUB RSP, 16
; 2EB: 48C7C79EFFFFFF MOV RDI, -98
; 2F2: B904000000 MOV ECX, 4
; 2F7: 48892C24 MOV [RSP], RBP
; 2FB: 488BEC MOV RBP, RSP
; 2FE: E83D535CFF CALL #x52116640 ; #<FUNCTION TRUNCATE>
; 303: 48897DE8 MOV [RBP-24], RDI
; 307: 488B55E8 MOV RDX, [RBP-24]
; 30B: 31FF XOR EDI, EDI
; 30D: E8EEFA5AFF CALL #x52100E00 ; GENERIC-=
; etc.

As evidenced from the few uses of DELETE-VOP, it's unclear how robust this stuff is.
Are they broken, or am I "holding it wrong"? I'll dig some more into it.
Anyway, it certainly suggests that analysis of the if/else chain would be nice to do even if the backend does not support coding as anything but a bunch of serial tests, because the analysis is a precondition for finding the unreachable branches.

Douglas Katzman (dougk)
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.