diff options
author | Arsen Arsenović <arsen@aarsen.me> | 2024-08-02 13:17:40 +0200 |
---|---|---|
committer | Arsen Arsenović <arsen@gcc.gnu.org> | 2024-08-26 22:31:38 +0200 |
commit | c73d7f3c66c0b5865edd6880cd0d6be723cfbb8d (patch) | |
tree | f4cc6fb966f1563079bc44d63668bf0a402bdfd2 | |
parent | 92c5265d22afaac146b2a7ecbc3dac9fc3382877 (diff) | |
download | gcc-c73d7f3c66c0b5865edd6880cd0d6be723cfbb8d.zip gcc-c73d7f3c66c0b5865edd6880cd0d6be723cfbb8d.tar.gz gcc-c73d7f3c66c0b5865edd6880cd0d6be723cfbb8d.tar.bz2 |
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.
-rw-r--r-- | gcc/coroutine-passes.cc | 10 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/coroutines/pr115858.C | 23 |
2 files changed, 33 insertions, 0 deletions
diff --git a/gcc/coroutine-passes.cc b/gcc/coroutine-passes.cc index c0d6eca..9124eca 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 0000000..3dfe820 --- /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; +} |