From: Pip Cet <pipcet@gmail.com>
To: Andy Moreton <andrewjmoreton@gmail.com>
Cc: 46906@debbugs.gnu.org
Subject: bug#46906: 28.0.50; byte compiler infloops trying to compile infloop
Date: Thu, 4 Mar 2021 07:17:54 +0000 [thread overview]
Message-ID: <CAOqdjBfr6K7w8UvvJrUFuYQOiaFhNeqZcMZNq1NOfAHRoSZAWA@mail.gmail.com> (raw)
In-Reply-To: <86y2f3vmmb.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 818 bytes --]
On Wed, Mar 3, 2021 at 11:34 PM Andy Moreton <andrewjmoreton@gmail.com> wrote:
> On Wed 03 Mar 2021, Pip Cet wrote:
> > On Wed, Mar 3, 2021 at 9:15 PM Pip Cet <pipcet@gmail.com> wrote:
> >>
> >> Recipe in emacs -Q:
> >>
> >> In *scratch*, evaluate:
> >>
> >> (byte-compile (lambda (x)
> >> (if x (f))
> >> (while t)))
> >>
> >> Expected result:
> >>
> >> A (fairly useless) bytecode object
> >>
> >> Actual result:
> >>
> >> A spinning hourglass.
> >
> > Seems to be a fairly obvious bug in byte-opt.el, patch attached.
>
> Perhaps add your reproducer as a test case ?
Absolutely, thanks for the suggestion. See attached patch.
Should there, maybe, be a tag for tests that are known to loop forever
when they fail? It feels weird to write a test without a single should
in it...
Pip
[-- Attachment #2: 0001-Fix-bytecompiler-infloop-compiling-infloops-bug-4690.patch --]
[-- Type: text/x-patch, Size: 1924 bytes --]
From 2f430107f46b506dbb8dd79d9ce5a10cc2b3de9b Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
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
next prev parent reply other threads:[~2021-03-04 7:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-03 21:14 bug#46906: 28.0.50; byte compiler infloops trying to compile infloop Pip Cet
2021-03-03 21:44 ` Pip Cet
2021-03-03 23:33 ` Andy Moreton
2021-03-04 7:17 ` Pip Cet [this message]
2021-03-04 9:15 ` Juri Linkov
2021-03-04 10:19 ` Pip Cet
2021-03-04 11:16 ` Lars Ingebrigtsen
2021-03-04 12:15 ` Pip Cet
2021-03-05 13:16 ` Lars Ingebrigtsen
2021-03-04 17:58 ` Juri Linkov
2021-03-04 18:50 ` Pip Cet
2021-03-05 13:17 ` Lars Ingebrigtsen
2022-06-20 0:00 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOqdjBfr6K7w8UvvJrUFuYQOiaFhNeqZcMZNq1NOfAHRoSZAWA@mail.gmail.com \
--to=pipcet@gmail.com \
--cc=46906@debbugs.gnu.org \
--cc=andrewjmoreton@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.