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

            Bug ID: 70992
           Summary: Infinite recursion between fold_build2_stat_loc and
                    fold_binary_loc w/ -fwrapv
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: asolokha at gmx dot com
  Target Milestone: ---

1. Deep recursion between fold_binary_loc() and fold_build2_stat_loc() causes
cc1 to ICE on the following reduced testcase when compiling w/ -fwrapv:

unsigned int *od;
int wy = (0 % 0 + 1) * *od * 2;

% x86_64-unknown-linux-gnu-gcc-7.0.0-alpha20160501 -c -fwrapv zrcoshfy.c
zrcoshfy.c:2:13: warning: division by zero [-Wdiv-by-zero]
 int wy = (0 % 0 + 1) * *od * 2;
             ^
x86_64-unknown-linux-gnu-gcc-7.0.0-alpha20160501: internal compiler error:
Segmentation fault (program cc1)

#0  0x00000000008a2d24 in operand_equal_p(tree_node const*, tree_node const*,
unsigned int) ()
#1  0x00000000008a2be0 in operand_equal_p(tree_node const*, tree_node const*,
unsigned int) ()
#2  0x0000000000fbb046 in generic_simplify_PLUS_EXPR(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) [clone .isra.217] ()
#3  0x0000000000fdf25e in generic_simplify(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#4  0x00000000008b44bc in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#5  0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#6  0x00000000005a2d82 in fold_plusminus_mult_expr(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#7  0x00000000008b6184 in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#8  0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#9  0x00000000008cf9d0 in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#10 0x00000000008b9d69 in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#11 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#12 0x00000000008b6184 in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#13 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#14 0x00000000008cf9d0 in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#15 0x00000000008d022e in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#16 0x00000000008b9d69 in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#17 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()

<…>

#190618 0x00000000008b6f03 in fold_binary_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190619 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190620 0x00000000008d01e1 in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#190621 0x00000000008b9d69 in fold_binary_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190622 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190623 0x00000000008c0fa0 in fold_build2_initializer_loc(unsigned int,
tree_code, tree_node*, tree_node*, tree_node*) ()
#190624 0x00000000006ad649 in c_fully_fold_internal(tree_node*, bool, bool*,
bool*, bool) ()
#190625 0x00000000006b0a2c in c_fully_fold(tree_node*, bool, bool*) ()
#190626 0x000000000065a1ac in digest_init(unsigned int, tree_node*, tree_node*,
tree_node*, bool, bool, int) ()
#190627 0x000000000065c8d8 in store_init_value(unsigned int, tree_node*,
tree_node*, tree_node*) ()
#190628 0x00000000006321e9 in finish_decl(tree_node*, unsigned int, tree_node*,
tree_node*, tree_node*) ()
#190629 0x0000000000696fda in c_parser_declaration_or_fndef(c_parser*, bool,
bool, bool, bool, bool, tree_node**, vec<c_token, va_heap, vl_ptr>, tree_node*)
()
#190630 0x00000000006a3837 in c_parser_external_declaration(c_parser*) ()
#190631 0x00000000006a42b3 in c_parse_file() ()
#190632 0x0000000000707f73 in c_common_parse_file() ()
#190633 0x0000000000b9cd1e in compile_file() ()
#190634 0x00000000006173f3 in toplev::main(int, char**) ()
#190635 0x0000000000619637 in main ()

2. Changing "0 % 0" to "1 % 0" leads to a slightly different trace:

#0  0x0000000000e9e9f0 in wi::mul_internal(long*, long const*, unsigned int,
long const*, unsigned int, unsigned int, signop, bool*, bool) ()
#1  0x00000000008af916 in int_const_binop_1(tree_code, tree_node const*,
tree_node const*, int) ()
#2  0x00000000008c4a38 in const_binop(tree_code, tree_node*, tree_node*) ()
#3  0x00000000008cfb71 in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#4  0x00000000008b9d69 in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#5  0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#6  0x00000000008b6184 in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#7  0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#8  0x00000000008cf9d0 in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#9  0x00000000008d022e in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#10 0x00000000008b9d69 in fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*) ()
#11 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()

<…>

#190616 0x00000000008b6f03 in fold_binary_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190617 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190618 0x00000000008d01e1 in extract_muldiv(tree_node*, tree_node*, tree_code,
tree_node*, bool*) ()
#190619 0x00000000008b9d69 in fold_binary_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190620 0x00000000008c05cb in fold_build2_stat_loc(unsigned int, tree_code,
tree_node*, tree_node*, tree_node*) ()
#190621 0x00000000008c0fa0 in fold_build2_initializer_loc(unsigned int,
tree_code, tree_node*, tree_node*, tree_node*) ()
#190622 0x00000000006ad649 in c_fully_fold_internal(tree_node*, bool, bool*,
bool*, bool) ()
#190623 0x00000000006b0a2c in c_fully_fold(tree_node*, bool, bool*) ()
#190624 0x000000000065a1ac in digest_init(unsigned int, tree_node*, tree_node*,
tree_node*, bool, bool, int) ()
#190625 0x000000000065c8d8 in store_init_value(unsigned int, tree_node*,
tree_node*, tree_node*) ()
#190626 0x00000000006321e9 in finish_decl(tree_node*, unsigned int, tree_node*,
tree_node*, tree_node*) ()
#190627 0x0000000000696fda in c_parser_declaration_or_fndef(c_parser*, bool,
bool, bool, bool, bool, tree_node**, vec<c_token, va_heap, vl_ptr>, tree_node*)
()
#190628 0x00000000006a3837 in c_parser_external_declaration(c_parser*) ()
#190629 0x00000000006a42b3 in c_parse_file() ()
#190630 0x0000000000707f73 in c_common_parse_file() ()
#190631 0x0000000000b9cd1e in compile_file() ()
#190632 0x00000000006173f3 in toplev::main(int, char**) ()
#190633 0x0000000000619637 in main ()

Reply via email to