forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 321
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
clang++ 14.0.2 compiled code crash when calling coroutine handle.destroy() in await suspend() #6724
Comments
FunMiles
changed the title
clang++ code crash when calling coroutine handle.destroy() in await suspend()
clang++ 14.0.2 compiled code crash when calling coroutine handle.destroy() in await suspend()
Apr 27, 2023
The problem remains under 14.0.3. |
This problem exist in the original LLVM and is fixed by llvm@c467245 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have an example of code that works with G++ 12, older Clang++ (v14.0.0 on macOS with experimental coroutines) and Clang++ in unoptimized compilation but crashes with -O2 or -O3 turned on. The crash happens when calling destroy on the handle of the suspended coroutine. The docs on cppreference.com states that when await_resume is called:
the coroutine is suspended (its coroutine state is populated with local variables and current suspension point). awaiter.await_suspend(handle) is called, where handle is the coroutine handle representing the current coroutine. Inside that function, the suspended coroutine state is observable via that handle, and it's this function's responsibility to schedule it to resume on some executor, or to be destroyed.
My code does just that. It destroys the calling subroutine and resumes another coroutine. Unfortunately, in macOS, Clang++ 14.0.2 (recent update) makes this code crash but only when -O2 or -O3 are used.
The below code is the minimum code I could build to demonstrate the problem. Note that almost any change will not be able to demonstrate the crash. For example, removing the loop in main (the part inside is called only once) will avoid the crash. The compiler does very aggressive optimization such that running the debugger does not allow to stop in several places that might be useful.
The expected output:
Actual output:
The text was updated successfully, but these errors were encountered: