From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 03E023858C50; Wed, 1 Mar 2023 02:10:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03E023858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677636659; bh=UqDBuKj031wDA7fylPoU6gWR4adW1kGJRoFZUEsMjBQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cq7osgqAPbL+dUCfCvJNEpq0gltJQ/VzhsnaULiEpLISHrixA1hn5BKYsKZ3UDQe0 cH2wpFhCzpqYdlGooXB4D+DBB0BJZDBx3OYj5LCAYn0SuJjwAHH0J/PeaCJr7izeXC 1wsaM+CHJYZYbq9TgFvJC9HAKWr9A6usY2Nc987g= From: "yinyuefengyi at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug gcov-profile/97923] [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines Date: Wed, 01 Mar 2023 02:10:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: gcov-profile X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yinyuefengyi at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97923 --- Comment #6 from Xionghu Luo (luoxhu at gcc dot gnu.org) --- below changes could fix the incorrect location diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 96845154a92..2dc8608dedf 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 =3D &local_label; /* Keep the original source location on the first 'if'. */ - t =3D shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p, locus); + tree op0 =3D TREE_OPERAND (pred, 0); + t =3D 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 =3D &local_label; /* Keep the original source location on the first 'if'. */ - t =3D shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, l= ocus); + tree op0 =3D TREE_OPERAND (pred, 0); + t =3D shortcut_cond_r (op0, true_label_p, NULL, EXPR_LOCATION (op0)); append_to_statement_list (t, &expr); That produce expected block line info and coverage: gcov-dump test.gcno -lp: test.gcno: 583: 01450000: 35:LINES test.gcno: 595: block 2:`test.c':1, 3 <=3D change from = 5 to 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 test.gcno: 782: 01450000: 31:LINES test.gcno: 794: block 7:`test.c':5 test.gcno: 821: 01450000: 31:LINES test.gcno: 833: block 8:`test.c':5 test.gcno: 860: 01450000: 31:LINES test.gcno: 872: block 9:`test.c':5 test.gcno: 899: 01450000: 31:LINES test.gcno: 911: block 10:`test.c':5 test.gcno: 938: 01450000: 31:LINES test.gcno: 950: block 11:`test.c':5 cat test.c.gcov: -: 0:Source:test.c -: 0:Graph:test.gcno -: 0:Data:test.gcda -: 0:Runs:1 1: 1:int foo(char c) -: 2:{ 1*: 3: return ((c >=3D 'A' && c <=3D 'Z') 1*: 4: || (c >=3D 'a' && c <=3D 'z') 1*: 5: || (c >=3D '0' && c <=3D '0')); -: 6:} -: 7: 1: 8:int main() { return foo('0'); }=