Hi! I've backported this fix from the trunk to 4.8 branch and for the trunk committed the new testcase.
2013-12-20 Jakub Jelinek <ja...@redhat.com> PR c++/59255 Backported from mainline 2013-08-19 Dehao Chen <de...@google.com> * value-prof.c (gimple_ic): Fix the bug of adding EH edge. * g++.dg/tree-prof/pr59255.C: New test. --- gcc/value-prof.c.jj 2013-03-16 08:14:33.000000000 +0100 +++ gcc/value-prof.c 2013-12-20 17:19:44.821152952 +0100 @@ -1270,8 +1270,7 @@ gimple_ic (gimple icall_stmt, struct cgr /* Build an EH edge for the direct call if necessary. */ lp_nr = lookup_stmt_eh_lp (icall_stmt); - if (lp_nr != 0 - && stmt_could_throw_p (dcall_stmt)) + if (lp_nr > 0 && stmt_could_throw_p (dcall_stmt)) { edge e_eh, e; edge_iterator ei; --- gcc/testsuite/g++.dg/tree-prof/pr59255.C.jj 2013-12-20 17:17:17.271928149 +0100 +++ gcc/testsuite/g++.dg/tree-prof/pr59255.C 2013-12-20 17:18:48.748446891 +0100 @@ -0,0 +1,29 @@ +// PR c++/59255 +// { dg-options "-O2 -std=c++11" } + +struct S +{ + __attribute__((noinline, noclone)) ~S () noexcept (true) + { + if (fn) + fn (1); + } + void (*fn) (int); +}; + +__attribute__((noinline, noclone)) void +foo (int x) +{ + if (x != 1) + throw 1; +} + +int +main () +{ + for (int i = 0; i < 100; i++) + { + S s; + s.fn = foo; + } +} Jakub