From patchwork Wed Sep 4 14:53:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Arsen_Arsenovi=C4=87?= X-Patchwork-Id: 97086 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 B8C1C3861839 for ; Wed, 4 Sep 2024 15:00:59 +0000 (GMT) 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 [80.241.56.172]) by sourceware.org (Postfix) with ESMTPS id BAAC63858C50 for ; Wed, 4 Sep 2024 15:00:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAAC63858C50 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BAAC63858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.241.56.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725462034; cv=none; b=M5WpzGRh2xYqUVgkuobWw7leJjiJ3VVpkEThspS8QUSnd1owCpFLm8wH4mBAWDwTukTM0+EJoDEisUukYlxYC/dnH6dS3xS34yJuE70AMp9Hh8F9zTVSG6acEvYRFX4wSVaMmm5GDkhfWN0VyCMI9IGEWdiTIb2YciQrbS/AQCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725462034; c=relaxed/simple; bh=LzMkhFfwJyKOSGRRdodqsgAIWd/aYhocRZ+MODTj83o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lN+mVC5UyMdNYpyLkn77pkVkWSXKNDNOTqdlSLz6vApc2O+DbCy2c8mQCQpD48+ZMkmYMFe3bECVkV9YJjMnw7QXuT9JuBwkDES62miA8L26EXML+PY/YHPDRdRXz4suhJmvARK4YX5lspiHcrZmdbhhF7yrW2UZg7GcNs5X7n8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (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 mout-p-202.mailbox.org (Postfix) with ESMTPS id 4WzQf253gkz9tG1; Wed, 4 Sep 2024 17:00:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1725462026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=MLBVSKgbGJ+BphYMAh0ZSv/+SYrOBClOARNSWweXLAg=; b=aKrK0etrCUBKgVOEqibCL9pp2h6/MSHe4Gr6xUcz6bYk1CGbqpZ7ctN6RS5Gk3C6rsD538 A8ektjGbcP/JofzZxUX/VuWQjtYrzqC6QJGhZOJxfPhljMzlbJ78+52gcdkFBAZM5zNeaJ DVhHoK6UyN20U98K8C0h96relk+mOAuThSPMvSGDynPuSfiNl98Xd5svNdwXfRMEj7e2Ws 8HEoTcfpM+DHFy+oL8iq9gV+iNn8qrVa6FK1031s+BrA3Fx0NGCE8/WgaRy6vcLeLNwU+q dQvbSti6qGKERHECNx7ZK2ZF+NJUElG9/Apyi96hBmRc7pz6pFS97ep85dTpfg== From: =?utf-8?q?Arsen_Arsenovi=C4=87?= To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?Arsen_Arsenovi=C4=87?= Subject: [pushed] c++: add a testcase for [PR 108620] Date: Wed, 4 Sep 2024 16:53:44 +0200 Message-ID: <20240904145836.643680-1-arsen@aarsen.me> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Pushed as obvious. ---------- >8 ---------- Fixed by r15-2540-g32e678b2ed7521. Add a testcase, as the original ones do not cover this particular failure mode. gcc/testsuite/ChangeLog: PR c++/108620 * g++.dg/coroutines/pr108620.C: New test. --- gcc/testsuite/g++.dg/coroutines/pr108620.C | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr108620.C diff --git a/gcc/testsuite/g++.dg/coroutines/pr108620.C b/gcc/testsuite/g++.dg/coroutines/pr108620.C new file mode 100644 index 000000000000..e8016b9f8a23 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr108620.C @@ -0,0 +1,95 @@ +// https://gcc.gnu.org/PR108620 +#include +#include +#include + +template +struct task; + +template +struct task_private_data { + inline task_private_data() noexcept : data_(nullptr) {} + inline task_private_data(PrivateDataType* input) noexcept : data_(input) {} + inline task_private_data(task_private_data&& other) noexcept = default; + inline task_private_data& operator=(task_private_data&&) noexcept = default; + inline task_private_data(const task_private_data&) = delete; + inline task_private_data& operator=(const task_private_data&) = delete; + inline ~task_private_data() {} + + inline bool await_ready() const noexcept { return true; } + inline PrivateDataType* await_resume() const noexcept { return data_; } + inline void await_suspend(std::coroutine_handle<>) noexcept {} + + PrivateDataType* data_; +}; + +template +struct task_context { + PrivateDataType data_; +}; + +template +struct task { + using self_type = task; + std::shared_ptr> context_; + + task(const std::shared_ptr>& input): context_(input) {} + + static auto yield_private_data() noexcept { return task_private_data{}; } + + struct promise_type { + std::shared_ptr> context_; + + template + promise_type(Input&& input, Rest&&...) { + context_ = std::make_shared>(); + context_->data_ = std::forward(input); + } + + auto get_return_object() noexcept { return self_type{context_}; } + std::suspend_never initial_suspend() noexcept { return {}; } + std::suspend_never final_suspend() noexcept { return {}; } + void unhandled_exception() { throw; } + + template + void return_value(ReturnType&&) {} + + template + inline task_private_data yield_value( + task_private_data&& input) noexcept { + input.data_ = &context_->data_; + return task_private_data(input.data_); + } + }; +}; + +template +task call1(TArg&& arg, OutputType& output) { + OutputType* ptr = co_yield task::yield_private_data(); + output = *ptr; + co_return 0; +} + + +struct container { + std::string* ptr; +}; + +template +task call2(TArg&& arg, container& output) { + output.ptr = co_yield task::yield_private_data(); + co_return 0; +} + +int main() { + // success + std::string output1; + call1(std::string("hello1"), output1); + std::cout<< "output1: "<< output1<< std::endl; + + // crash + container output2; + auto task2 = call2(std::string("hello2"), output2); + std::cout<< "output2: "<< *output2.ptr<< std::endl; + return 0; +}