From patchwork Fri Mar 10 20:24:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 737569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vfzKD49NBz9s7n for ; Sat, 11 Mar 2017 07:25:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ibETfnFf"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=d5tlyz9OXlL+HZ7j3nr7PetryMTLBrtN2LrXb/NX/B7JEwPluC bumfEvi0HvT5xD/EGCugGt1cL0dwqwA/5obxzxHbonhAe3XncLXa8gr5D/c1hTsL MTjJWrA+j6tLRiy2pfQcMja0oNoqCS/B5ROUDKQxL2slQSwDrrhzHvvKo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=a/abXwylCx9CZhAd+Lv10Y5iubg=; b=ibETfnFfl1HOThNRXqZ3 Ki5rdESc0O6bNCvHxq1Je2sruPTdRUS9N1WpU94V+NT30qD6oPbmI4Fw7TE1jiLe tMAZQXrV1xnPCYJ5/p6o8uyynE1qSbUDykrc12hgfqZJDH80Ct89AUCU9fzfUZ3s XYGAa8CpTJEZOwfyDMAwohU= Received: (qmail 5326 invoked by alias); 10 Mar 2017 20:25:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 5298 invoked by uid 89); 10 Mar 2017 20:25:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=14498, uut, sum X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Mar 2017 20:25:01 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2B884AB1D; Fri, 10 Mar 2017 20:25:00 +0000 (UTC) To: GCC Patches Cc: Nathan Sidwell , Jan Hubicka , Richard Biener From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] gcov: Mark BBs that do not correspond to a line in source code (PR gcov-profile/79891). Message-ID: <113a3fb2-817c-ff7c-e57a-d5ee1656d4b9@suse.cz> Date: Fri, 10 Mar 2017 21:24:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 X-IsSubscribed: yes Hello. As briefly discussed in the PR, there are BB that do not correspond to a real line in source code. profile.c emits locations for all BBs that have a gimple statement belonging to a line. I hope these should be marked in gcov utility and not added in --all-block mode to counts of lines. Patch survives make check RUNTESTFLAGS="gcov.exp". Thanks for review and feedback. Martin From cc8738a287d5b0b98d61013ee065c96ed3e3cefa Mon Sep 17 00:00:00 2001 From: marxin Date: Fri, 10 Mar 2017 20:01:06 +0100 Subject: [PATCH] gcov: Mark BBs that do not correspond to a line in source code (PR gcov-profile/79891). gcc/ChangeLog: 2017-03-10 Martin Liska PR gcov-profile/79891 * gcov.c (read_graph_file): Mark BB that correspond to a real line in source code. (accumulate_line_counts): Do not sum these BBs. gcc/testsuite/ChangeLog: 2017-03-10 Martin Liska PR gcov-profile/79891 * gcc.misc-tests/gcov-17.c: New test. --- gcc/gcov.c | 12 +++++++++--- gcc/testsuite/gcc.misc-tests/gcov-17.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-17.c diff --git a/gcc/gcov.c b/gcc/gcov.c index 4b5043c2f9f..10209b4c560 100644 --- a/gcc/gcov.c +++ b/gcc/gcov.c @@ -141,6 +141,7 @@ typedef struct block_info /* Block is a landing pad for longjmp or throw. */ unsigned is_nonlocal_return : 1; + unsigned has_line_assigned: 1; union { @@ -1448,6 +1449,8 @@ read_graph_file (void) fn->num_blocks = num_blocks; fn->blocks = XCNEWVEC (block_t, fn->num_blocks); + fn->blocks[ENTRY_BLOCK].has_line_assigned = 1; + fn->blocks[EXIT_BLOCK].has_line_assigned = 1; for (ix = 0; ix != num_blocks; ix++) fn->blocks[ix].flags = gcov_read_unsigned (); } @@ -1529,6 +1532,7 @@ read_graph_file (void) else if (fn && tag == GCOV_TAG_LINES) { unsigned blockno = gcov_read_unsigned (); + fn->blocks[blockno].has_line_assigned = 1; unsigned *line_nos = XCNEWVEC (unsigned, length - 1); if (blockno >= fn->num_blocks || fn->blocks[blockno].u.line.encoding) @@ -2458,9 +2462,11 @@ accumulate_line_counts (source_t *src) /* Cycle detection. */ for (block = line->u.blocks; block; block = block->chain) { - for (arc_t *arc = block->pred; arc; arc = arc->pred_next) - if (!line->has_block (arc->src)) - count += arc->count; + if (block->has_line_assigned) + for (arc_t *arc = block->pred; arc; arc = arc->pred_next) + if (!line->has_block (arc->src)) + count += arc->count; + for (arc_t *arc = block->succ; arc; arc = arc->succ_next) arc->cs_count = arc->count; } diff --git a/gcc/testsuite/gcc.misc-tests/gcov-17.c b/gcc/testsuite/gcc.misc-tests/gcov-17.c new file mode 100644 index 00000000000..1cff708be9b --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/gcov-17.c @@ -0,0 +1,30 @@ +/* Test gcov block mode. */ + +/* { dg-options "-fprofile-arcs -ftest-coverage" } */ +/* { dg-do run { target native } } */ + +unsigned int +UuT (void) +{ + unsigned int true_var = 1; + unsigned int false_var = 0; + unsigned int ret = 0; + + if (true_var) /* count(1) */ + { + if (false_var) /* count(1) */ + ret = 111; /* count(#####) */ + } + else + ret = 999; /* count(#####) */ + return ret; +} + +int +main (int argc, char **argv) +{ + UuT (); + return 0; +} + +/* { dg-final { run-gcov { -a gcov-17.c } } } */ -- 2.11.1