summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorGor Nishanov <GorNishanov@gmail.com>2017-05-22 22:33:17 +0000
committerGor Nishanov <GorNishanov@gmail.com>2017-05-22 22:33:17 +0000
commit5b050e4a1836c34b296303d0fbe29de87cffa436 (patch)
treecbd37fac2e30c362a3b90dfcaf11404de82e2790 /clang/lib
parenteb00ee07beff4fab367fa16b8074ba9856469f52 (diff)
downloadbcm5719-llvm-5b050e4a1836c34b296303d0fbe29de87cffa436.tar.gz
bcm5719-llvm-5b050e4a1836c34b296303d0fbe29de87cffa436.zip
[coroutines] Wrap the body of the coroutine in try-catch
Summary: If unhandled_exception member function is present in the coroutine promise, wrap the body of the coroutine in: ``` try { body } catch(...) { promise.unhandled_exception(); } ``` Reviewers: EricWF, rnk, rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31692 llvm-svn: 303583
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGCoroutine.cpp23
-rw-r--r--clang/lib/Sema/SemaCoroutine.cpp9
2 files changed, 31 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp b/clang/lib/CodeGen/CGCoroutine.cpp
index f01237205f0..c09c63f04b8 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -270,6 +270,15 @@ struct CallCoroDelete final : public EHScopeStack::Cleanup {
};
}
+static void emitBodyAndFallthrough(CodeGenFunction &CGF,
+ const CoroutineBodyStmt &S, Stmt *Body) {
+ CGF.EmitStmt(Body);
+ const bool CanFallthrough = CGF.Builder.GetInsertBlock();
+ if (CanFallthrough)
+ if (Stmt *OnFallthrough = S.getFallthroughHandler())
+ CGF.EmitStmt(OnFallthrough);
+}
+
void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) {
auto *NullPtr = llvm::ConstantPointerNull::get(Builder.getInt8PtrTy());
auto &TI = CGM.getContext().getTargetInfo();
@@ -318,7 +327,19 @@ void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) {
// FIXME: Emit initial suspend and more before the body.
CurCoro.Data->CurrentAwaitKind = AwaitKind::Normal;
- EmitStmt(S.getBody());
+
+ if (auto *OnException = S.getExceptionHandler()) {
+ auto Loc = S.getLocStart();
+ CXXCatchStmt Catch(Loc, /*exDecl=*/nullptr, OnException);
+ auto *TryStmt = CXXTryStmt::Create(getContext(), Loc, S.getBody(), &Catch);
+
+ EnterCXXTryStmt(*TryStmt);
+ emitBodyAndFallthrough(*this, S, TryStmt->getTryBlock());
+ ExitCXXTryStmt(*TryStmt);
+ }
+ else {
+ emitBodyAndFallthrough(*this, S, S.getBody());
+ }
// See if we need to generate final suspend.
const bool CanFallthrough = Builder.GetInsertBlock();
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index be89cd16deb..857dcda4e6e 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1043,6 +1043,15 @@ bool CoroutineStmtBuilder::makeOnException() {
if (UnhandledException.isInvalid())
return false;
+ // Since the body of the coroutine will be wrapped in try-catch, it will
+ // be incompatible with SEH __try if present in a function.
+ if (!S.getLangOpts().Borland && Fn.FirstSEHTryLoc.isValid()) {
+ S.Diag(Fn.FirstSEHTryLoc, diag::err_seh_in_a_coroutine_with_cxx_exceptions);
+ S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
+ << Fn.getFirstCoroutineStmtKeyword();
+ return false;
+ }
+
this->OnException = UnhandledException.get();
return true;
}
OpenPOWER on IntegriCloud