From patchwork Wed Aug 7 13:15:13 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: 1970039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aarsen.me header.i=@aarsen.me header.a=rsa-sha256 header.s=MBO0001 header.b=vr4OEfsL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf9gK3Sj1z1yfC for ; Wed, 7 Aug 2024 23:16:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 494B1385B508 for ; Wed, 7 Aug 2024 13:16:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050:0:465::102]) by sourceware.org (Postfix) with ESMTPS id 9399F3858C41 for ; Wed, 7 Aug 2024 13:16:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9399F3858C41 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 9399F3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2050:0:465::102 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723036586; cv=none; b=uIzGZgH/Y7nAlmE22kyHFjzQgiWPQnKu8C5d80i+5g+j9UEU7FMTLNTT68WW/DjvPPgp23EQQGRZ/StYdwKyFapSovT2McZ3ETVmkyuPOkbcDosh+odwMxMRu6uRe0cOdC3YDMFLXGBKrL1UxOZu5LhyEDKCwp9p3+g+iH4asZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723036586; c=relaxed/simple; bh=gXU9TcHuXP31lEN9I2lUW5sYeNmpjJLhAqOZJKQEtBs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=k3kJVu5Lz3xKdXoElFkwzMedEOcHl3HVjMfB48Hg3eEN+/OboSp9EZMDtiPSNcz4ZOI6WoGiICUR7QRHMNA20ghj4641KJHbh9X39ic37tpq+VRfUSSVjepfvt1O6Oe5sjWEi7gPHSwXYmMsKyjhwgGCmyAG+KdU1Uaaf+c6X0Y= ARC-Authentication-Results: i=1; server2.sourceware.org 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 X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4Wf9fs4XJQz9v7t; Wed, 7 Aug 2024 15:16:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1723036581; 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=GixzFdGHvrPF8z+T4Elf22iL8O25ilImizmh2olptos=; b=vr4OEfsL+SpC85PwGga3OANAED86F0MR2Sz6IlGB9+G5eQ1p1QS8FuiQdqomBojb5WiIuz 3pscpmHa8Bxh43YIOXMxrsdh00u0ws7260/I4Q94iO3hpRzLi+HEraJliSEBUsFfL+o7wz ICroJiTZH4BIHF0L/rUv+AUsqQgGEjWijyvT2PGtZ72UGYs8fMU3Cyai5QqnZPlga38P51 xrnyGXC5V9GW2023CQWazd/OgmUw+rUCdR0WBPRTPmkLvBR8AD8dUgGHLvosu3upUsjurq VGgTdG0rZ5RZFBwjnTSoLB3HvAmHOXkTrC6wi0GTIKm/YOClMGM6vNGeWOAQww== From: =?utf-8?q?Arsen_Arsenovi=C4=87?= To: gcc-patches@gcc.gnu.org Cc: Iain Sandoe , =?utf-8?q?Arsen_Arsenovi=C4=87?= Subject: [PATCH] coroutines: diagnose usage of alloca in coroutines Date: Wed, 7 Aug 2024 15:15:13 +0200 Message-ID: <20240807131613.526335-1-arsen@aarsen.me> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_INFOUSMEBIZ, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-pc-linux-gnu. OK for trunk? ---------- >8 ---------- We do not support it currently, and the resulting memory can only be used inside a single resumption, so best not confuse the user with it. PR c++/115858 - Incompatibility of coroutines and alloca() gcc/ChangeLog: PR c++/115858 * coroutine-passes.cc (execute_early_expand_coro_ifns): Emit a sorry if a statement is an alloca call. gcc/testsuite/ChangeLog: PR c++/115858 * g++.dg/coroutines/pr115858.C: New test. --- gcc/coroutine-passes.cc | 10 ++++++++++ gcc/testsuite/g++.dg/coroutines/pr115858.C | 23 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr115858.C diff --git a/gcc/coroutine-passes.cc b/gcc/coroutine-passes.cc index c0d6eca7c070..9124ecae5916 100644 --- a/gcc/coroutine-passes.cc +++ b/gcc/coroutine-passes.cc @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple.h" #include "tree-pass.h" #include "ssa.h" +#include "calls.h" #include "cgraph.h" #include "pretty-print.h" #include "diagnostic-core.h" @@ -306,6 +307,15 @@ execute_early_expand_coro_ifns (void) { gimple *stmt = gsi_stmt (gsi); + /* Tell the user about 'alloca', we don't support it yet. */ + if (gimple_alloca_call_p (stmt)) + { + sorry_at (gimple_location (stmt), + "% is not yet supported in coroutines"); + gsi_next (&gsi); + continue; + } + if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt)) { gsi_next (&gsi); diff --git a/gcc/testsuite/g++.dg/coroutines/pr115858.C b/gcc/testsuite/g++.dg/coroutines/pr115858.C new file mode 100644 index 000000000000..3dfe820dbdfd --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr115858.C @@ -0,0 +1,23 @@ +#include + +struct task +{ + struct promise_type + { + void return_void () {} + task get_return_object () { return {}; } + void unhandled_exception () {} + std::suspend_never initial_suspend () { return {}; } + std::suspend_never final_suspend () noexcept { return {}; } + }; +}; + +task +f () +{ + void* a = __builtin_alloca (10); + // { dg-message "sorry, unimplemented: 'alloca' is not yet supported in coroutines" "" { target *-*-* } {.-1} } + void* b = __builtin_alloca_with_align (10, 16); + // { dg-message "sorry, unimplemented: 'alloca' is not yet supported in coroutines" "" { target *-*-* } {.-1} } + co_return; +}