From patchwork Fri Jul 7 00:40:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Li X-Patchwork-Id: 9829257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 75CBF60317 for ; Fri, 7 Jul 2017 00:41:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6620528544 for ; Fri, 7 Jul 2017 00:41:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AD35285AD; Fri, 7 Jul 2017 00:41:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4DB228582 for ; Fri, 7 Jul 2017 00:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752718AbdGGAlC (ORCPT ); Thu, 6 Jul 2017 20:41:02 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:32824 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752351AbdGGAlB (ORCPT ); Thu, 6 Jul 2017 20:41:01 -0400 Received: by mail-pf0-f195.google.com with SMTP id e199so2313957pfh.0 for ; Thu, 06 Jul 2017 17:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=kH98qdTQ/UiX6v3m9LsENmsO4+8iNntiNENQQsR6TxQ=; b=NCw0E5Futh32AYnwIesR6yOB+4w/xc3L0k8up0C8U9t5lVX3kZaoDPsezeF+V6ZD8L rAprvTTWnf9fG66moWMswTdTrykd803S2vftK0Wii/MjZ7Y/1xQZPFnQbW2sNWspQMCT Gaq9DvLib8rzBnNF4chBUuEAOlmS8qIRjyM3DSq2vVkrhP6CT9F5zCxVr8luwJwY09A4 BSN9//5b9AErIws05ZtOiCFBOv3C6nKgfsG5sZILf1tnuz6W/mnlK9R9BAo/rN+SwKqN Rq47XkVDlByAYB0wr/bXg80I/0Lf81G1KbE9bNtWoQGtD1sJH3ZpQQ5g3juycoVFrlb3 6E8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=kH98qdTQ/UiX6v3m9LsENmsO4+8iNntiNENQQsR6TxQ=; b=PTbpWLroUo2y2ebqVU9pMYx8krQ4+B4L4VHk6rZumdezL3XE1WTM8kpoWoqUU28pU7 xrh6Fc7djBwiiKL9u2mjRuWWxfq9trvir6foPg2RS9nKMnjS1ONcHdU7hrAXhtQ0wcnj ExpOz13ytvoOIqgOLN3pEn8Jn4NjH4z85oj52nOEUETui2WihGGzjYLmtCTefEA2ezwn 1f7rQb7JWmGhJ9nEkj6jysID9lHL5G34Y1vXmfaJP0rEQZyXZIpOGGxzzc33gYBvMzIY 5hPOHOtjKCPbxrgoNr6wlIe/B+5Zgy0WMZL2otVvLC33McSGdzceanfsADI9dHSsZrlx RTvg== X-Gm-Message-State: AIVw111kj5wBkRz8z6k22Yipb6gIT5r22p2YbOhR0nVve3STVzTHltSD SpETclnOHn5Sesb15ATlGBL0814xhg== X-Received: by 10.98.8.132 with SMTP id 4mr29248107pfi.109.1499388060612; Thu, 06 Jul 2017 17:41:00 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.149.130 with HTTP; Thu, 6 Jul 2017 17:40:59 -0700 (PDT) In-Reply-To: <20170706191950.81268-2-luc.vanoostenryck@gmail.com> References: <20170706191950.81268-1-luc.vanoostenryck@gmail.com> <20170706191950.81268-2-luc.vanoostenryck@gmail.com> From: Christopher Li Date: Thu, 6 Jul 2017 17:40:59 -0700 X-Google-Sender-Auth: mEWX8wXsghIBuleK5L1dl1vB430 Message-ID: Subject: Re: [PATCH 1/5] do not corrupt ptrlist while killing unreachable BBs To: Luc Van Oostenryck Cc: Linux-Sparse Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Jul 6, 2017 at 12:19 PM, Luc Van Oostenryck wrote: > In commit (51cfbc90a5 "fix: kill unreachable BBs after killing a child") > kill_unreachable_bbs() was called during simplification in order > to avoid creating fake cycles between phis and issuing bogus > "crazy programmer" warnings. > > However, simplification is done via cse.c:clean_up_insns() > which is looping over all BBs while kill_unreachable_bbs() > loops over all BBs *and* can delete some of them which may > corrupt the looping in clean_up_insns(). > > Fix this, by adding a flag to kill_unreachable_bbs(), telling > if it is safe to delete the BBs or if we can just mark them > as unreachable (set bb->ep to NULL and unlink any parent and/or > chilren), in which case the deletion will be done later. > > Note: the reproducer is one with very broken syntax but nothing > seems to forbid the same situation to happen with a valid > program. > > Fixes: 51cfbc90a5e1462fcd624a1598ecd985a508a5d6 > Signed-off-by: Luc Van Oostenryck Thanks for catching it. That is a very serious bug. The release will be on hold until this bug has been fix. It is actually more than one of them. I will send out a separate patch catching this kind of behavior. When the parent is doing the loop on this, the lower level caller remove the list element is very hasty. > -void kill_unreachable_bbs(struct entrypoint *ep) > +void kill_unreachable_bbs(struct entrypoint *ep, int del) > { > struct basic_block *bb; > unsigned long generation = ++bb_generation; > @@ -837,7 +837,8 @@ void kill_unreachable_bbs(struct entrypoint *ep) > /* Mark it as being dead */ > kill_bb(bb); > bb->ep = NULL; > - DELETE_CURRENT_PTR(bb); > + if (del) > + DELETE_CURRENT_PTR(bb); > } END_FOR_EACH_PTR(bb); > PACK_PTR_LIST(&ep->bbs); > Well, it can happen to other ptr list as well. And it did. For this one, I thing it is simpler just move the kill_unreachable_bbs() to the outer stage. Some thing like this, what do you say? It did pass the validation test you send out on this patch. From c4ef6086b07cdf1d0d1790a274ba056910b00b44 Mon Sep 17 00:00:00 2001 From: Christopher Li Date: Thu, 6 Jul 2017 16:25:38 -0700 Subject: [PATCH 1/2] move kill_unreachable_bbs to outer cse stage --- cse.c | 3 +++ linearize.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cse.c b/cse.c index 0d3815c..af9863f 100644 --- a/cse.c +++ b/cse.c @@ -387,6 +387,9 @@ repeat: } } + if (repeat_phase & REPEAT_CFG_CLEANUP) + kill_unreachable_bbs(ep); + if (repeat_phase & REPEAT_SYMBOL_CLEANUP) simplify_memops(ep); diff --git a/linearize.c b/linearize.c index 7313e72..a367207 100644 --- a/linearize.c +++ b/linearize.c @@ -671,9 +671,6 @@ void insert_branch(struct basic_block *bb, struct instruction *jmp, struct basic remove_parent(child, bb); } END_FOR_EACH_PTR(child); PACK_PTR_LIST(&bb->children); - - if (repeat_phase & REPEAT_CFG_CLEANUP) - kill_unreachable_bbs(bb->ep); }