Bug 109421 - Compilation takes a long time for struct that contains a large default-initialized array
Summary: Compilation takes a long time for struct that contains a large default-initia...
Status: RESOLVED DUPLICATE of bug 92385
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: compile-time-hog
Depends on:
Blocks:
 
Reported: 2023-04-05 17:20 UTC by Emily Jakobs
Modified: 2023-04-05 17:25 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emily Jakobs 2023-04-05 17:20:44 UTC
This is similar to #59659, but is still a problem in GCC 11.2.1 and GCC 10.2.1. 

The following code takes a very long time to compile with -O3 enabled:


#include <vector>

#ifndef SIZE
#define SIZE 100000
#endif
struct S
{
  int a;
};

struct T
{
  std::vector<S> arr[SIZE]{}; // remove the default-initializer {} to compile fast
};

int main(int argc, char** argv)
{
  T t;
  for (int i=0; i<SIZE; ++i) {
    t.arr[i].push_back(S{argc * i}); // use argc so that gcc doesn't optimize everything out
  }
  return t.arr[SIZE-1][0].a;
}
Comment 1 Andrew Pinski 2023-04-05 17:24:54 UTC
Looks to be fixed with GCC 12.1.0 .
Comment 2 Andrew Pinski 2023-04-05 17:25:40 UTC
Dup of bug 92385.

*** This bug has been marked as a duplicate of bug 92385 ***