https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83705
--- Comment #7 from Dominique d'Humieres <dominiq at lps dot ens.fr> --- > Of course, commenting out the part in simplify.c makes the repeat_7.f90 > test fail. Also, when compiling the testcase in this PR the compiler > uses 1.7 GB RAM, so I do think it makes sense to have *some* limit > where we give up and defer to runtime. I agree, but the limit should probably not hardcoded. In order to test large strings with our rebuilding gfortran, I have highjacked flag_max_array_constructor with the following patch: --- ../_clean/gcc/fortran/simplify.c 2018-01-05 20:02:38.000000000 +0100 +++ gcc/fortran/simplify.c 2018-01-07 12:20:45.000000000 +0100 @@ -6080,12 +6114,14 @@ gfc_simplify_repeat (gfc_expr *e, gfc_ex len = e->value.character.length; gfc_charlen_t nlen = ncop * len; - /* Here's a semi-arbitrary limit. If the string is longer than 32 MB - (8 * 2**20 elements * 4 bytes (wide chars) per element) defer to + /* Here's a semi-arbitrary limit. If the string is longer than 256 MB + (8 * 2**25 elements * 4 bytes (wide chars) per element) defer to runtime instead of consuming (unbounded) memory and CPU at compile time. */ - if (nlen > 8388608) + /* printf("nlen = %lld, limit = %lld\n", nlen, 4096ll * flag_max_array_constructor); */ + if (nlen > 4096ll * flag_max_array_constructor) return NULL; + /* printf("result\n"); */ result = gfc_get_character_expr (e->ts.kind, &e->where, NULL, nlen); for (size_t i = 0; i < (size_t) ncop; i++) Note that on darwin repeat_7.f90 compiles, but does not link: % time gfc repeat_7_db.f90 -fmax-array-constructor=1000000 final section layout: __TEXT/__text addr=0x100000E2E, size=0x000000B0, fileOffset=0x00000E2E, type=1 __TEXT/__stubs addr=0x100000EDE, size=0x0000001E, fileOffset=0x00000EDE, type=28 __TEXT/__stub_helper addr=0x100000EFC, size=0x00000042, fileOffset=0x00000EFC, type=32 __TEXT/__cstring addr=0x100000F3E, size=0x00000010, fileOffset=0x00000F3E, type=13 __TEXT/__const addr=0x100000F50, size=0x8000001C, fileOffset=0x00000F50, type=0 __TEXT/__eh_frame addr=0x180000F70, size=0x00000088, fileOffset=0x80000F70, type=19 __DATA/__nl_symbol_ptr addr=0x180001000, size=0x00000010, fileOffset=0x80001000, type=29 __DATA/__la_symbol_ptr addr=0x180001010, size=0x00000028, fileOffset=0x80001010, type=27 __DATA/__huge addr=0x180001038, size=0x00000000, fileOffset=0x00000000, type=25 ld: 32-bit RIP relative reference out of range (2147483784 max is +/-2GB): from _main (0x100000EA1) to _options.1.3769 (0x180000F50) in '_main' from /var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccs6xnfq.o for architecture x86_64 collect2: error: ld returned 1 exit status 218.482u 16.499s 4:01.43 97.3% 0+0k 0+0io 2668pf+0w