From 2f430107f46b506dbb8dd79d9ce5a10cc2b3de9b Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Wed, 3 Mar 2021 21:37:13 +0000 Subject: [PATCH] Fix bytecompiler infloop compiling infloops (bug#46906) * lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode): Don't apply optimization if we can't change anything. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-infloop): New test. --- lisp/emacs-lisp/byte-opt.el | 6 +++--- test/lisp/emacs-lisp/bytecomp-tests.el | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index b51ba801552d6..aedfde6c0c6ab 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el @@ -2012,9 +2012,9 @@ byte-optimize-lapcode ((and (memq (car lap0) byte-goto-ops) (memq (car (setq tmp (nth 1 (memq (cdr lap0) lap)))) '(byte-goto byte-return))) - (cond ((and (not (eq tmp lap0)) - (or (eq (car lap0) 'byte-goto) - (eq (car tmp) 'byte-goto))) + (cond ((and (or (eq (car lap0) 'byte-goto) + (eq (car tmp) 'byte-goto)) + (not (eq (cdr tmp) (cdr lap0)))) (byte-compile-log-lap " %s [%s]\t-->\t%s" (car lap0) tmp tmp) (if (eq (car tmp) 'byte-return) diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 03c267ccd0fef..eeb75c53ee2a9 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -1222,6 +1222,11 @@ bytecomp-reify-function (byte-compile 'counter) (should (equal (counter) 1)))))) +(ert-deftest bytecomp-infloop () + "Check that optimizing an infinite loop does not loop indefinitely." + ;; This form should not cause the optimizer to loop (bug#46906) + (byte-compile (lambda (x) (if (eq x x) (f)) (while t)))) + ;; Local Variables: ;; no-byte-compile: t ;; End: -- 2.30.1