This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/86320] very long compilation time for std::array<std::pair<int, int>, 1024 * 1024>
- From: "jason at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 27 Jun 2018 03:00:36 +0000
- Subject: [Bug c++/86320] very long compilation time for std::array<std::pair<int, int>, 1024 * 1024>
- Auto-submitted: auto-generated
- References: <bug-86320-4@http.gcc.gnu.org/bugzilla/>
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