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

            Bug ID: 79266
           Summary: excessive compile time for large static array (-O1)
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: josh at joshtriplett dot org
  Target Milestone: ---

Consider the following test case:

int main(int argc, char *argv[]) {
    char *array[] = {
#include "num_array.h"
        argv[0],
    };
    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.

Reply via email to