-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[bug] clang (incorrectly?) optimizes away an entire simple coroutine #65030
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
Comments
@llvm/issue-subscribers-coroutines |
1 similar comment
@llvm/issue-subscribers-coroutines |
At least this may not be the same reason with #65018, since the problem exists at least from clang14 (may be longer). |
Yes, good point! I should have mentioned that. |
I feel this might not be a bug now. Because the coroutine handle is not passed to any where after it gets created. So we can't resume it or destroy it. Then no matter what the So I'd like to close the page and feel free to reopen it if you find something differently. |
Good point, thank you! If I alter my example so that the coroutine handle escapes, then the optimization goes away. I apologize for missing this. |
Never mind. Your excellent reproducer helped a lot. |
In #65018 I made a report about clang introducing a data race in the following program with
-O1
, by writing to the coroutine frame after suspending:I found that if you compile it with
-O2
instead ata738bdf35e
(Compiler Explorer), clang completely eliminates the application logic and just returns a pointer to an uninitialized object:I don't think this optimization is correct. It seems like clang is asserting there is undefined behavior in the original code, but if there is I can't find it. It should be initializing the
resume
anddestroy
function pointers in the coroutine frame, then faithfully callingAwaiter::await_suspend
for each element in the array. That function may have arbitrary behavior, including side effects that consume the integer in the array.This may or may not have the same cause as #65018, where clang introduces a data race into this coroutine. Perhaps the data race that clang introduces allows it to convince itself that there is undefined behavior?
The text was updated successfully, but these errors were encountered: