Division operator is optimized away if function is defined by macro, despite div-by-zero still being possible
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Invalid
|
Undecided
|
Unassigned |
Bug Description
```
(defvar *zero* 0)
(defmacro bug-maker (name &body body)
`(defun ,name () ,@body))
(bug-maker doesnt-error (/ 3 *zero*) nil)
(bug-maker errors (/ 3 *zero*))
(doesnt-error)
(errors)
```
Here, doesnt-error throws out the (/ 3 *zero*), likely because it's assuming that the result is pure and unused, therefore optimizes it away. This is despite division having a side-effect of throwing an error if division by zero occurs.
Bug reproduced on:
SBCL 2.3.3: 5.15.0-60-generic #66-Ubuntu SMP Fri Jan 20 14:29:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
SBCL 2.4.10-1.1-suse: 5.15.167.
*features*
(:QUICKLISP :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-UNIX
:NON-BASE-
:ANSI-CL :COMMON-LISP :ELF :IEEE-FLOATING-
:PACKAGE-
:SB-THREAD :SB-UNICODE :SBCL :UNIX)
Have you ensured that this is in safe code?