From patchwork Thu Apr 30 13:24:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 1280412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Cbhp3mRtz9sSd for ; Thu, 30 Apr 2020 23:24:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66333395CC0C; Thu, 30 Apr 2020 13:24:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp1.wavenetuk.net (smtp.wavenetuk.net [195.26.36.10]) by sourceware.org (Postfix) with ESMTP id BCED43892007 for ; Thu, 30 Apr 2020 13:24:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BCED43892007 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=iain@sandoe.co.uk Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by smtp1.wavenetuk.net (Postfix) with ESMTPA id CB6371200EBC; Thu, 30 Apr 2020 14:24:43 +0100 (BST) From: Iain Sandoe Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] coroutines: Fix handling of artificial vars [PR94886] Message-Id: Date: Thu, 30 Apr 2020 14:24:41 +0100 To: GCC Patches X-Mailer: Apple Mail (2.3273) X-Spam-Status: No, score=-25.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Nathan Sidwell Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi Another case found when building the folly experimental coros stuff. tested on x86_64-darwin so far, OK for master after testing on x86_64-linux? thanks Iain The testcase ICEs because the range-based for generates three artificial variables that need to be allocated to the coroutine frame but, when walking the BIND_EXR that contains these, the DECL_INITIAL for one of them refers to an entry appearing later, which means that the frame entry hasn't been allocated when that INITIAL is walked. The solution is to defer walking the DECL_INITIAL/SIZE etc. until all the BIND_EXPR vars have been processed. gcc/cp/ChangeLog: 2020-04-30 Iain Sandoe PR c++/94886 * coroutines.cc (transform_local_var_uses): Defer walking the DECL_INITIALs of BIND_EXPR vars until all the frame allocations have been made. gcc/testsuite/ChangeLog: 2020-04-30 Iain Sandoe PR c++/94886 * g++.dg/coroutines/pr94886-folly-3.C: New test. --- gcc/cp/coroutines.cc | 21 ++++++++++++------- .../g++.dg/coroutines/pr94886-folly-3.C | 15 +++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr94886-folly-3.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 7bb3e98fe6c..1bc4bf2e45b 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1813,14 +1813,6 @@ transform_local_var_uses (tree *stmt, int *do_subtree, void *d) /* Re-write the variable's context to be in the actor func. */ DECL_CONTEXT (lvar) = lvd->context; - /* we need to walk some of the decl trees, which might contain - references to vars replaced at a higher level. */ - cp_walk_tree (&DECL_INITIAL (lvar), transform_local_var_uses, d, - NULL); - cp_walk_tree (&DECL_SIZE (lvar), transform_local_var_uses, d, NULL); - cp_walk_tree (&DECL_SIZE_UNIT (lvar), transform_local_var_uses, d, - NULL); - /* For capture proxies, this could include the decl value expr. */ if (local_var.is_lambda_capture || local_var.has_value_expr_p) { @@ -1842,6 +1834,19 @@ transform_local_var_uses (tree *stmt, int *do_subtree, void *d) lvd->actor_frame, fld_ref, NULL_TREE); local_var.field_idx = fld_idx; } + /* Now we've built the revised var in the frame, substitute uses of + it in initializers and the bind expr body. */ + for (lvar = BIND_EXPR_VARS (*stmt); lvar != NULL; + lvar = DECL_CHAIN (lvar)) + { + /* we need to walk some of the decl trees, which might contain + references to vars replaced at a higher level. */ + cp_walk_tree (&DECL_INITIAL (lvar), transform_local_var_uses, d, + NULL); + cp_walk_tree (&DECL_SIZE (lvar), transform_local_var_uses, d, NULL); + cp_walk_tree (&DECL_SIZE_UNIT (lvar), transform_local_var_uses, d, + NULL); + } cp_walk_tree (&BIND_EXPR_BODY (*stmt), transform_local_var_uses, d, NULL); /* Now we have processed and removed references to the original vars, diff --git a/gcc/testsuite/g++.dg/coroutines/pr94886-folly-3.C b/gcc/testsuite/g++.dg/coroutines/pr94886-folly-3.C new file mode 100644 index 00000000000..d7bd2c17d4a --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr94886-folly-3.C @@ -0,0 +1,15 @@ + +#include "coro.h" +#include "coro1-ret-int-yield-int.h" + +#include + +coro1 +my_coro () +{ + const std::array expectedValues = {{0, 3, 1, 4, 2}}; + + for (int expectedValue : expectedValues) { + co_yield expectedValue; + } +}