unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36484: c-mode hangs on macro with comment
@ 2019-07-03  0:36 Nicholas Drozd
       [not found] ` <mailman.43.1562114299.2688.bug-gnu-emacs@gnu.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Nicholas Drozd @ 2019-07-03  0:36 UTC (permalink / raw)
  To: 36484

Here's a simple C program:

#define x /***/5
int main(void) {
    return x;
}

`gcc -Wall` compiles it without any warnings, but opening it causes
Emacs to hang, and sometimes even to freeze hard.

It has something to do with the macro, but I haven't been able to
figure out exactly what's going on.

Here's a test function with an even smaller reproducing example:

(defun c-mode-hang ()
  (interactive)
  (with-temp-buffer
    (insert "#define /***/5")
    (c-mode)))

Running that function under the profiler suggests that the problem is
in `c-end-of-macro`:

- c-extend-region-for-CPP          13869  98%
  - c-end-of-macro                     10470  74%
    c-forward-single-comment        2759  19%

This may have something to do with commit 39acaf, or maybe 6b5388.

GNU Emacs 27.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
of 2019-06-30





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#36484: c-mode hangs on macro with comment
       [not found] ` <mailman.43.1562114299.2688.bug-gnu-emacs@gnu.org>
@ 2019-07-04 10:36   ` Alan Mackenzie
  2019-07-04 13:34   ` Alan Mackenzie
       [not found]   ` <20190704133423.88899.qmail@mail.muc.de>
  2 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-07-04 10:36 UTC (permalink / raw)
  To: Nicholas Drozd; +Cc: 36484

Hello, Nicholas.

In article <mailman.43.1562114299.2688.bug-gnu-emacs@gnu.org> you wrote:
> Here's a simple C program:

> #define x /***/5
> int main(void) {
>     return x;
> }

> `gcc -Wall` compiles it without any warnings, but opening it causes
> Emacs to hang, and sometimes even to freeze hard.

I can reproduce this, and I'm looking into the cause.

> It has something to do with the macro, but I haven't been able to
> figure out exactly what's going on.

> Here's a test function with an even smaller reproducing example:

> (defun c-mode-hang ()
>   (interactive)
>   (with-temp-buffer
>     (insert "#define /***/5")
>     (c-mode)))

> Running that function under the profiler suggests that the problem is
> in `c-end-of-macro`:

> - c-extend-region-for-CPP          13869  98%
>   - c-end-of-macro                     10470  74%
>     c-forward-single-comment        2759  19%

Thanks, that's helpful information.

> This may have something to do with commit 39acaf, or maybe 6b5388.

> GNU Emacs 27.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
> of 2019-06-30

-- 
Alan Mackenzie (Nuremberg, Germany).






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#36484: c-mode hangs on macro with comment
       [not found] ` <mailman.43.1562114299.2688.bug-gnu-emacs@gnu.org>
  2019-07-04 10:36   ` Alan Mackenzie
@ 2019-07-04 13:34   ` Alan Mackenzie
       [not found]   ` <20190704133423.88899.qmail@mail.muc.de>
  2 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-07-04 13:34 UTC (permalink / raw)
  To: Nicholas Drozd; +Cc: 36484

Hello again, Nicholas.

In article <mailman.43.1562114299.2688.bug-gnu-emacs@gnu.org> you wrote:
> Here's a simple C program:

> #define x /***/5
> int main(void) {
>     return x;
> }

> `gcc -Wall` compiles it without any warnings, but opening it causes
> Emacs to hang, and sometimes even to freeze hard.

> It has something to do with the macro, but I haven't been able to
> figure out exactly what's going on.

There was an infinite loop in c-end-of-macro, now fixed.

[ .... ]

> Running that function under the profiler suggests that the problem is
> in `c-end-of-macro`:

Indeed, so.

[ .... ]

I've committed a patch to the Emacs repository master branch.  Would you
please update your copy of master, and confirm the bug is indeed fixed
(or else, tell me what's still wrong).

> GNU Emacs 27.0.50 (build 6, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
> of 2019-06-30

Thanks for taking the trouble to report this bug, and thanks even more
for making it such an easy to follow report, and doing so much diagnosis
on it.

-- 
Alan Mackenzie (Nuremberg, Germany).






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#36484: c-mode hangs on macro with comment
       [not found]   ` <20190704133423.88899.qmail@mail.muc.de>
@ 2019-07-04 17:08     ` Nicholas Drozd
  2019-07-17  8:22       ` Alan Mackenzie
  0 siblings, 1 reply; 7+ messages in thread
From: Nicholas Drozd @ 2019-07-04 17:08 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 36484

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Works for me! Attached is a patch for an added cc-mode test case.

