Bug 69756 - Passing a multidimensional variable-length array into a lambda (by reference) causes an error
Summary: Passing a multidimensional variable-length array into a lambda (by reference)...
Status: RESOLVED DUPLICATE of bug 60230
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda, ice-on-valid-code, wrong-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2016-02-10 20:27 UTC by Sam
Modified: 2022-03-11 00:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.7.4, 6.1.0
Last reconfirmed: 2016-02-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam 2016-02-10 20:27:43 UTC
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.
Comment 1 Richard Biener 2016-02-11 08:30:40 UTC
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).
Comment 2 Richard Biener 2016-02-11 08:39:10 UTC
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.
Comment 3 Paolo Carlini 2018-03-03 00:56:47 UTC
One more...

*** This bug has been marked as a duplicate of bug 60230 ***