From patchwork Wed Nov 30 17:13:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 27918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1047803wrr; Wed, 30 Nov 2022 09:14:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf51KMMqZwz/4+xdIIcrWok/jhOuZzEFLimOBytF2DN0L3dgrtYynKyEHSwtRMQHlK16NVPj X-Received: by 2002:a17:906:6dd7:b0:7a1:1c24:e564 with SMTP id j23-20020a1709066dd700b007a11c24e564mr40853665ejt.629.1669828444666; Wed, 30 Nov 2022 09:14:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669828444; cv=none; d=google.com; s=arc-20160816; b=gTnTM11kzgA4iQW6Yzv06pX1thqQP2GFTOu48fhAhq82uNrewoiFZ0D0PkzQdSJEnd RHfSVh2ltp15zzzkBfkJpNEFHGPw4Bwt7q/8trsE0NaFbgzyoJc4tPZ3psP8efPHwPb1 7wXTKYU6CIT+uFJ/3bSyMxQwuEbvk4kQtWZkvOCQmEqpuJiLkLrTL2M/x058Ezq75yEW UOYwGYct9KOo+s0BL90KOL3R7lJj9dv/qUnEF3CrU9aD4neZBE0n29VlPzMy4xHo13Is 83Y9aqufTB5RDFRlbWHMn9GmTarC5KkgSM6J3uV8ZvsLq+6fnbGNe/zloU/u103YMJiQ TuJw== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UILdvHHLtE4IdzRCYkUU5UMeflbqFEJOLiNDtMUyFno=; b=Z2K0JYZAgVsg1GEzVne0ZfYxV6gBowyUY4XDPSc7hXFxrO+zfV+IKwttTSmKnhW9c3 SbzLuoOc8/fh8mFNOFreFxaxSG2hF1WQkRHsU9RMXQwALSuSaan9PDU9UnUlgTZZiNO9 t166pKc6C3ldZUWP+WYte//DpFS5NOY9TmbX+hFaVsKJJ6ipUDTY3owMkfvOooxWsOGp 5XZInEjWm2pkzQVwA8vEIJICzKmHgJXx5RIFnU1r75Gq6+bscRAMGauJQywAGsjiHQLM H1e1QcdkwVBorBsn1uigsBFuPw5HIwHNQeVVgahtboEkTWH1WLl/0/FI7qy4qo8il99c Nxwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cK5tmKIW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id h7-20020a0564020e0700b00459b51c2b25si1782318edh.438.2022.11.30.09.14.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Nov 2022 09:14:04 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cK5tmKIW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 626B4385B523 for ; Wed, 30 Nov 2022 17:14:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 626B4385B523 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669828443; bh=UILdvHHLtE4IdzRCYkUU5UMeflbqFEJOLiNDtMUyFno=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=cK5tmKIWuqMEePRwpONZKK+GgBOlVVbSJ5X2Kwkj0mlrK4DVSRvQgt65Drnc/xYRo Re8Q09qElGyYP0i+cuDS6Vyv2RAiqMsSwUqtZ7qNXeZxKn30PskRs/LrnQ6nydvDMl DmjVCjgzqzrDPlquJ0bOWpfgwXEh8QB0ss4sZh3E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050:0:465::202]) by sourceware.org (Postfix) with ESMTPS id 489253858D1E for ; Wed, 30 Nov 2022 17:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 489253858D1E Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4NMm4X4jSlz9sTZ; Wed, 30 Nov 2022 18:13:16 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Fix ICE on named continue label in an unrolled loop [PR107592] Date: Wed, 30 Nov 2022 18:13:14 +0100 Message-Id: <20221130171314.323962-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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 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: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw 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?1750942030755123445?= X-GMAIL-MSGID: =?utf-8?q?1750942030755123445?= Hi, This patch fixes an ICE with using `continue' on a named label in an unrolled loop statement. Continue labels in an unrolled loop require a unique label per iteration. Previously this used the Statement body node for each unrolled iteration to generate a new entry in the label hash table. This does not work when the continue label has an identifier, as said named label is pointing to the outer UnrolledLoopStatement node. What would happen is that during the lowering of `continue label', an automatic label associated with the unrolled loop would be generated, and a jump to that label inserted, but because it was never pushed by the visitor for the loop itself, it subsequently never gets emitted. To fix, correctly use the UnrolledLoopStatement as the key to look up and store the break/continue label pair, but remove the continue label from the value entry after every loop to force a new label to be generated by the next call to `push_continue_label' Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and committed to mainline, and backported to previous release branches. Regards Iain. --- PR d/107592 gcc/d/ChangeLog: * toir.cc (IRVisitor::push_unrolled_continue_label): New method. (IRVisitor::pop_unrolled_continue_label): New method. (IRVisitor::visit (UnrolledLoopStatement *)): Use them instead of push_continue_label and pop_continue_label. gcc/testsuite/ChangeLog: * gdc.dg/pr107592.d: New test. --- gcc/d/toir.cc | 26 ++++++++++++++++++++++++-- gcc/testsuite/gdc.dg/pr107592.d | 13 +++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr107592.d diff --git a/gcc/d/toir.cc b/gcc/d/toir.cc index e5f5751f6db..e387f27760d 100644 --- a/gcc/d/toir.cc +++ b/gcc/d/toir.cc @@ -529,6 +529,28 @@ public: this->do_label (label); } + /* Generate and set a new continue label for the current unrolled loop. */ + + void push_unrolled_continue_label (UnrolledLoopStatement *s) + { + this->push_continue_label (s); + } + + /* Finish with the continue label for the unrolled loop. */ + + void pop_unrolled_continue_label (UnrolledLoopStatement *s) + { + Statement *stmt = s->getRelatedLabeled (); + d_label_entry *ent = d_function_chain->labels->get (stmt); + gcc_assert (ent != NULL && ent->bc_label == true); + + this->pop_continue_label (TREE_VEC_ELT (ent->label, bc_continue)); + + /* Remove the continue label from the label htab, as a new one must be + inserted at the end of every unrolled loop. */ + ent->label = TREE_VEC_ELT (ent->label, bc_break); + } + /* Visitor interfaces. */ @@ -1089,9 +1111,9 @@ public: if (statement != NULL) { - tree lcontinue = this->push_continue_label (statement); + this->push_unrolled_continue_label (s); this->build_stmt (statement); - this->pop_continue_label (lcontinue); + this->pop_unrolled_continue_label (s); } } diff --git a/gcc/testsuite/gdc.dg/pr107592.d b/gcc/testsuite/gdc.dg/pr107592.d new file mode 100644 index 00000000000..59f34477356 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr107592.d @@ -0,0 +1,13 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107592 +// { dg-do compile } + +void test107592(Things...)(Things things) +{ + label: + foreach (thing; things) + { + continue label; + } +} + +alias a107592 = test107592!(string);