From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 954323858D33; Thu, 2 Mar 2023 08:42:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 954323858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x22d.google.com with SMTP id b13so16819282ljf.6; Thu, 02 Mar 2023 00:42:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677746532; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=oCqMQD4MM/sQmoaPjI+3s12xc9ZEQawcHKkDNvUq7ys=; b=qu0W3sgf8rmaJpOKf/3FNsbDRT2bSq3KOLoI0ATOsNIa5IXToyjeLWpZy2dHq0YytY ebKTidJ18n0RXdevmx1SSy2a/rElWjiS6YsMjvoqPEZWrWFq8XqjcWDayuCH38UZPPrs rnmvxf3yuR8nYRQne60U2FoV+a50GYzk0LtKiSjooGfRb8oJDo0eJrIkY4O/1YAKWlRf i4BfXjm2CSNeJevtDkETsRacYJK24Zwu5UDvf+DCRuNWsep5oZxCpm0is5T1vE10cxRb h7pB8hGd03NfzqEV48OI36qr9+PaQYIg2PJYruXe+KFp8PcTovo8BUbQeN3t66ogenL7 0Bvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677746532; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oCqMQD4MM/sQmoaPjI+3s12xc9ZEQawcHKkDNvUq7ys=; b=RIGV40Uh0x5xqyao6lScUZypIFZxAQTkowin3Sl1/oiRYT5giUILp67hlSwJPL5+xf 62hFBmx+M0iLwnwHJrtS9aQrKYJa6G7CYydxju5TuWFnFzgwbKnWA+KhksznVTDpK/Wl 5FU8KJNUEM+ZaS91ENfh7tCJPr4UZh1fnbPfKyIQXzCVZ64kOplrzvKzJ64gQ3QpM/6Q dd6Pdc3FkMzRApJcbysR4nwvDBzBjnlXec95aoIHEMnW4Bx9NCLR4bcLG0myKjPNUu/7 nEChkC+n3bC3I1ybCLHXeU1gvgCVjbUJfjNX+vYeWBMk/i7UQnDV14IM9Qdsb5A/8eyI d8/w== X-Gm-Message-State: AO0yUKW5kvvIarjAzf9UxfCzdOTnbE/+yLm78OHvp+Jw0Xrklnvlz6Cu Q2/jGowoto5u5Yq680IFt6UUEfmHjsawNVhCCBk= X-Google-Smtp-Source: AK7set/IzwW0WqT7ILJKHIlOARIDV35YYhhQZlpmFspvMx6V6UK5QIglRg4fj2gJEm2a9Zenk3T/zqkI8EVdafWU5xs= X-Received: by 2002:a2e:b5dc:0:b0:295:b29f:a663 with SMTP id g28-20020a2eb5dc000000b00295b29fa663mr2992436ljn.6.1677746531951; Thu, 02 Mar 2023 00:42:11 -0800 (PST) MIME-Version: 1.0 References: <20230302022921.4055291-1-xionghuluo@tencent.com> In-Reply-To: <20230302022921.4055291-1-xionghuluo@tencent.com> From: Richard Biener Date: Thu, 2 Mar 2023 09:41:59 +0100 Message-ID: Subject: Re: [PATCH 1/2] gcov: Fix "do-while" structure in case statement leads to incorrect code coverage [PR93680] To: Xionghu Luo Cc: gcc-patches@gcc.gnu.org, luoxhu@gcc.gnu.org, rguenther@suse.de, hubicka@ucw.cz Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: On Thu, Mar 2, 2023 at 3:31 AM Xionghu Luo via Gcc-patches wrote: > > When spliting edge with self loop, the split edge should be placed just next to > the edge_in->src, otherwise it may generate different position latch bbs for > two consecutive self loops. For details, please refer to: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93680#c4 > > Regression tested pass on x86_64-linux-gnu and aarch64-linux-gnu, OK for > master? > > gcc/ChangeLog: > > PR gcov/93680 > * tree-cfg.cc (split_edge_bb_loc): Return edge_in->src for self loop. > > gcc/testsuite/ChangeLog: > > PR gcov/93680 > * gcc.misc-tests/gcov-pr93680.c: New test. > > Signed-off-by: Xionghu Luo > --- > gcc/testsuite/gcc.misc-tests/gcov-pr93680.c | 24 +++++++++++++++++++++ > gcc/tree-cfg.cc | 2 +- > 2 files changed, 25 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-pr93680.c > > diff --git a/gcc/testsuite/gcc.misc-tests/gcov-pr93680.c b/gcc/testsuite/gcc.misc-tests/gcov-pr93680.c > new file mode 100644 > index 00000000000..b2bf9e626fc > --- /dev/null > +++ b/gcc/testsuite/gcc.misc-tests/gcov-pr93680.c > @@ -0,0 +1,24 @@ > +/* { dg-options "-fprofile-arcs -ftest-coverage" } */ > +/* { dg-do run { target native } } */ > + > +int f(int s, int n) > +{ > + int p = 0; > + > + switch (s) > + { > + case 0: /* count(5) */ > + do { p++; } while (--n); /* count(5) */ > + return p; /* count(1) */ > + > + case 1: /* count(5) */ > + do { p++; } while (--n); /* count(5) */ > + return p; /* count(1) */ > + } > + > + return 0; > +} > + > +int main() { f(0, 5); f(1, 5); return 0; } > + > +/* { dg-final { run-gcov gcov-pr93680.c } } */ > diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc > index a9fcc7fd050..6fa1d83d366 100644 > --- a/gcc/tree-cfg.cc > +++ b/gcc/tree-cfg.cc > @@ -3009,7 +3009,7 @@ split_edge_bb_loc (edge edge_in) > if (dest_prev) > { > edge e = find_edge (dest_prev, dest); > - if (e && !(e->flags & EDGE_COMPLEX)) > + if ((e && !(e->flags & EDGE_COMPLEX)) || edge_in->src == edge_in->dest) I think this should eventually apply to all backedge edge_in, correct? But of course we cannot easily test for this here. Still since this affects ordering in the {next,prev}_bb chain only but not CFG semantics I wonder how it can affect coverage? Isn't it only by chance that this block order survives? For the case when both edge_in->src has more than one successor and edge_in->dest has more than one predecessor there isn't any good heuristic to make printing the blocks in chain order "nice" (well, the backedge one maybe). But as said - this order shouldn't have any effect on semantics ... > return edge_in->src; > } > return dest_prev; > -- > 2.27.0 >