By the way, I came across this issue because a similar line appears in
a winning entry to the 1988 International Obfuscated C Code Contest
(https://www.ioccc.org/1988/dale.c). That line is included in the test
case.

Trivia question: which Emacs maintainer is a past IOCCC winner?

[-- Attachment #2: 0001-test-lisp-progmodes-cc-mode-tests.el-Add-test-for-bu.patch --]
[-- Type: text/x-patch, Size: 979 bytes --]

From 569c10a367edb261a45d41f119d98e3bc932d135 Mon Sep 17 00:00:00 2001
From: Nick Drozd <nicholasdrozd@gmail.com>
Date: Thu, 4 Jul 2019 10:59:25 -0500
Subject: [PATCH] * test/lisp/progmodes/cc-mode-tests.el: Add test for
 bug#36484

---
 test/lisp/progmodes/cc-mode-tests.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/test/lisp/progmodes/cc-mode-tests.el b/test/lisp/progmodes/cc-mode-tests.el
index 0b8f37dbbf..c10105fffc 100644
--- a/test/lisp/progmodes/cc-mode-tests.el
+++ b/test/lisp/progmodes/cc-mode-tests.el
@@ -69,4 +69,13 @@ c-or-c++-mode
               "struct template {"
               "#include <string.h>")))))
 
+(ert-deftest c-mode-macro-comment ()
+  "Test for bug#36484."
+  (dolist (macro-string '("#define /***/f"
+                          "#define x /***/5"
+                          "#define a(x)get/***/x/***/id())"))
+    (with-temp-buffer
+      (insert macro-string)
+      (c-mode))))
+
 ;;; cc-mode-tests.el ends here
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#36484: c-mode hangs on macro with comment
  2019-07-04 17:08     ` Nicholas Drozd
@ 2019-07-17  8:22       ` Alan Mackenzie
  2019-07-17 13:29         ` Nicholas Drozd
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Mackenzie @ 2019-07-17  8:22 UTC (permalink / raw)
  To: Nicholas Drozd; +Cc: 36484-done

Hello, Nicholas.

On Thu, Jul 04, 2019 at 12:08:14 -0500, Nicholas Drozd wrote:
> Works for me!

That's great, thanks.  I'm closing the bug with this post.

> Attached is a patch for an added cc-mode test case. 

The patch works fine, too, thanks.  But I got bogged down on the
copyright assignment sort of things for the patch.

Have you signed copyright assignment papers for Emacs?  (I think you
have, judging by the number of commits in your name, but I don't know
where to look to check.)

Otherwise, it would appear that your patch is a "trivial" patch, in that
it is less than 15 lines long.  But I think that only applies when the
total number of lines you've contributed to Emacs is less than about 15.

So, sorry about all this non-creative stuff, but would you please tell
me whether or not you've signed an Emacs copyright assignment.  Then I
should be able to commit your patch.

> By the way, I came across this issue because a similar line appears in
> a winning entry to the 1988 International Obfuscated C Code Contest
> (https://www.ioccc.org/1988/dale.c). That line is included in the test
> case.

> Trivia question: which Emacs maintainer is a past IOCCC winner?

I don't know (and haven't cheated by researching it ;-), but if I had to
guess, I'd say Paul Eggert.

[ snip patch ].

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#36484: c-mode hangs on macro with comment
  2019-07-17  8:22       ` Alan Mackenzie
@ 2019-07-17 13:29         ` Nicholas Drozd
  2019-07-17 14:32           ` Alan Mackenzie
  0 siblings, 1 reply; 7+ messages in thread
From: Nicholas Drozd @ 2019-07-17 13:29 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 36484-done

Yes, I've signed, and yes, it was him (1990)!





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#36484: c-mode hangs on macro with comment
  2019-07-17 13:29         ` Nicholas Drozd
@ 2019-07-17 14:32           ` Alan Mackenzie
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Mackenzie @ 2019-07-17 14:32 UTC (permalink / raw)
  To: Nicholas Drozd; +Cc: 36484

Hello again, Nicholas.

On Wed, Jul 17, 2019 at 08:29:44 -0500, Nicholas Drozd wrote:
> Yes, I've signed, ....

Great!  I've committed the amendment to cc-mode-tests.el in your name.

> .... and yes, it was him (1990)!

Hah!  Good guess then!  It doesn't surprise me at all.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-07-17 14:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-03  0:36 bug#36484: c-mode hangs on macro with comment Nicholas Drozd
     [not found] ` <mailman.43.1562114299.2688.bug-gnu-emacs@gnu.org>
2019-07-04 10:36   ` Alan Mackenzie
2019-07-04 13:34   ` Alan Mackenzie
     [not found]   ` <20190704133423.88899.qmail@mail.muc.de>
2019-07-04 17:08     ` Nicholas Drozd
2019-07-17  8:22       ` Alan Mackenzie
2019-07-17 13:29         ` Nicholas Drozd
2019-07-17 14:32           ` Alan Mackenzie

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).