Early inline FLET transform causes bad assembly.

Bug #1793559 reported by Andrzej Walczak
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

(defun inner (x fn)
  (declare (fixnum x) (function fn))
  (funcall fn x))
(declaim (inline inner))

(defun outer (x)
  (flet ((fn (x) (1+ x)))
    (declare (inline fn))
    (inner x #'fn)))

(disassemble 'outer)

; disassembly for OUTER
; Size: 32 bytes. Origin: #x1137796
; 96: 4883EC10 SUB RSP, 16 ; no-arg-parsing entry point
; 9A: 488B05AFFFFFFF MOV RAX, [RIP-81] ; #<FUNCTION (FLET FN :IN OUTER) {11376EB}>
; A1: B902000000 MOV ECX, 2
; A6: 48892C24 MOV [RSP], RBP
; AA: 488BEC MOV RBP, RSP
; AD: FF50FD CALL QWORD PTR [RAX-3]
; B0: 488BE5 MOV RSP, RBP
; B3: F8 CLC
; B4: 5D POP RBP
; B5: C3 RET

;; On the contrary:

(defun outer2 (x y)
  (declare (fixnum x y))
  (flet ((fn (x) (+ x y)))
    (declare (inline fn))
    (inner x #'fn)))

(disassemble 'outer2)

; disassembly for OUTER2
; Size: 12 bytes. Origin: #x1137B76
; 76: 4801D7 ADD RDI, RDX ; no-arg-parsing entry point
; 79: 488BD7 MOV RDX, RDI
; 7C: 488BE5 MOV RSP, RBP
; 7F: F8 CLC
; 80: 5D POP RBP
; 81: C3 RET

Revision history for this message
Stas Boukarev (stassats) wrote :

Seems to be no longer the case.

Changed in sbcl:
status: New → 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.