Something went wrong while setting issue due date.
Local variable corruption, with handler-bind inside loop
In the following code the local variables of F get corrupted:
(in-package :cl-user)
(defun f ()
(let ((val 1234)
(x 3))
(loop while (> x 0)
do (block try-except-stmt
(handler-bind
((error (lambda (e)
(warn "Error: ~S" e)
;; Without the next expression, the function works as expected
(return-from try-except-stmt nil))))
(my-call (lambda ()
(warn "x: ~S val: ~S" x val)
(decf x 1)
(warn "new x: ~S" x))))))))
(defun my-call (func)
(funcall func))
The expected output occurs if the code is run interpreted:
> (load "/tmp/x.lisp")
#P"/tmp/x.lisp"
> (f)
;;; Warning: x: 3 val: 1234
;;; Warning: new x: 2
;;; Warning: x: 2 val: 1234
;;; Warning: new x: 1
;;; Warning: x: 1 val: 1234
;;; Warning: new x: 0
NIL
But with F compiled the output is wrong. The variables X and VAL get bogus values:
> (compile 'f)
;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; End of Pass 1.
F
NIL
NIL
> (f)
;;; Warning: x: 3 val: 1234
;;; Warning: new x: 2
;;; Warning: x: 1725 val: 2
;;; Warning: new x: 1724
;;; Warning: x: 1728 val: 1724
;;; Warning: new x: 1727
;;; Warning: x: 1731 val: 1727
;;; Warning: new x: 1730
;;; Warning: x: 1734 val: 1730
...
(lisp-implementation-version) "16.1.3"
(ext:lisp-implementation-vcs-id) "226dd3577510bb6c6a2a06db10e857dfd788996e"
(software-type) "Linux"
(software-version) "3.16.0-4-amd64"
(machine-type) "x86_64"
*features* QUICKLISP ASDF-PACKAGE-SYSTEM ASDF3.1 ASDF3 ASDF2 ASDF OS-UNIX NON-BASE-CHARS-EXIST-P ASDF-UNICODE WALKER CDR-1 CDR-5 LINUX FORMATTER CDR-7 ECL-WEAK-HASH LITTLE-ENDIAN ECL-READ-WRITE-LOCK LONG-LONG UINT64-T UINT32-T UINT16-T RELATIVE-PACKAGE-NAMES LONG-FLOAT UNICODE DFFI CLOS-STREAMS CMU-FORMAT UNIX ECL-PDE DLOPEN CLOS THREADS BOEHM-GC ANSI-CL COMMON-LISP IEEE-FLOATING-POINT CDR-14 PREFIXED-API FFI X86_64 COMMON ECL
The test code is extracted from a CLPython test case.