public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates
@ 2023-04-06  0:37 zhonghao at pku dot org.cn
  2023-04-06  0:59 ` [Bug c++/109426] Gcc runs into Infinite loop pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: zhonghao at pku dot org.cn @ 2023-04-06  0:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

            Bug ID: 109426
           Summary: Gcc runs into Infinite loop, when resolving templates
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follows:

typedef struct astruct_d
{
 void *data;
} astruct;

/* Generate a whole bunch of unique fake mallocs, this
 keeps the vartrack dump simpler to understand (all
 the "size" arguments have a unique name). */
#define DE0(X) \
 void *malloc##X (unsigned long size##X);
#define DE1(X) \
 DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \
 DE0(X##5) DE0(X##6) DE0(X##7) DE0(X##8) DE0(X##9)
#define DE2(X) \
 DE1(X##0) DE1(X##1) DE1(X##2) DE1(X##3) DE1(X##4) \
 DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9)
#define DE3(X) \
 DE2(X##0) DE2(X##1) DE2(X##2) DE2(X##3) DE2(X##4) \
 DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9)
#define DE4(X) \
 DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \
 DE3(X##5) DE3(X##6) DE3(X##7) DE3(X##8) DE3(X##9)
DE4(0)
#undef DE0
#undef DE1
#undef DE2
#undef DE3
#undef DE4

void foo (void)
{
/* Now call all those mallocs and generate a series of
 variables while at it. */
#define DE0(X) \
 astruct *A##X = (astruct *) malloc##X(sizeof (astruct));
#define DE1(X) \
 DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \
 DE0(X##5) DE0(X##6) DE0(X##7) DE0(X##8) DE0(X##9)
#define DE2(X) \
 DE1(X##0) DE1(X##1) DE1(X##2) DE1(X##3) DE1(X##4) \
 DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9)
#define DE3(X) \
 DE2(X##0) DE2(X##1) DE2(X##2) DE2(X##3) DE2(X##4) \
 DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9)
#define DE4(X) \
 DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \
 DE3(X##5) DE3(X##6) DE3(X##7) DE3(X##8) DE3(X##9)
DE4(0)
DE4(1)
}

GCC runs into an infinite loop:

code0.c:35:18: warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]
   35 |  astruct *A##X = (astruct *) malloc##X(sizeof (astruct));
      |                  ^
code0.c:37:32: note: in expansion of macro ‘DE0’
   37 |  DE0(X##0) DE0(X##1) DE0(X##2) DE0(X##3) DE0(X##4) \
      |                                ^~~
code0.c:41:42: note: in expansion of macro ‘DE1’
   41 |  DE1(X##5) DE1(X##6) DE1(X##7) DE1(X##8) DE1(X##9)
      |                                          ^~~
code0.c:44:2: note: in expansion of macro ‘DE2’
   44 |  DE2(X##5) DE2(X##6) DE2(X##7) DE2(X##8) DE2(X##9)
      |  ^~~
code0.c:46:22: note: in expansion of macro ‘DE3’
   46 |  DE3(X##0) DE3(X##1) DE3(X##2) DE3(X##3) DE3(X##4) \
      |                      ^~~
code0.c:49:1: note: in expansion of macro ‘DE4’
   49 | DE4(1)
      | ^~~

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

* [Bug c++/109426] Gcc runs into Infinite loop
  2023-04-06  0:37 [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates zhonghao at pku dot org.cn
@ 2023-04-06  0:59 ` pinskia at gcc dot gnu.org
  2023-04-06  1:08 ` [Bug c/109426] " pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-06  0:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Gcc runs into Infinite      |Gcc runs into Infinite loop
                   |loop, when resolving        |
                   |templates                   |

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code example you provided does not have any templates ...

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

* [Bug c/109426] Gcc runs into Infinite loop
  2023-04-06  0:37 [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates zhonghao at pku dot org.cn
  2023-04-06  0:59 ` [Bug c++/109426] Gcc runs into Infinite loop pinskia at gcc dot gnu.org
@ 2023-04-06  1:08 ` pinskia at gcc dot gnu.org
  2023-04-06  5:00 ` xry111 at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-06  1:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |c

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is no infinite loop and the code finally completes.

