Version: gcc (GCC) 5.1.0, Ubuntu 14.04 LTS (virtual machine) gcc -v output: COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-5.1.0/configure --enable-cxx --enable-lto --enable-ssp --with-isl=/usr/local --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-ld=yes --enable-gold=yes --prefix=/usr/local Thread model: posix gcc version 5.1.0 (GCC) command: g++ MWE.cpp -o mwe Output: MWE.cpp: In lambda function: MWE.cpp:6:38: internal compiler error: in expand_expr_real_1, at expr.c:9608 int output = array[i4][i5][i6]; ^ Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. MWE.ii, generated by adding -save-temps to the command: # 1 "MWE.cpp" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "MWE.cpp" int main() { int i1 = 2, i2 = 3, i3 = 4; int array[i1][i2][i3]; auto lambda = [&]() { int i4 = 1, i5 = 2, i6 = 3; int output = array[i4][i5][i6]; }; lambda(); } Additional information: Problem also occurs with two indices (int array [i1][i2]), but not with one index (int array [i1]). Tested on gcc.godbolt.org with GCC version 5.3.0, problem still occurs with similar error message.
We ICE expanding _4(D) in _5 = _4(D) /[ex] 4; But (gdb) p context $7 = <function_decl 0x7ffff69e6d20 main> (gdb) p current_function_decl $8 = <function_decl 0x7ffff69e6e00 operator()> for its underlying decl. So we somehow failed to properly remap things here (and appearantly have no verification for this).
Ok, it's that way already during into-SSA. It seems that we gimplify type sizes and end up using the main()s type size in the lambda which is uninitialized there: main()::<lambda()> (const struct __lambda0 * const __closure) { sizetype D.2424; sizetype D.2425; int[0:D.2357][0:D.2347] * D.2426; int[0:(sizetype) __closure->__array.max][0:D.2357][0:D.2347] & array [value-expr: (int[0:(sizetype) __closure->__array.max][0:D.2357][0:D.2347] &) __closure->__array.ptr]; { int i4; int i5; int i6; int output; typedef struct ._0 ._0; i4 = 1; i5 = 2; i6 = 3; D.2424 = D.2371 /[ex] 4; D.2371 is defined in main(). This hits at invalid tree (type) sharing between functions and/or invalid gimplification or un-nesting. Not sure how lambdas are exactly implemented.
One more... *** This bug has been marked as a duplicate of bug 60230 ***