This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/86320] very long compilation time for std::array<std::pair<int, int>, 1024 * 1024>


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

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Wed Jun 27 02:59:44 2018
New Revision: 262173

URL: https://gcc.gnu.org/viewcvs?rev=262173&root=gcc&view=rev
Log:
        PR c++/86320 - memory-hog with std::array of pair

        * typeck2.c (process_init_constructor_array): Only compute a
        constant initializer once.

In this PR, we have a large std::array of pairs.  Since the C array is
wrapped in a class we don't go to build_vec_init, so we end up with
digest_init wanting to build up the element initializer for each element of
the array.

In the more general case, like 80272, we have a data structure problem: we
don't currently have a good way of expressing the same dynamic
initialization of many elements within a CONSTRUCTOR.  RANGE_EXPR probably
ought to work, but will need more work at genericize or gimplify time.

But in this case, the initialization for each element reduces to constant
0, so we don't even need to add anything to the CONSTRUCTOR.  We just need
to realize that if the initializer for one element is 0, the others will be
as well, and we don't need to iterate over the whole array.

For the trunk, I also use a RANGE_EXPR to handle constant initialization by
a value other than 0.

void foo ()
{
  std::array<std::pair<int, int>, 1024 * 1024> arr {};
}

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck2.c

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]