public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114638] New: Hang and Memory Consumption Increase during Compilation with Recursive Template Instantiation
@ 2024-04-08 12:07 iamanonymous.cs at gmail dot com
  2024-04-08 12:37 ` [Bug c++/114638] " xry111 at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2024-04-08 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114638
           Summary: Hang and Memory Consumption Increase during
                    Compilation with Recursive Template Instantiation
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---

The following code snippet triggers a hang issue:
============================================
$ cat bug.cpp

struct Z
{
  Z () = default;
  Z (Z const &) = default;
  constexpr Z (Z &&) {}
};

template < typename T > 
constexpr int 
fn (T v)
{
  return fn (v);
}

auto t = fn (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z
(Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z
(Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z (Z ());

============================================
The code with this syntax error should promptly output a compilation error
instead of hanging indefinitely and depleting memory resources. The command we
used is(no error output):
============================================
g++ bug.cpp
============================================


The GCC version:
============================================
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/cTest/gcc/myinstall/libexec/gcc/x86_64-linux-gnu/14.0.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../configure -v --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --enable-checking=no
--enable-languages=c,c++ --disable-multilib --prefix=/home/cTest/gcc/myinstall
--disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.1 20240329 (experimental) (GCC) 
============================================

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

* [Bug c++/114638] Hang and Memory Consumption Increase during Compilation with Recursive Template Instantiation
  2024-04-08 12:07 [Bug c++/114638] New: Hang and Memory Consumption Increase during Compilation with Recursive Template Instantiation iamanonymous.cs at gmail dot com
@ 2024-04-08 12:37 ` xry111 at gcc dot gnu.org
  2024-04-08 20:38 ` [Bug c++/114638] Hang and Memory Consumption Increase during Compilation with many object creation of itself pinskia at gcc dot gnu.org
  2024-04-08 20:48 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-04-08 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org

--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
The test case is just a "compiler bomb" and I don't know if we can do anything
better.

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

* [Bug c++/114638] Hang and Memory Consumption Increase during Compilation with many object creation of itself
  2024-04-08 12:07 [Bug c++/114638] New: Hang and Memory Consumption Increase during Compilation with Recursive Template Instantiation iamanonymous.cs at gmail dot com
  2024-04-08 12:37 ` [Bug c++/114638] " xry111 at gcc dot gnu.org
@ 2024-04-08 20:38 ` pinskia at gcc dot gnu.org
  2024-04-08 20:48 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-08 20:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Hang and Memory Consumption |Hang and Memory Consumption
                   |Increase during Compilation |Increase during Compilation
                   |with Recursive Template     |with many object creation
                   |Instantiation               |of itself

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This has nothing to do with template but rather

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

* [Bug c++/114638] Hang and Memory Consumption Increase during Compilation with many object creation of itself
  2024-04-08 12:07 [Bug c++/114638] New: Hang and Memory Consumption Increase during Compilation with Recursive Template Instantiation iamanonymous.cs at gmail dot com
  2024-04-08 12:37 ` [Bug c++/114638] " xry111 at gcc dot gnu.org
  2024-04-08 20:38 ` [Bug c++/114638] Hang and Memory Consumption Increase during Compilation with many object creation of itself pinskia at gcc dot gnu.org
@ 2024-04-08 20:48 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-08 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-04-08
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
      Known to fail|                            |4.1.2

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
the problem seems related to tentative parsing. But I will note clang does give
an error quickly. 

Reduced C++98 testcase:
```
struct Z
{
  Z ();
  Z (Z const &);
};


Z t = Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z ( Z
(Z (Z (Z ()));
```

GCC did get worse over time though. Add one more `Z(` and it fails. There is
definitely some O(n^2) issue going on. Most likely trying to figure out if this
is a function declaration vs a function call vs an object creation ...

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

end of thread, other threads:[~2024-04-08 20:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-08 12:07 [Bug c++/114638] New: Hang and Memory Consumption Increase during Compilation with Recursive Template Instantiation iamanonymous.cs at gmail dot com
2024-04-08 12:37 ` [Bug c++/114638] " xry111 at gcc dot gnu.org
2024-04-08 20:38 ` [Bug c++/114638] Hang and Memory Consumption Increase during Compilation with many object creation of itself pinskia at gcc dot gnu.org
2024-04-08 20:48 ` pinskia 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).