Bug 79266 - excessive compile time for large static array (-O1)
Summary: excessive compile time for large static array (-O1)
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: compile-time-hog
Depends on: 12245
  Show dependency treegraph
Reported: 2017-01-28 19:50 UTC by Josh Triplett
Modified: 2017-11-25 14:57 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Josh Triplett 2017-01-28 19:50:51 UTC
Consider the following test case:

int main(int argc, char *argv[]) {
    char *array[] = {
#include "num_array.h"
    int sum = 0;
    for (int i = 0; i < sizeof(array)/sizeof(*array); i++) {
        sum += __builtin_strlen(array[i]);
    return sum;

Where num_array.h gets generated as follows:

seq 1 250000 | sed 's/.*/"&",/' > num_array.h

When compiled without optimization, it compiles without issue:

/tmp$ time gcc test.c -o test

real	0m6.563s
user	0m6.288s
sys	0m0.264s
/tmp$ ./test

However, turning on even -O1 causes gcc to run for a long time with no signs of stopping.
Comment 1 Josh Triplett 2017-01-28 20:02:53 UTC
Following up: it looks like gcc -O1 does eventually complete, after several minutes.  -O3 is still running.
Comment 2 Andrew Pinski 2017-01-28 20:15:16 UTC
There might be a dup of this bug just filed a few days ago and that was marked as a dup too.
Comment 3 Richard Biener 2017-01-30 11:31:47 UTC
actually a dup would be likely PR12245 though that's for static arrays.  The dup was for C++ code btw, PR56671 which is about std::bitset<>, a more simple to solve issue.