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

            Bug ID: 85141
           Summary: [6/7/8 Regression] ICE with pointer arithmetic of
                    static member function address
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: reichelt at gcc dot gnu.org
  Target Milestone: ---

The following valid code snippet (compiled with "-fpermissive")
triggers an ICE since GCC 4.7.0:

======================
struct A
{
  static int foo();
};

void bar(int i)
{
  i += A().foo;
}
======================

bug.cc: In function 'void bar(int)':
bug.cc:8:5: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   i += A().foo;
   ~~^~~~~~~~~~
bug.cc:8:12: warning: invalid conversion from 'int (*)()' to 'int'
[-fpermissive]
   i += A().foo;
            ^~~
bug.cc:8:5: internal compiler error: tree check: expected field_decl, have
baselink in component_ref_field_offset, at tree.c:12950
   i += A().foo;
   ~~^~~~~~~~~~
0x78c848 tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ../../gcc/gcc/tree.c:9322
0x795d33 tree_check(tree_node*, char const*, int, char const*, tree_code)
        ../../gcc/gcc/tree.h:3135
0x795d33 component_ref_field_offset(tree_node*)
        ../../gcc/gcc/tree.c:12950
0xc6d027 gimplify_compound_lval
        ../../gcc/gcc/gimplify.c:2936
0xc65372 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.c:11386
0xc74ff3 gimplify_modify_expr
        ../../gcc/gcc/gimplify.c:5625
0xc666f0 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.c:11434
0xc735de gimplify_target_expr
        ../../gcc/gcc/gimplify.c:6576
0xc668ed gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.c:11815
0xc697f6 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.c:6658
0xc6a179 gimplify_compound_expr
        ../../gcc/gcc/gimplify.c:5885
0xc6f74a gimplify_modify_expr_rhs
        ../../gcc/gcc/gimplify.c:5225
0xc74f3a gimplify_modify_expr_rhs
        ../../gcc/gcc/gimplify.c:5125
0xc74f3a gimplify_modify_expr
        ../../gcc/gcc/gimplify.c:5580
0xc666f0 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.c:11434
0xc697f6 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.c:6658
0xc67692 gimplify_cleanup_point_expr
        ../../gcc/gcc/gimplify.c:6399
0xc67692 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.c:11811
0xc697f6 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.c:6658
0xc6b1ea gimplify_body(tree_node*, bool)
        ../../gcc/gcc/gimplify.c:12635
Please submit a full bug report, [etc.]


If I add the option "-fsanitize=undefined" I get a different stack trace:

bug.cc: In function 'void bar(int)':
bug.cc:8:5: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   i += A().foo;
   ~~^~~~~~~~~~
bug.cc:8:12: warning: invalid conversion from 'int (*)()' to 'int'
[-fpermissive]
   i += A().foo;
            ^~~
bug.cc:8:1: internal compiler error: tree check: expected tree that contains
'decl common' structure, have 'baselink' in
cp_ubsan_maybe_instrument_member_access, at cp/cp-ubsan.c:154
 }
 ^
0x78d0a7 tree_contains_struct_check_failed(tree_node const*,
tree_node_structure_enum, char const*, int, char const*)
        ../../gcc/gcc/tree.c:9494
0x5eee6d contains_struct_check(tree_node*, tree_node_structure_enum, char
const*, int, char const*)
        ../../gcc/gcc/tree.h:3249
0x5eee6d cp_ubsan_maybe_instrument_member_access
        ../../gcc/gcc/cp/cp-ubsan.c:154
0x5eee6d cp_ubsan_check_member_access_r
        ../../gcc/gcc/cp/cp-ubsan.c:213
0x116564b walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set<tree_node*, default_hash_traits<tree_node*> >*))
        ../../gcc/gcc/tree.c:11387
0x11659c6 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set<tree_node*, default_hash_traits<tree_node*> >*))
        ../../gcc/gcc/tree.c:11613
0x1165d6f walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set<tree_node*, default_hash_traits<tree_node*> >*))
        ../../gcc/gcc/tree.c:11703
0x8746c0 cp_ubsan_instrument_member_accesses(tree_node**)
        ../../gcc/gcc/cp/cp-ubsan.c:250
0x86f327 cp_genericize_tree
        ../../gcc/gcc/cp/cp-gimplify.c:1576
0x86f622 cp_genericize(tree_node*)
        ../../gcc/gcc/cp/cp-gimplify.c:1714
0x89e312 finish_function(bool)
        ../../gcc/gcc/cp/decl.c:15864
0x93bfa9 cp_parser_function_definition_after_declarator
        ../../gcc/gcc/cp/parser.c:26850
0x93cd26 cp_parser_function_definition_from_specifiers_and_declarator
        ../../gcc/gcc/cp/parser.c:26763
0x93cd26 cp_parser_init_declarator
        ../../gcc/gcc/cp/parser.c:19511
0x943e28 cp_parser_simple_declaration
        ../../gcc/gcc/cp/parser.c:13059
0x944c38 cp_parser_block_declaration
        ../../gcc/gcc/cp/parser.c:12884
0x948bc2 cp_parser_declaration
        ../../gcc/gcc/cp/parser.c:12782
0x948fd1 cp_parser_declaration_seq_opt
        ../../gcc/gcc/cp/parser.c:12658
0x9492c4 cp_parser_translation_unit
        ../../gcc/gcc/cp/parser.c:4563
0x9492c4 c_parse_file()
        ../../gcc/gcc/cp/parser.c:39024
Please submit a full bug report, [etc.]

Reply via email to