You are causing an warnings of over 2x9999 warning messages with the macros.
This will be slow.

I don't run into an infinite loop at all on the trunk.

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

* [Bug c/109426] Gcc runs into Infinite loop
  2023-04-06  0:37 [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates zhonghao at pku dot org.cn
  2023-04-06  0:59 ` [Bug c++/109426] Gcc runs into Infinite loop pinskia at gcc dot gnu.org
  2023-04-06  1:08 ` [Bug c/109426] " pinskia at gcc dot gnu.org
@ 2023-04-06  5:00 ` xry111 at gcc dot gnu.org
  2023-04-06  9:36 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-04-06  5:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |xry111 at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> There is no infinite loop and the code finally completes.
> 
> You are causing an warnings of over 2x9999 warning messages with the macros.
> This will be slow.

Looks like it's slow not only because of the warnings.  The preprocessed code
is 1.6M and it's slow even with -w (62.76s with 12.2.0).

> 
> I don't run into an infinite loop at all on the trunk.

Anyway this is INVALID.  You cannot assume any compiler able to compile such a
compiler bomb efficiently.

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

* [Bug c/109426] Gcc runs into Infinite loop
  2023-04-06  0:37 [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates zhonghao at pku dot org.cn
                   ` (2 preceding siblings ...)
  2023-04-06  5:00 ` xry111 at gcc dot gnu.org
@ 2023-04-06  9:36 ` redi at gcc dot gnu.org
  2023-04-06 10:25 ` xry111 at gcc dot gnu.org
  2023-04-06 11:07 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-06  9:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. this code is just copied from PR 54402. It might have been helpful to say
where you found the code.

zhonghao, it's really not helpful to just copy&paste code that you don't
understand into bug reports with stupid, incorrect claims like "while expanding
templates". Maybe you're trying to be helpful, but you're just wasting our
time.

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

* [Bug c/109426] Gcc runs into Infinite loop
  2023-04-06  0:37 [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates zhonghao at pku dot org.cn
                   ` (3 preceding siblings ...)
  2023-04-06  9:36 ` redi at gcc dot gnu.org
@ 2023-04-06 10:25 ` xry111 at gcc dot gnu.org
  2023-04-06 11:07 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-04-06 10:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

--- Comment #5 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #4)
> N.B. this code is just copied from PR 54402. It might have been helpful to
> say where you found the code.
> 
> zhonghao, it's really not helpful to just copy&paste code that you don't
> understand into bug reports with stupid, incorrect claims like "while
> expanding templates". Maybe you're trying to be helpful, but you're just
> wasting our time.

I'm wondering if this is an attempt for some kind of "academic research" here
like the notorious UMN incident in LKML.

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

* [Bug c/109426] Gcc runs into Infinite loop
  2023-04-06  0:37 [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates zhonghao at pku dot org.cn
                   ` (4 preceding siblings ...)
  2023-04-06 10:25 ` xry111 at gcc dot gnu.org
@ 2023-04-06 11:07 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-06 11:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109426

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's a pattern with this person:
https://gcc.gnu.org/bugzilla/buglist.cgi?bug_status=RESOLVED&cf_known_to_fail_type=allwords&cf_known_to_work_type=allwords&email1=zhonghao%40pku.org.cn&emailreporter1=1&emailtype1=substring&list_id=377697&product=gcc&query_format=advanced&resolution=INVALID

See PR 86306 for discussion and their justification for these low quality
reports. I think they're genuinely trying to be helpful, just not succeeding.

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

end of thread, other threads:[~2023-04-06 11:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06  0:37 [Bug c++/109426] New: Gcc runs into Infinite loop, when resolving templates zhonghao at pku dot org.cn
2023-04-06  0:59 ` [Bug c++/109426] Gcc runs into Infinite loop pinskia at gcc dot gnu.org
2023-04-06  1:08 ` [Bug c/109426] " pinskia at gcc dot gnu.org
2023-04-06  5:00 ` xry111 at gcc dot gnu.org
2023-04-06  9:36 ` redi at gcc dot gnu.org
2023-04-06 10:25 ` xry111 at gcc dot gnu.org
2023-04-06 11:07 ` redi at gcc dot gnu.org

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).