From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 5E7613858C3A; Mon, 24 Apr 2023 10:19:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E7613858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682331543; bh=4ZV+7Z2uCL+iF4qPlHZOWw93R+2HrTw/Udj55h7h4hs=; h=From:To:Subject:Date:From; b=YUyQj0AZsK6vsyfw9XMzXh39T5yRolP5dAabFnDLYN0eC3b/INsjGhnbXpoR4IYWs 5zJezbR05brQLXbPflWWSch4OoPsYVcYBD0ghFLRHU/CoPB02m0ZULAeR0Eco1JfVq 9ObLohoQ0POdzMxfZdu2X0DEI+NX6iguMKmICmu4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/gcov-json-add-calls)] Refactor how are blocks, lines and branches printed. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/gcov-json-add-calls X-Git-Oldrev: f7faa9d00d81695bc13ac13fd8f9fe12a5ca4625 X-Git-Newrev: 69685de0593ef7431108e1b06502b8a202a3a1a0 Message-Id: <20230424101903.5E7613858C3A@sourceware.org> Date: Mon, 24 Apr 2023 10:19:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:69685de0593ef7431108e1b06502b8a202a3a1a0 commit 69685de0593ef7431108e1b06502b8a202a3a1a0 Author: Martin Liska Date: Mon Apr 24 12:17:57 2023 +0200 Refactor how are blocks, lines and branches printed. Diff: --- gcc/gcov.cc | 50 ++++++++++++++++------------------------------ gcc/testsuite/lib/gcov.exp | 8 ++++---- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/gcc/gcov.cc b/gcc/gcov.cc index fa03f32a8e9..de3ada676d1 100644 --- a/gcc/gcov.cc +++ b/gcc/gcov.cc @@ -663,7 +663,6 @@ static void file_summary (const coverage_info *); static const char *format_gcov (gcov_type, gcov_type, int); static void accumulate_line_counts (source_info *); static void output_gcov_file (const char *, source_info *); -static int output_branch_count (FILE *, int, const arc_info *); static void output_lines (FILE *, const source_info *); static string make_gcov_file_name (const char *, const char *); static char *mangle_name (const char *); @@ -2891,32 +2890,29 @@ accumulate_line_counts (source_info *src) } } -/* Output information about ARC number IX. Returns nonzero if - anything is output. */ +/* Output information about ARC. */ -static int -output_branch_count (FILE *gcov_file, int ix, const arc_info *arc) +static void +output_branch_count (FILE *gcov_file, const arc_info *arc) { if (arc->is_call_non_return) { if (arc->src->count) - { - fnotice (gcov_file, "call %2d returned %s\n", ix, - format_gcov (arc->src->count - arc->count, - arc->src->count, -flag_counts)); - } + fnotice (gcov_file, "call returned %s\n", + format_gcov (arc->src->count - arc->count, + arc->src->count, -flag_counts)); else - fnotice (gcov_file, "call %2d never executed\n", ix); + fnotice (gcov_file, "call never executed\n"); } else if (!arc->is_unconditional) { if (arc->src->count) - fnotice (gcov_file, "branch %2d taken %s%s", ix, + fnotice (gcov_file, "branch taken %s%s", format_gcov (arc->count, arc->src->count, -flag_counts), arc->fall_through ? " (fallthrough)" : arc->is_throw ? " (throw)" : ""); else - fnotice (gcov_file, "branch %2d never executed%s", ix, + fnotice (gcov_file, "branch never executed%s", (arc->fall_through ? " (fallthrough)" : arc->is_throw ? " (throw)" : "")); @@ -2928,14 +2924,11 @@ output_branch_count (FILE *gcov_file, int ix, const arc_info *arc) else if (flag_unconditional && !arc->dst->is_call_return) { if (arc->src->count) - fnotice (gcov_file, "unconditional %2d taken %s\n", ix, + fnotice (gcov_file, "unconditional taken %s\n", format_gcov (arc->count, arc->src->count, -flag_counts)); else - fnotice (gcov_file, "unconditional %2d never executed\n", ix); + fnotice (gcov_file, "unconditional never executed\n"); } - else - return 0; - return 1; } static const char * @@ -3082,10 +3075,6 @@ output_line_details (FILE *f, const line_info *line, unsigned line_num) { if (flag_all_blocks) { - arc_info *arc; - int ix, jx; - - ix = jx = 0; for (vector::const_iterator it = line->blocks.begin (); it != line->blocks.end (); it++) { @@ -3095,25 +3084,20 @@ output_line_details (FILE *f, const line_info *line, unsigned line_num) (*it)->exceptional, false, (*it)->count, line_num, "%%%%%", "$$$$$", 0); - fprintf (f, "-block %2d", ix++); + fprintf (f, "-block %d", (*it)->id); if (flag_verbose) fprintf (f, " (BB %u)", (*it)->id); fprintf (f, "\n"); } if (flag_branches) - for (arc = (*it)->succ; arc; arc = arc->succ_next) - jx += output_branch_count (f, jx, arc); + for (arc_info *arc = (*it)->succ; arc; arc = arc->succ_next) + output_branch_count (f, arc); } } else if (flag_branches) - { - int ix; - - ix = 0; - for (vector::const_iterator it = line->branches.begin (); - it != line->branches.end (); it++) - ix += output_branch_count (f, ix, (*it)); - } + for (vector::const_iterator it = line->branches.begin (); + it != line->branches.end (); it++) + output_branch_count (f, *it); } /* Output detail statistics about function FN to file F. */ diff --git a/gcc/testsuite/lib/gcov.exp b/gcc/testsuite/lib/gcov.exp index e5e94fa5a76..7b5819821f0 100644 --- a/gcc/testsuite/lib/gcov.exp +++ b/gcc/testsuite/lib/gcov.exp @@ -133,12 +133,12 @@ proc verify-branches { testname testcase file } { set shouldbe [lreplace $shouldbe $i $i [expr 100 - $num]] } } - } elseif [regexp "branch +\[0-9\]+ taken (-\[0-9\]+)%" "$line" \ + } elseif [regexp "branch +taken (-\[0-9\]+)%" "$line" \ all taken] { # Percentages should never be negative. fail "$testname line $n: negative percentage: $taken" incr failed - } elseif [regexp "branch +\[0-9\]+ taken (\[0-9\]+)%" "$line" \ + } elseif [regexp "branch +taken (\[0-9\]+)%" "$line" \ all taken] { #send_user "$n: taken = $taken\n" # Percentages should never be greater than 100. @@ -213,12 +213,12 @@ proc verify-calls { testname testcase file } { } # Record the percentages to check for. set shouldbe $new_shouldbe - } elseif [regexp "call +\[0-9\]+ returned (-\[0-9\]+)%" "$line" \ + } elseif [regexp "call +returned (-\[0-9\]+)%" "$line" \ all returns] { # Percentages should never be negative. fail "$testname line $n: negative percentage: $returns" incr failed - } elseif [regexp "call +\[0-9\]+ returned (\[0-9\]+)%" "$line" \ + } elseif [regexp "call +returned (\[0-9\]+)%" "$line" \ all returns] { # For branches we check that percentages are not greater than # 100 but call return percentages can be, as for setjmp(), so