From: Martin Liska Date: Fri, 7 Nov 2014 12:32:30 +0000 (+0100) Subject: re PR tree-optimization/63595 (Segmentation faults inside kernel) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8c14c817f30b966f509636b96d4e5586261a258b;p=gcc.git re PR tree-optimization/63595 (Segmentation faults inside kernel) PR ipa/63595 * g++.dg/ipa/pr63595.C: New test. * cgraphunit.c (cgraph_node::expand_thunk): DECL_BY_REFERENCE is correctly handled for thunks created by IPA ICF. From-SVN: r217218 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7535286f915..6fc91b5d66d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-11-07 Martin Liska + + PR ipa/63595 + * cgraphunit.c (cgraph_node::expand_thunk): DECL_BY_REFERENCE + is correctly handled for thunks created by IPA ICF. + 2014-11-07 Jiong Wang 2014-11-07 Richard Biener diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index d2e88474594..75d414024a7 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -1555,7 +1555,15 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk) if (!VOID_TYPE_P (restype)) { if (DECL_BY_REFERENCE (resdecl)) - restmp = gimple_fold_indirect_ref (resdecl); + { + restmp = gimple_fold_indirect_ref (resdecl); + if (!restmp) + restmp = build2 (MEM_REF, + TREE_TYPE (TREE_TYPE (DECL_RESULT (alias))), + resdecl, + build_int_cst (TREE_TYPE + (DECL_RESULT (alias)), 0)); + } else if (!is_gimple_reg_type (restype)) { restmp = resdecl; @@ -1651,7 +1659,11 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk) gimple_call_set_tail (call, true); /* Build return value. */ - ret = gimple_build_return (restmp); + if (!DECL_BY_REFERENCE (resdecl)) + ret = gimple_build_return (restmp); + else + ret = gimple_build_return (resdecl); + gsi_insert_after (&bsi, ret, GSI_NEW_STMT); } else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5e1581439b8..8575ba3e180 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-11-07 Martin Liska + + PR ipa/63595 + * g++.dg/ipa/pr63595.C: New test. + 2014-11-07 Richard Biener PR middle-end/63770 diff --git a/gcc/testsuite/g++.dg/ipa/pr63595.C b/gcc/testsuite/g++.dg/ipa/pr63595.C new file mode 100644 index 00000000000..30e930345b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr63595.C @@ -0,0 +1,80 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-icf-details" } */ + +template class B; +template class TriaObjectAccessor; +template class A; +template class TriaDimensionInfo { +public: + typedef A<3, TriaObjectAccessor<2, 3> > raw_quad_iterator; + typedef A<3, B<3> > raw_hex_iterator; + typedef raw_hex_iterator raw_cell_iterator; +}; +template class Triangulation : public TriaDimensionInfo<1> { + public: + typedef typename TriaDimensionInfo::raw_quad_iterator raw_quad_iterator; + TriaDimensionInfo::raw_cell_iterator end() const; + raw_quad_iterator end_quad() const { + return raw_quad_iterator(const_cast(this), 0, 0); + } +}; +template class TriaAccessor { +public: + typedef void AccessorData; + TriaAccessor(const Triangulation * = 0); + Triangulation<1> *tria; + + int a, b, c; +}; +template class TriaObjectAccessor<2, dim> : public TriaAccessor { +public: + typedef typename TriaAccessor::AccessorData AccessorData; + TriaObjectAccessor(const Triangulation * = 0); +}; +template class TriaObjectAccessor<3, dim> : public TriaAccessor { +public: + typedef typename TriaAccessor::AccessorData AccessorData; + TriaObjectAccessor(const Triangulation * = 0); +}; +template class B : public TriaObjectAccessor { +public: + typedef typename TriaObjectAccessor::AccessorData AccessorData; + B(const Triangulation * = 0); +}; +template class A { +public: + A(const A &); + A(const Triangulation *, int, int); + Accessor accessor; +}; +template class Triangulation<3>; +template +A::A(const Triangulation *, int, int) {} +template +TriaAccessor::TriaAccessor(const Triangulation *) + : tria(), a(-1), b(-2), c(-3) {} +template +TriaObjectAccessor<2, dim>::TriaObjectAccessor(const Triangulation *) {} +template +TriaObjectAccessor<3, dim>::TriaObjectAccessor(const Triangulation *) {} +template B::B(const Triangulation *) {} +template <> +TriaDimensionInfo<3>::raw_cell_iterator Triangulation<3>::end() const { + return raw_hex_iterator(const_cast(this), 0, 0); +} + +#pragma GCC optimize ("-O0") +int main() +{ + Triangulation <3> t; + Triangulation<3>::raw_quad_iterator i1 = t.end_quad(); + TriaDimensionInfo<3>::raw_cell_iterator i2 = t.end(); + + if(i2.accessor.c != -3) + return 1; + + return 0; +} + +/* { dg-final { scan-ipa-dump "Equal symbols: 1" "icf" } } */ +/* { dg-final { cleanup-ipa-dump "icf" } } */