https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94955
Bug ID: 94955 Summary: ICE in to_wide Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hubicka at gcc dot gnu.org Target Milestone: --- Created attachment 48454 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48454&action=edit proposed patch This was reported to me by Mark Williams (who also did the testcase and proposed patch) % g++ -std=gnu++17 bug.ii -S -o bug.s bug.ii: In function �void d()�: bug.ii:6:32: internal compiler error: in sign_mask, at wide-int.h:855 6 | void d() { short e = e >> b::c(); } | ^ 0xa56be2 generic_wide_int<wide_int_ref_storage<false, false> >::sign_mask() const /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/wide-int.h:855 0xa56be2 bool wi::neg_p<generic_wide_int<wide_int_ref_storage<false, false> > >(generic_wide_int<wide_int_ref_storage<false, false> > const&, signop) /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/wide-int.h:1836 0xa56be2 tree_int_cst_sgn(tree_node const*) /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/tree.c:7386 0x1065e85 cp_build_binary_op(op_location_t const&, tree_code, tree_node*, tree_node*, int) /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/typeck.c:5613 0xfa9629 build_new_op_1 /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/call.c:6501 0xfa931d build_new_op(op_location_t const&, tree_code, int, tree_node*, tree_node*, tree_node*, tree_node**, int) /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/call.c:6547 0x106267f build_x_binary_op(op_location_t const&, tree_code, tree_node*, tree_code, tree_node*, tree_code, tree_node**, int) /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/typeck.c:4248 0x10162f0 cp_parser_binary_expression /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:9684 0x10157a4 cp_parser_assignment_expression /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:9824 0x1015380 cp_parser_constant_expression /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:10118 0x1015380 cp_parser_initializer_clause /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:23148 0x1015380 cp_parser_initializer /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:23086 0x1008ab0 cp_parser_init_declarator /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:20780 0x1006144 cp_parser_simple_declaration /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:13689 0x101df42 cp_parser_declaration_statement /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:13121 0x101a67c cp_parser_statement /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:11434 0x101a38a cp_parser_statement_seq_opt /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:11800 0x101a38a cp_parser_compound_statement /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:11750 0x101a0f9 cp_parser_function_body /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:22992 0x101a0f9 cp_parser_ctor_initializer_opt_and_function_body /home/engshare/third-party2/gcc/9.x/src/gcc-10.x/gcc/cp/parser.c:23043 The problem was that it had previously used fold_for_warn to find an INTEGER_CST, and assumed the cp_fold_rvalue would too. But fold_for_warn handles some edge cases that cp_fold_rvalue does not, and in this case we end up with a NOP_EXPR instead of the INTEGER_CST