From 3b445b24ddadf8a95bf9ee80242d9eb10521ab7e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 18 Feb 2015 23:02:43 +0100 Subject: [PATCH] re PR gcov-profile/64634 (gcov reports catch(...) as not executed) PR gcov-profile/64634 * tree-eh.c (frob_into_branch_around): Fix up typos in function comment. (lower_catch): Put eh_seq resulting from EH lowering of the cleanup sequence after the cleanup rather than before it. * g++.dg/gcov/gcov-15.C: New test. From-SVN: r220801 --- gcc/ChangeLog | 9 +++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/gcov/gcov-15.C | 26 ++++++++++++++++++++++++++ gcc/tree-eh.c | 16 +++++++++++++--- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gcov/gcov-15.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4919a5f2ddb..07cadb36aed 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2015-02-18 Jakub Jelinek + + PR gcov-profile/64634 + * tree-eh.c (frob_into_branch_around): Fix up typos + in function comment. + (lower_catch): Put eh_seq resulting from EH lowering of + the cleanup sequence after the cleanup rather than before + it. + 2015-02-18 Tom de Vries * common.opt (fstdarg-opt): New option. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ff3697e8e02..1ca711d93b7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-02-18 Jakub Jelinek + + PR gcov-profile/64634 + * g++.dg/gcov/gcov-15.C: New test. + 2015-02-18 Tom de Vries * gfortran.dg/coarray_35a.f90: Add missing cleanup-modules. diff --git a/gcc/testsuite/g++.dg/gcov/gcov-15.C b/gcc/testsuite/g++.dg/gcov/gcov-15.C new file mode 100644 index 00000000000..fcd16b00b1c --- /dev/null +++ b/gcc/testsuite/g++.dg/gcov/gcov-15.C @@ -0,0 +1,26 @@ +// PR gcov-profile/64634 +// { dg-options "-fprofile-arcs -ftest-coverage" } +// { dg-do run { target native } } + +void catchEx () // count(1) +{ + __builtin_exit (0); // count(1) + try + {} + catch (int) + {} +} + +int main () // count(1) +{ + try + { + throw 5; // count(1) + } + catch (...) // count(1) + { + catchEx (); // count(1) + } +} + +// { dg-final { run-gcov gcov-15.C } } diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index 3c45f37efbf..a111e9d93ae 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -884,10 +884,10 @@ eh_region_may_contain_throw (eh_region r) /* We want to transform try { body; } catch { stuff; } to - normal_seqence: + normal_sequence: body; over: - eh_seqence: + eh_sequence: landing_pad: stuff; goto over; @@ -1813,6 +1813,12 @@ lower_catch (struct leh_state *state, gtry *tp) this_state.cur_region = state->cur_region; this_state.ehp_region = try_region; + /* Add eh_seq from lowering EH in the cleanup sequence after the cleanup + itself, so that e.g. for coverage purposes the nested cleanups don't + appear before the cleanup body. See PR64634 for details. */ + gimple_seq old_eh_seq = eh_seq; + eh_seq = NULL; + out_label = NULL; cleanup = gimple_try_cleanup (tp); for (gsi = gsi_start (cleanup); @@ -1849,7 +1855,11 @@ lower_catch (struct leh_state *state, gtry *tp) gimple_try_set_cleanup (tp, new_seq); - return frob_into_branch_around (tp, try_region, out_label); + gimple_seq new_eh_seq = eh_seq; + eh_seq = old_eh_seq; + gimple_seq ret_seq = frob_into_branch_around (tp, try_region, out_label); + gimple_seq_add_seq (&eh_seq, new_eh_seq); + return ret_seq; } /* A subroutine of lower_eh_constructs_1. Lower a GIMPLE_TRY with a -- 2.30.2