From patchwork Mon Jul 31 20:36:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9873109 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 7EB166037D for ; Mon, 31 Jul 2017 20:36:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DBAC27F3E for ; Mon, 31 Jul 2017 20:36:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62894285DC; Mon, 31 Jul 2017 20:36:37 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 D7CDE27F3E for ; Mon, 31 Jul 2017 20:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751054AbdGaUgg (ORCPT ); Mon, 31 Jul 2017 16:36:36 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:35245 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751106AbdGaUgf (ORCPT ); Mon, 31 Jul 2017 16:36:35 -0400 Received: by mail-wr0-f194.google.com with SMTP id c24so28955665wra.2 for ; Mon, 31 Jul 2017 13:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VMWEcWoOUVrfSGAmuaAKMYnaE6HQIPaaWl9lpbFYF2U=; b=UY88ZDHmrEVTzXle+Qa1hX3Z+0hBTptV0PkSYlP+/5YSOmRcMN+5tjNKGYBwr08hwY 3KywVUgf0U91CXY0gBv/R+nofRjdu9Zb6xo3YyZTlHhQ1gfsXkZO9e8HyvwAt9f6VF/2 ELxdryaLruGMwGxb5WtTNA/76Ijz34oiFwhqqLlvh4ObHrpMy81Vx82V+W4fFfOutcgH 1y7B79GLtpDtr6iCwbOi+ybs1LL9LqqlsaStmtQkJYc51cj1CCN57j8L2gx/OMs+cSyP BPeSKvJRPz7tMoujxZUJte4aHiBKTH2SmwV27hRYpss40pUB24eDhNSfFerNv2beXTKZ CxRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VMWEcWoOUVrfSGAmuaAKMYnaE6HQIPaaWl9lpbFYF2U=; b=kcLkjnG3CcilnwL65X15YmlnexokkIFcFrKPq6hBmSCXsUT3LVhaeLvfQuAr3SFuNq vtIG/+j22Qv1x6qVc30aRq3WkfE+c05iloLdyINp2E/WInu0c8XnHhyN8aSAUIopD7Ez hYptScaaEhKlt3bqq+I9jP+DUYYipQYbSw43cf/qjihdHVh1OZHPqgYgBv4iwwx7+YZn KthBcUc9/qbZTZKSVvUa4PgosGnHi/MjcT+LloWCoMOiuBmZZt9dNlP716ZXf9RZ1EGY N8PuR65/CKo0TdT6YnV4hy7ZzfHRZEDeI4WHmTjVmOhlLsT+LKe9Li0+d5aFqsIibNuH 435A== X-Gm-Message-State: AIVw1130g6nDHOFve9VIOWBGkN0qsdt7Cok+2cqLk0DgpM6JLrxjME3p OZ7fOeA5kO8pJw== X-Received: by 10.223.157.4 with SMTP id k4mr15496100wre.270.1501533394601; Mon, 31 Jul 2017 13:36:34 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:40c4:ab00:f976:d678:e4f6:5c60]) by smtp.gmail.com with ESMTPSA id n7sm47682350wrb.37.2017.07.31.13.36.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Jul 2017 13:36:34 -0700 (PDT) From: Luc Van Oostenryck To: Christopher Li Cc: linux-sparse@vger.kernel.org, Michael Stefaniuc , Luc Van Oostenryck Subject: [PATCH v3 2/7] fix infinite simplification loops Date: Mon, 31 Jul 2017 22:36:19 +0200 Message-Id: <20170731203624.58971-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170731203624.58971-1-luc.vanoostenryck@gmail.com> References: <20170731203624.58971-1-luc.vanoostenryck@gmail.com> 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 Each time a parent is removed from a BB there is the possibility that the BB become unreachable. This in turn can create cycles of dead BBs which can the create inifinite loops during the simplification process. Fix this by setting the flag REPEAT_CFG_CLEANUP when a branch is rewritten, this will in turn trigger a call to kill_unreachable_bbs() which will break these loops. Reported-by: Michael Stefaniuc Signed-off-by: Luc Van Oostenryck --- flow.c | 3 ++- validation/infinite-loop02.c | 11 +++++++++++ validation/infinite-loop03.c | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 validation/infinite-loop02.c create mode 100644 validation/infinite-loop03.c diff --git a/flow.c b/flow.c index fce8bde21..536bf257f 100644 --- a/flow.c +++ b/flow.c @@ -34,7 +34,8 @@ static int rewrite_branch(struct basic_block *bb, return 0; /* We might find new if-conversions or non-dominating CSEs */ - repeat_phase |= REPEAT_CSE; + /* we may also create new dead cycles */ + repeat_phase |= REPEAT_CSE | REPEAT_CFG_CLEANUP; *ptr = new; replace_bb_in_list(&bb->children, old, new, 1); remove_bb_from_list(&old->parents, bb, 1); diff --git a/validation/infinite-loop02.c b/validation/infinite-loop02.c new file mode 100644 index 000000000..7d0761d87 --- /dev/null +++ b/validation/infinite-loop02.c @@ -0,0 +1,11 @@ +void foo(void) +{ + int a = 1; + while ((a = !a)) + ; +} + +/* + * check-name: infinite loop 02 + * check-command: sparse -Wno-decl $file + */ diff --git a/validation/infinite-loop03.c b/validation/infinite-loop03.c new file mode 100644 index 000000000..ac8a9519d --- /dev/null +++ b/validation/infinite-loop03.c @@ -0,0 +1,16 @@ +static void foo(int *buf) +{ + int a = 1; + int *b; + do { + if (a) + b = buf; + if (a) + *buf = 0; + } while (!(a = !a)); +} + +/* + * check-name: infinite loop 03 + * check-command: sparse -Wno-decl $file + */