From patchwork Fri Aug 2 10:46:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 95192 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAFC4385842C for ; Fri, 2 Aug 2024 10:46:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 832853858D26 for ; Fri, 2 Aug 2024 10:46:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 832853858D26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 832853858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722595573; cv=none; b=SoKZilo0oyTCWnlcUmew23GBC7qzDsugWWiyWfYyyAoIfzYMfKWOEIcg1QZrgHnR1faZ8WBiWom5inVbcAFQXPY/QxzJyV89kFmLNWsB0oJPY+YO2hfgzkb6g1eubKm9eCbtoFaVgWfxutQ9RuUfxAY1n9D+qPcaFSEMyltj5Ho= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722595573; c=relaxed/simple; bh=idhIZ9DAZAMd8E3Swd/5bIUZeXM28Q+75/Zp/CN0FIo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=s5d5PdGA90PmsSFz6NpBBtz1uaqXk5MIkfWs0FyeTldH15yswZXdMJgMS6xsZbPY1Irc6Wu0hO7RXZqUtaL/cjglivqTz4Dp3l/u94EwQX4RVNg3VEK8svMesCN+pXnxF2FNZOgPcc8xqMtAkEHlZbo8dtYeykv/YGD9Br3DhvQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42122ac2f38so18332145e9.1 for ; Fri, 02 Aug 2024 03:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722595570; x=1723200370; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:from:to:cc:subject:date:message-id:reply-to; bh=2ZeTBKVntkv57hAsx1RUmqPYyHOgEhF+6kKNfzB4moo=; b=duCy63fU7FqNFQ2HqVwewfcPnaYqfZOvLFArkk81NEvUaFXcgjZIb3h3JX4Zkln/jU My6oOPAelvXZyFUqP4lS+e4MI1N3wn6ZRhPvywFnKUmxrC1LQd0GL624RVsvxup6jB1M 7ZYp1xMwRF1NOzz46FtfCGA9P400Z9nRY8C5czDJUkJc+ya+OteSk9BdxDDD+T+/YbUR +3PxUsRNQ84+MZecF2l9xp3aMM6K2AF3XAMP14SEqnaxgsGgy1tLDt5Lz9+tngdrHXri dystfgBoeOAbQMIoWMdXPaMdszLaFnSMwN+APMiKjcPyg6HltYHFDr82yoUJI04G6lkN x8UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722595570; x=1723200370; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2ZeTBKVntkv57hAsx1RUmqPYyHOgEhF+6kKNfzB4moo=; b=j9gGGwPvRt3cXX+rnfyzlS37xyIurQYpwaTbljddciTJophpu0nRrPOwbLh+BAeI1N mNVqLmxUdBNRkzK8CXJuoIpkygLJihzomLNVaQjDH0QkIUwY8ZXRp2r+9MkinyCeO6c9 uHbfAiFz79ShpyAFApoZAbtuxxZuM+WDX7wnX6X4us9UDMnNDZG9icna/H2ZKQ5+bPqR 9/nlvaUElX5MRkvOuo9ouwC+AhHH4mi3wr1P689uKV15bORJEevq7m1luOcAEmJlCmRv jBwNYN5DRQi8jUneX9VDn93yHcR2qE95hqfWQbpIvR1AxfiLlef0sdnp0HSMgnFAT/uq KpWw== X-Gm-Message-State: AOJu0YxrwyPqezCUsrn4AwiBBHEwqHW7wBsxcJgVUmJSKxjXZvTV/of2 2m9sbtct3RFzIKcWSPERDCkk/uR/TYLPEgCQ3lHoixljon+dqj1zbPMP7X6A X-Google-Smtp-Source: AGHT+IHQijK84dvOWV+m1LxcYeFAXVuanMjW78PQREpfA86CfIJToDksXfwrhbLkHl3YioCyxAWnSA== X-Received: by 2002:a05:600c:4e8a:b0:426:5b17:8458 with SMTP id 5b1f17b1804b1-428e69e3f47mr23074155e9.12.1722595569872; Fri, 02 Aug 2024 03:46:09 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-428e6e329b6sm28005545e9.20.2024.08.02.03.46.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 02 Aug 2024 03:46:09 -0700 (PDT) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [pushed] c++, coroutines: Provide a CTOR for a callback object [NFC]. Date: Fri, 2 Aug 2024 11:46:08 +0100 Message-Id: <20240802104608.41067-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: iain@sandoe.co.uk Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Tested on x86_64-darwin, pushed to trunk as obvious, thanks Iain --- 8< --- This provides and uses a CTOR to initialize the object used in tree walks to track local variable uses. This makes the idiom used consistent. gcc/cp/ChangeLog: * coroutines.cc (struct local_vars_frame_data): Add a CTOR. (morph_fn_to_coro): Use CTOR for local_vars_frame_data instead of brace init. Signed-off-by: Iain Sandoe --- gcc/cp/coroutines.cc | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 78a72047846..af03f5e0f74 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -3989,10 +3989,14 @@ struct local_vars_frame_data { tree *field_list; hash_map *local_var_uses; - unsigned int nest_depth, bind_indx; - location_t loc; - bool saw_capture; - bool local_var_seen; + unsigned int nest_depth = 0; + unsigned int bind_indx = 0; + location_t loc = UNKNOWN_LOCATION; + bool saw_capture = false; + bool local_var_seen = false; + + local_vars_frame_data (tree *_fl, hash_map *_lvu) + : field_list (_fl), local_var_uses (_lvu) {} }; /* A tree-walk callback that processes one bind expression noting local @@ -4577,8 +4581,6 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) /* Build our dummy coro frame layout. */ coro_frame_type = begin_class_definition (coro_frame_type); - /* The fields for the coro frame. */ - tree field_list = NULL_TREE; /* We need to know, and inspect, each suspend point in the function in several places. It's convenient to place this map out of line @@ -4592,10 +4594,13 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) cp_walk_tree (&fnbody, await_statement_walker, &body_aw_points, NULL); /* 4. Now make space for local vars, this is conservative again, and we - would expect to delete unused entries later. */ + would expect to delete unused entries later. Compose the frame entries + list. */ + + /* The fields for the coro frame. */ + tree field_list = NULL_TREE; hash_map local_var_uses; - local_vars_frame_data local_vars_data - = {&field_list, &local_var_uses, 0, 0, fn_start, false, false}; + local_vars_frame_data local_vars_data (&field_list, &local_var_uses); cp_walk_tree (&fnbody, register_local_var_uses, &local_vars_data, NULL); /* Tie off the struct for now, so that we can build offsets to the