https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63664
Bug ID: 63664 Summary: ipa-icf pass fails with segfault Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: enkovich.gnu at gmail dot com Created attachment 33825 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33825&action=edit Reproducer There is a segfault in ipa-icf pass. >g++ test.cpp -O2 -c test.cpp:40:1: internal compiler error: Segmentation fault } ^ 0xe87262 crash_signal ../../gcc-pl-ref/gcc/toplev.c:349 0x17000ad ipa_icf_gimple::func_checker::compatible_types_p(tree_node*, tree_node*, bool, bool) ../../gcc-pl-ref/gcc/ipa-icf-gimple.c:172 0x170035c ipa_icf_gimple::func_checker::compare_operand(tree_node*, tree_node*) ../../gcc-pl-ref/gcc/ipa-icf-gimple.c:220 0x17020a2 ipa_icf_gimple::func_checker::compare_tree_ssa_label(tree_node*, tree_node*) ../../gcc-pl-ref/gcc/ipa-icf-gimple.c:737 0x1702187 ipa_icf_gimple::func_checker::compare_gimple_label(gimple_statement_base*, gimple_statement_base*) ../../gcc-pl-ref/gcc/ipa-icf-gimple.c:755 0x1701c29 ipa_icf_gimple::func_checker::compare_bb(ipa_icf_gimple::sem_bb*, ipa_icf_gimple::sem_bb*) ../../gcc-pl-ref/gcc/ipa-icf-gimple.c:604 0x16f463b ipa_icf::sem_function::equals_private(ipa_icf::sem_item*, hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&) ../../gcc-pl-ref/gcc/ipa-icf.c:455 0x16f3e74 ipa_icf::sem_function::equals(ipa_icf::sem_item*, hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&) ../../gcc-pl-ref/gcc/ipa-icf.c:355 0x16f8687 ipa_icf::sem_item_optimizer::subdivide_classes_by_equality(bool) ../../gcc-pl-ref/gcc/ipa-icf.c:1771 0x16f7d93 ipa_icf::sem_item_optimizer::execute() ../../gcc-pl-ref/gcc/ipa-icf.c:1590 0x16fa221 ipa_icf_driver ../../gcc-pl-ref/gcc/ipa-icf.c:2320 0x16fa736 ipa_icf::pass_ipa_icf::execute(function*) ../../gcc-pl-ref/gcc/ipa-icf.c:2368 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. >g++ -v Using built-in specs. COLLECT_GCC=../../../gcc-ref-build/bin/g++ COLLECT_LTO_WRAPPER=/export/users/ienkovic/gcc-ref-build/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-ref/configure --prefix=/export/users/ienkovic/gcc-ref-build --enable-languages=c,c++,fortran --disable-bootstrap Thread model: posix gcc version 5.0.0 20141024 (experimental) (GCC) The problem is that compared labels have null types and ipa_icf_gimple::func_checker::compatible_types_p doesn't check for null types. Possible patch: diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c index 1369b74..afc0eeb 100644 --- a/gcc/ipa-icf-gimple.c +++ b/gcc/ipa-icf-gimple.c @@ -169,6 +169,11 @@ bool func_checker::compatible_types_p (tree t1, tree t2, bool compare_polymorphic, bool first_argument) { + if (!t1 && !t2) + return true; + else if (!t1 || !t2) + return false; + if (TREE_CODE (t1) != TREE_CODE (t2)) return return_false_with_msg ("different tree types"); If we don't want labels to have null type then start_preparsed_function (decl.c:13607) has to be fixed.