https://gcc.gnu.org/g:c73d7f3c66c0b5865edd6880cd0d6be723cfbb8d
commit r15-3202-gc73d7f3c66c0b5865edd6880cd0d6be723cfbb8d Author: Arsen Arsenović <ar...@aarsen.me> Date: Fri Aug 2 13:17:40 2024 +0200 coroutines: diagnose usage of alloca in coroutines 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: * coroutine-passes.cc (execute_early_expand_coro_ifns): Emit a sorry if a statement is an alloca call. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr115858.C: New test. Diff: --- gcc/coroutine-passes.cc | 10 ++++++++++ gcc/testsuite/g++.dg/coroutines/pr115858.C | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) 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), + "%<alloca%> 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 <coroutine> + +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; +}