From patchwork Thu Mar 2 02:29:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xionghu Luo X-Patchwork-Id: 63174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3997546wrd; Wed, 1 Mar 2023 18:31:09 -0800 (PST) X-Google-Smtp-Source: AK7set8pRZfovDyWO9dnfUkuSceNZwjtTAw6T8pCZVKFn04Q6vS6vhu/QVSAO52ABgGQHwnFF2MJ X-Received: by 2002:a05:6402:4e:b0:4aa:a4f0:2c17 with SMTP id f14-20020a056402004e00b004aaa4f02c17mr10364916edu.4.1677724269016; Wed, 01 Mar 2023 18:31:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677724269; cv=none; d=google.com; s=arc-20160816; b=gJTAyBSuIA7MAlj1r8U6SYzrM4TNFe/Yq+6B4XLT6zb5TnV+NJ+54/hY+cz/eUPkKy OGFbbfnBbX1jv0TLRT5LFTcbkCOt09KZr+g8JO9PEKuJ9fadunj8ZTa8k4yz58HiHVFK IPIHcTgWLK4aJ6Nu6D1AmS0hsKx6EQys6d4Rin+F84lVDlr/sIWDo7FAMjR+5a6mxdSW lAzKvlh1V/W57I0BfTZI+6v00dF+BzsV+q6uBG+eW0CDKm49dT+wiUvxt4MZiPlZDHW8 VuUsG2x9TSS8FG8F5NAyOUPE04b2ptbrFwQ7ofauRlfstml2Fyl1ftBSXARii1Kgolrl +i5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=yYEoj+46rNydxf3gkg+CcaEErEQXYdai8kiEXBCmwP4=; b=zhEjnAkFIoIwl5YxLdhkPlX+DzSfYHD2iYpOsSS0BRqc+AEjbQNmmPsnflDOSk/DKZ E98BXF6Kv5ezNct348wb7HVQqLZikJOoK+3R6T41b9MW1R2Qjsvign3W3r8mlew8b1ZU Zghr02v9EJWPHie7iK4pVd7MfFZdVJ2STg2thuXJGWcA97Osj1PWUF6LRpoLUQsXxWSl Uyxwu4vayUy26lSgbvEFnY9ELy3O7riMD+0julhYL8LqhYacqGYdvc+QmvaC9rFMG/q+ Iq0NgnHcjdV0SUrDNkpAqUMB4lpxgHPIfHyB6VqevzYqTJjfWPa+vV9KDUPMZlX+rRTL ht8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uhV4c2wR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q10-20020aa7da8a000000b004af6f21fa99si14256253eds.264.2023.03.01.18.31.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 18:31:08 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uhV4c2wR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25A32385B50C for ; Thu, 2 Mar 2023 02:31:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25A32385B50C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677724260; bh=yYEoj+46rNydxf3gkg+CcaEErEQXYdai8kiEXBCmwP4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uhV4c2wRpgZS+sejL4R3lVJrudJzEA8y1er0cLQ3Qhg4TMZbkWOvenHUizw7A6F0c P0lesxZVsmr/F9T7NgzOYHSf0vi24uUtLsN8ptQdO+bKxxSYUaWmmK0stDqsopzMJV au/3bv3jVlfZdd3cYzUBNFsORq+/MhKZ2FLTzsqw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from VM-122-127-centos.localdomain (unknown [43.132.141.3]) by sourceware.org (Postfix) with ESMTPS id 1CD243858D33; Thu, 2 Mar 2023 02:30:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CD243858D33 Received: by VM-122-127-centos.localdomain (Postfix, from userid 1009) id B38C540FD0; Thu, 2 Mar 2023 10:30:11 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: luoxhu@gcc.gnu.org, rguenther@suse.de, hubicka@ucw.cz, Xionghu Luo Subject: [PATCH 2/2] gcov: Fix incorrect gimple line LOCATION [PR97923] Date: Thu, 2 Mar 2023 10:29:21 +0800 Message-Id: <20230302022921.4055291-2-xionghuluo@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230302022921.4055291-1-xionghuluo@tencent.com> References: <20230302022921.4055291-1-xionghuluo@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RCVD_IN_PBL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Xionghu Luo via Gcc-patches From: Xionghu Luo Reply-To: Xionghu Luo Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759221403045726808?= X-GMAIL-MSGID: =?utf-8?q?1759221403045726808?= For case like belowi test.c: 1:int foo(char c) 2:{ 3: return ((c >= 'A' && c <= 'Z') 4: || (c >= 'a' && c <= 'z') 5: || (c >= '0' && c <='0'));} the generated line number is incorrect for condition c>='A' of block 2: Thus correct the condition op0 location. gcno diff before and with this patch: test.gcno: 575: block 11: 1:0001(tree) test.gcno: 583: 01450000: 35:LINES -test.gcno: 595: block 2:`test.c':1, 5 +test.gcno: 595: block 2:`test.c':1, 3 test.gcno: 626: 01450000: 31:LINES test.gcno: 638: block 3:`test.c':3 test.gcno: 665: 01450000: 31:LINES test.gcno: 677: block 4:`test.c':4 test.gcno: 704: 01450000: 31:LINES test.gcno: 716: block 5:`test.c':4 test.gcno: 743: 01450000: 31:LINES test.gcno: 755: block 6:`test.c':5 Also save line id in line vector for gcov debug use. Regression tested pass on x86_64-linux-gnu and aarch64-linux-gnu, OK for master? gcc/ChangeLog: PR gcov/97923 * gcov.cc (line_info::line_info): Init id. (solve_flow_graph): Fix typo. (add_line_counts): Set line->id. * gimplify.cc (shortcut_cond_r): Correct cond expr op0 location. gcc/testsuite/ChangeLog: PR gcov/97923 * gcc.misc-tests/gcov-pr97923.c: New test. Signed-off-by: Xionghu Luo --- gcc/gcov.cc | 9 ++++++--- gcc/gimplify.cc | 6 ++++-- gcc/testsuite/gcc.misc-tests/gcov-pr97923.c | 13 +++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-pr97923.c diff --git a/gcc/gcov.cc b/gcc/gcov.cc index 2ec7248cc0e..77ca94c71c4 100644 --- a/gcc/gcov.cc +++ b/gcc/gcov.cc @@ -205,6 +205,8 @@ public: /* Execution count. */ gcov_type count; + unsigned id; + /* Branches from blocks that end on this line. */ vector branches; @@ -216,8 +218,8 @@ public: unsigned has_unexecuted_block : 1; }; -line_info::line_info (): count (0), branches (), blocks (), exists (false), - unexceptional (0), has_unexecuted_block (0) +line_info::line_info (): count (0), id (0), branches (), blocks (), + exists (false), unexceptional (0), has_unexecuted_block (0) { } @@ -2370,7 +2372,7 @@ solve_flow_graph (function_info *fn) /* If the graph has been correctly solved, every block will have a valid count. */ - for (unsigned i = 0; ix < fn->blocks.size (); i++) + for (unsigned i = 0; i < fn->blocks.size (); i++) if (!fn->blocks[i].count_valid) { fnotice (stderr, "%s:graph is unsolvable for '%s'\n", @@ -2730,6 +2732,7 @@ add_line_counts (coverage_info *coverage, function_info *fn) } line->count += block->count; } + line->id = ln; } has_any_line = true; diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index ade6e335da7..341a27b033e 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -3915,7 +3915,8 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p, false_label_p = &local_label; /* Keep the original source location on the first 'if'. */ - t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p, locus); + tree op0 = TREE_OPERAND (pred, 0); + t = shortcut_cond_r (op0, NULL, false_label_p, EXPR_LOCATION (op0)); append_to_statement_list (t, &expr); /* Set the source location of the && on the second 'if'. */ @@ -3938,7 +3939,8 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p, true_label_p = &local_label; /* Keep the original source location on the first 'if'. */ - t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, locus); + tree op0 = TREE_OPERAND (pred, 0); + t = shortcut_cond_r (op0, true_label_p, NULL, EXPR_LOCATION (op0)); append_to_statement_list (t, &expr); /* Set the source location of the || on the second 'if'. */ diff --git a/gcc/testsuite/gcc.misc-tests/gcov-pr97923.c b/gcc/testsuite/gcc.misc-tests/gcov-pr97923.c new file mode 100644 index 00000000000..ad4f7d40817 --- /dev/null +++ b/gcc/testsuite/gcc.misc-tests/gcov-pr97923.c @@ -0,0 +1,13 @@ +/* { dg-options "-fprofile-arcs -ftest-coverage" } */ +/* { dg-do run { target native } } */ + +int foo(int c) +{ + return ((c >= 'A' && c <= 'Z') /* count(1*) */ + || (c >= 'a' && c <= 'z') /* count(1*) */ + || (c >= '0' && c <= '0')); /* count(1*) */ +} + +int main() { foo(0); } + +/* { dg-final { run-gcov gcov-pr97923-1.c } } */