Skip to content

Instantly share code, notes, and snippets.

@iains
Created December 10, 2022 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iains/392ac23e0101297faf14b6d5e9020a95 to your computer and use it in GitHub Desktop.
Save iains/392ac23e0101297faf14b6d5e9020a95 to your computer and use it in GitHub Desktop.
allow 'extern "C" ' coroutines.
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 3f23317a315..c1a0d6c2283 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h"
#include "gcc-rich-location.h"
#include "hash-map.h"
+#include "cgraph.h"
static bool coro_promise_type_found_p (tree, location_t);
@@ -4060,6 +4061,17 @@ coro_build_actor_or_destroy_function (tree orig, tree fn_type,
else
info->destroy_decl = fn;
}
+ /* If the function is extern "C" the mangler will not be called. */
+ if (DECL_EXTERN_C_P (orig))
+ {
+ /* clone_function_name () picks up the name from DECL_ASSEMBLER_NAME
+ which is not yet set here. */
+ SET_DECL_ASSEMBLER_NAME (fn, DECL_NAME (orig));
+ if (actor_p)
+ SET_DECL_ASSEMBLER_NAME (fn, clone_function_name (fn, "actor"));
+ else
+ SET_DECL_ASSEMBLER_NAME (fn, clone_function_name (fn, "destroy"));
+ }
return fn;
}
@iains
Copy link
Author

iains commented Dec 10, 2022

just because one can do something ... does not mean one should (I'm still not exactly sure about when this would be useful and whether it was intended in the design - question to core to follow).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment