Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER for gcc and modern MSVC #216

Open
RedBeard0531 opened this issue Mar 22, 2023 · 1 comment

Comments

@RedBeard0531
Copy link

MSVC now supports symmetric transfer, and I think gcc has since it introduced coroutines support. However, cppcoro currently only uses symmetric transfer for clang >= 7.

/// \def CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER
/// Defined to 1 if the compiler supports returning a coroutine_handle from
/// the await_suspend() method as a way of transferring execution
/// to another coroutine with a guaranteed tail-call.
#if CPPCORO_COMPILER_CLANG
# if __clang_major__ >= 7
# define CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER 1
# endif
#endif
#ifndef CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER
# define CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER 0
#endif

Rather than hard-coding a bunch more compiler versions, it may make more sense to check for __cpp_impl_coroutine >= 201902 to automatically use symmetric transfer for any compiler that claims compliant support of the final coroutine spec (probably with || __clang_minor__ >= 7 to keep working with old clang).

@RedBeard0531
Copy link
Author

FYI, I ran into this while comparing codegen between gcc and clang on godbolt, where cppcoro is an easy way to quickly play with coroutines. When doing this I couldn't make sense of the gcc codegen until I realized that it was actually being fed different code than clang. When I added -DCPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER to the command line, everything made sense again. Hopefully nobody else has to go through this fun discovery process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant