functions bodies ending in infinite loops execute false branches

Bug #1986810 reported by Artyom Bologov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
High
Unassigned

Bug Description

I'm doing a CLI app that starts some threads and then does (loop) to force the executable stay alive and not (quit). However, having:
- function body ending in (loop) or equivalent infinite loop (I've tried (loop while t) and (loop for i = 0 until (plusp i)), for instance),
- (if arg ...) or (when arg ...) checks in the body,
- and some non-obviously-nil arg
makes the if/when before the (loop) to execute unconditionally, even if the condition is false.

The code snippet that shows the behavior reliably:
(progn
  (defvar *whatever-var* nil)
  (defun whatever ()
    (let ((arg (parse-integer
                ""
                :junk-allowed t)))
      (when arg
        (setf *whatever-var* "woo")))
    (loop))
  (sb-thread:make-thread (lambda ()
                    (whatever)))
  (sleep 1)
  *whatever-var*)

2. SBCL version:
$ sbcl --version
SBCL 2.2.6

3. uname output
$ uname -a
Linux paranoidal 5.18.10 #1 SMP PREEMPT_DYNAMIC 1 x86_64 GNU/Linux

4. Features
CL-USER> *features*
(:SLYNK CFFI-FEATURES:FLAT-NAMESPACE CFFI-FEATURES:X86-64 CFFI-FEATURES:UNIX
 :CFFI CFFI-SYS::FLAT-NAMESPACE ALEXANDRIA::SEQUENCE-EMPTYP :QUICKLISP :ASDF3.3
 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-UNIX :NON-BASE-CHARS-EXIST-P
 :ASDF-UNICODE :X86-64 :GENCGC :64-BIT :ANSI-CL :COMMON-LISP :ELF
 :IEEE-FLOATING-POINT :LINUX :LITTLE-ENDIAN :PACKAGE-LOCAL-NICKNAMES
 :SB-CORE-COMPRESSION :SB-LDB :SB-PACKAGE-LOCKS :SB-THREAD :SB-UNICODE :SBCL
 :UNIX)

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

I hope you don't actually have a (loop) in your code. That just wastes enormous amounts of CPU time.

Changed in sbcl:
importance: Undecided → High
status: New → Confirmed
assignee: nobody → Stas Boukarev (stassats)
Stas Boukarev (stassats)
Changed in sbcl:
status: Confirmed → Fix Committed
assignee: Stas Boukarev (stassats) → nobody
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.