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

            Bug ID: 102518
           Summary: [11/12 regression] ICE during GIMPLE pass: einline in
                    gimplify_modify_expr at -O2
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlegg at feralinteractive dot com
  Target Milestone: ---

Compiling this c++ code with g++ -O2 -c:
struct A {
  bool operator<(A b) { return b.x; }
  int x;
} * a;
int f(int *const c) {
  const A & b = reinterpret_cast<A const &>(c);
  while (a)
    if (*a < b)
      return 0;
}
int i;
void g() { f(&i); }

causes an ICE with g++ 11.2.0:
v.ii:10:1: warning: control reaches end of non-void function [-Wreturn-type]
   10 | }
      | ^
during GIMPLE pass: einline
v.ii: In function 'void g()':
v.ii:6:45: internal compiler error: in gimplify_modify_expr, at gimplify.c:5988
    6 |   const A & b = reinterpret_cast<A const &>(c);
      |                                             ^
0x6772ed gimplify_modify_expr
        ../../gcc-11.2.0/gcc/gimplify.c:5988
0xac86de gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc-11.2.0/gcc/gimplify.c:14094
0xacd4c2 gimplify_stmt(tree_node**, gimple**)
        ../../gcc-11.2.0/gcc/gimplify.c:6877
0xacd4c2 gimplify_and_add(tree_node*, gimple**)
        ../../gcc-11.2.0/gcc/gimplify.c:489
0xacd4c2 internal_get_tmp_var
        ../../gcc-11.2.0/gcc/gimplify.c:642
0xacd751 get_initialized_tmp_var(tree_node*, gimple**, gimple**, bool)
        ../../gcc-11.2.0/gcc/gimplify.c:674
0xacd751 prepare_gimple_addressable
        ../../gcc-11.2.0/gcc/gimplify.c:4334
0xacd7f1 gimplify_addr_expr
        ../../gcc-11.2.0/gcc/gimplify.c:6230
0xac924f gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc-11.2.0/gcc/gimplify.c:14141
0xac9fe8 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc-11.2.0/gcc/gimplify.c:14253
0xacb35f gimplify_compound_lval
        ../../gcc-11.2.0/gcc/gimplify.c:3074
0xac81b1 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc-11.2.0/gcc/gimplify.c:14046
0xad86b3 gimple_regimplify_operands(gimple*, gimple_stmt_iterator*)
        ../../gcc-11.2.0/gcc/gimplify-me.c:235
0xd907d2 copy_bb
        ../../gcc-11.2.0/gcc/tree-inline.c:2061
0xd91a64 copy_cfg_body
        ../../gcc-11.2.0/gcc/tree-inline.c:3048
0xd91a64 copy_body
        ../../gcc-11.2.0/gcc/tree-inline.c:3303
0xd94ccf expand_call_inline
        ../../gcc-11.2.0/gcc/tree-inline.c:5119
0xd96279 gimple_expand_calls_inline
        ../../gcc-11.2.0/gcc/tree-inline.c:5309
0xd96279 optimize_inline_calls(tree_node*)
        ../../gcc-11.2.0/gcc/tree-inline.c:5482
0x167957e early_inliner(function*)
        ../../gcc-11.2.0/gcc/ipa-inline.c:3007

The test case was heavily reduced, primarily without human interaction. I
wouldn't be surprised if an incorrect use of a type punned pointer was part of
the original code around the problem area however.

The ICE reproduces with "-O1 -finline-small-functions" instead of "-O2", but
not with plain "-O1".
I was able to reproduce it with compiler explorer using gcc with git hash
51018dd1395c72b3681ae5f84eceb94320472922, and 11.1, but not with 10.3 or
earlier.

Reply via email to