1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-04 02:51:31 -08:00

Fix variable aliasing bytecode miscompilation (bug#67116)

The compiler didn't cancel aliasing if the aliased variable was
modified in a variable binding in the same `let` that created
the alias.  For example,

 (let ((x A))
   (let ((y x)
         (z (setq x B)))
     y))

would incorrectly substitute y->x in the body form despite x being
already modified at that point, which normally should have cancelled
the aliasing.

Bug reported by Alan Mackenzie.

* lisp/emacs-lisp/byte-opt.el (byte-optimize--aliased-vars):
Now an alist that also contains the aliases; update the doc string.
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-let-form):
Detect aliasing early for `let`-bound variables as well.
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases):
Add test cases.
This commit is contained in:
Mattias Engdegård 2023-11-13 11:49:32 +01:00
parent 8090ab0543
commit 1247dc87ba
2 changed files with 36 additions and 29 deletions

View file

@ -643,6 +643,16 @@ inner loops respectively."
(funcall (car f) 3)
(list a b))
(let ((x (list 1)))
(let ((y x)
(z (setq x (vector x))))
(list x y z)))
(let ((x (list 1)))
(let* ((y x)
(z (setq x (vector x))))
(list x y z)))
(cond)
(mapcar (lambda (x) (cond ((= x 0)))) '(0 1))