On 8/7/24 9:15 AM, Arsen Arsenović wrote:
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()

If you indent this line...

gcc/ChangeLog:

        PR c++/115858

...you shouldn't need to repeat it here...

        * coroutine-passes.cc (execute_early_expand_coro_ifns): Emit a
        sorry if a statement is an alloca call.

gcc/testsuite/ChangeLog:

        PR c++/115858

...and here.  OK with that tweak.

        * 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),
+                     "%<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;
+}

Reply via email to