]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
coroutines: diagnose usage of alloca in coroutines
authorArsen Arsenović <arsen@aarsen.me>
Fri, 2 Aug 2024 11:17:40 +0000 (13:17 +0200)
committerArsen Arsenović <arsen@gcc.gnu.org>
Mon, 26 Aug 2024 20:31:38 +0000 (22:31 +0200)
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.

gcc/coroutine-passes.cc
gcc/testsuite/g++.dg/coroutines/pr115858.C [new file with mode: 0644]

index c0d6eca7c070bbff391a07ce51d05d7010ff24c9..9124ecae59163c58829e55d46ae72633b7c383bf 100644 (file)
@@ -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 (file)
index 0000000..3dfe820
--- /dev/null
@@ -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;
+}