-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang][Coroutines] Properly emit EH code for initial suspend `await_…
…resume` (#73073) This change aims to fix an ICE in issue #63803 The crash happens in `ExitCXXTryStmt` because `EmitAnyExpr()` adds additional cleanup to the `EHScopeStack`. This messes up the assumption in `ExitCXXTryStmt` that the top of the stack should be a `EHCatchScope`. However, since we never read a value returned from `await_resume()` of an init suspend, we can skip the part that builds this `RValue`. The code here may not be in the best shape. There's another bug that `memberCallExpressionCanThrow` doesn't work on the current Expr due to type mismatch. I am preparing a separate PR to address it plus some refactoring might be beneficial.
- Loading branch information
1 parent
2c87571
commit 1fad78b
Showing
3 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
clang/test/CodeGenCoroutines/coro-init-await-nontrivial-return.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple=x86_64-- -emit-llvm -fcxx-exceptions \ | ||
// RUN: -disable-llvm-passes %s -o - | FileCheck %s | ||
|
||
#include "Inputs/coroutine.h" | ||
|
||
struct NontrivialType { | ||
~NontrivialType() {} | ||
}; | ||
|
||
struct Task { | ||
struct promise_type; | ||
using handle_type = std::coroutine_handle<promise_type>; | ||
|
||
struct initial_suspend_awaiter { | ||
bool await_ready() { | ||
return false; | ||
} | ||
|
||
void await_suspend(handle_type h) {} | ||
|
||
NontrivialType await_resume() { return {}; } | ||
}; | ||
|
||
struct promise_type { | ||
void return_void() {} | ||
void unhandled_exception() {} | ||
initial_suspend_awaiter initial_suspend() { return {}; } | ||
std::suspend_never final_suspend() noexcept { return {}; } | ||
Task get_return_object() { | ||
return Task{handle_type::from_promise(*this)}; | ||
} | ||
}; | ||
|
||
handle_type handler; | ||
}; | ||
|
||
Task coro_create() { | ||
co_return; | ||
} | ||
|
||
// CHECK-LABEL: define{{.*}} ptr @_Z11coro_createv( | ||
// CHECK: init.ready: | ||
// CHECK-NEXT: store i1 true, ptr {{.*}} | ||
// CHECK-NEXT: call void @_ZN4Task23initial_suspend_awaiter12await_resumeEv( | ||
// CHECK-NEXT: call void @_ZN14NontrivialTypeD1Ev( | ||
// CHECK-NEXT: store i1 false, ptr {{.*}} |