PR c++/86320 - memory-hog with std::array of pair
commitcf755750cc4cb7a1e8da982a9801882506bb17f1
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Jun 2018 02:59:44 +0000 (27 02:59 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 Jun 2018 02:59:44 +0000 (27 02:59 +0000)
treee8ecb61a6f283f91fee98716062463538c3c38f0
parent070c395b755448b4bd4bb31c068fabaa166c514c
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 {};
}

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@262173 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/cp/ChangeLog
gcc/cp/typeck2.c