Bug 62272 - Gimplify throws error on method call from inside nested lambdas
Summary: Gimplify throws error on method call from inside nested lambdas
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.1
: P3 major
Target Milestone: 5.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 58907 (view as bug list)
Depends on:
Blocks: lambdas 67244
  Show dependency treegraph
 
Reported: 2014-08-26 20:48 UTC by Aaron Plavnick
Modified: 2015-08-17 21:28 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.2.1, 6.0
Known to fail: 4.9.3
Last reconfirmed: 2014-08-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Plavnick 2014-08-26 20:48:01 UTC
Here is a minimal code sample, the bug exists in 4.7.3, 4.8.2, and 4.9.1. I compiled with -std=c++11

--------------------------------------------

template< typename T >
class B
{
    public:
        void Foo() {}

        void Bar()
        {
            [&]()
            {
                [&]() { Foo(); }();
            }();
        }
};

int main( int argc, char** argv )
{
    B<int> b;
    b.Bar();
    return 0;
}

----------------------

The compiler returns: 

main.cpp: In lambda function:
main.cpp:11:34: internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:1741
                 [&]() { Foo(); }();
                                  ^
0x81b03d gimplify_var_or_parm_decl
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:1741
0x81d931 gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:8058
0x81cb40 gimplify_modify_expr
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:4527
0x81d97a gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:7627
0x820876 gimplify_stmt(tree_node**, gimple_statement_base**)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:5373
0x820a3a gimplify_and_add
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:385
0x820a3a gimplify_init_ctor_eval
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:3558
0x81c0f2 gimplify_init_constructor
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:3904
0x81c98e gimplify_modify_expr_rhs
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:4167
0x81ca64 gimplify_modify_expr
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:4486
0x81d97a gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:7627
0x81da18 gimplify_target_expr
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:5304
0x81da18 gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:7994
0x81e4b3 gimplify_addr_expr
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:4833
0x81e4b3 gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:7673
0x8235ba gimplify_call_expr
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:2395
0x81db82 gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:7598
0x820876 gimplify_stmt(tree_node**, gimple_statement_base**)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:5373
0x81dc0a gimplify_cleanup_point_expr
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:5149
0x81dc0a gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../../../src/gcc-4.9.1/gcc/gimplify.c:7990
Comment 1 Richard Biener 2014-08-27 08:15:44 UTC
Confirmed.

#1  0x0000000000ba3fb8 in gimplify_var_or_parm_decl (expr_p=0x7ffff68356b0)
    at /space/rguenther/src/svn/trunk/gcc/gimplify.c:1759
1759          gcc_assert (seen_error ());
(gdb) l
1754      if (TREE_CODE (decl) == VAR_DECL
1755          && !DECL_SEEN_IN_BIND_EXPR_P (decl)
1756          && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl)
1757          && decl_function_context (decl) == current_function_decl)
1758        {
1759          gcc_assert (seen_error ());
1760          return GS_ERROR;

(gdb) p debug_tree (decl)
 <var_decl 0x7ffff6831090 this
    type <pointer_type 0x7ffff682a150
...
    align 64 context <function_decl 0x7ffff682bc00 operator()>
    value-expr <component_ref 0x7ffff67c3f30 type <pointer_type 0x7ffff682a150>
        readonly
        arg 0 <indirect_ref 0x7ffff682e660 type <record_type 0x7ffff682f150 __lambda0>
            arg 0 <parm_decl 0x7ffff682c400 __closure>>
        arg 1 <field_decl 0x7ffff68302f8 __this type <pointer_type 0x7ffff682a150>
            used unsigned nonlocal decl_7 DI file t.ii line 11 col 18 size <integer_cst 0x7ffff66c4de0 64> unit size <integer_cst 0x7ffff66c4df8 8>
            align 64 offset_align 128
            offset <integer_cst 0x7ffff66c4e10 constant 0>
            bit offset <integer_cst 0x7ffff66c4e58 constant 0> context <record_type 0x7ffff682af18 __lambda0> chain <type_decl 0x7ffff6813ed8 __lambda0>>>>

seems like un-nesting didn't work somehow?
Comment 2 rippey.e 2014-11-03 19:17:46 UTC
Still broken in 4.9.2.
Comment 3 Guille 2015-02-21 20:07:14 UTC
For what it's worth, it compiles with the following modification [adding "this->" to the Foo call]:

template<typename T> class B
{
    public:
        void Foo() {}
        void Bar()
        {
            [&]()
            {
                [&]() { this->Foo(); }();
            }();
        }
};

int main( int argc, char** argv )
{
    B<int> b;
    b.Bar();
    return 0;
}

Without the "this->", it compiles in neither 4.9.2, nor 5.0.0.
Comment 4 Markus Trippelsdorf 2015-08-17 06:24:59 UTC
*** Bug 58907 has been marked as a duplicate of this bug. ***
Comment 5 Markus Trippelsdorf 2015-08-17 06:25:13 UTC
*** Bug 67244 has been marked as a duplicate of this bug. ***
Comment 6 Markus Trippelsdorf 2015-08-17 19:25:10 UTC
Fixed for gcc-5 by r226950 and gcc-6 by r226951.

gcc-4.9 still ICEs.
Comment 7 Markus Trippelsdorf 2015-08-17 19:29:38 UTC
*** Bug 58907 has been marked as a duplicate of this bug. ***
Comment 8 Jason Merrill 2015-08-17 19:50:15 UTC
Fixed for 5.3.
Comment 9 Markus Trippelsdorf 2015-08-17 19:53:22 UTC
(In reply to Jason Merrill from comment #8)
> Fixed for 5.3.

Well, 4.9.3 still ICEs.
Comment 10 Jason Merrill 2015-08-17 21:28:34 UTC
(In reply to Markus Trippelsdorf from comment #9)
> (In reply to Jason Merrill from comment #8)
> > Fixed for 5.3.
> 
> Well, 4.9.3 still ICEs.

Yes, but this isn't a regression.