Skip to content

Commit e7d1ae0

Browse files
[Clang][coro] Fix crash on emitting init suspend if the return type of await_resume() is not trivially destructible
1 parent 2c87571 commit e7d1ae0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

clang/lib/CodeGen/CGCoroutine.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
245245
FPOptionsOverride(), Loc, Loc);
246246
TryStmt = CXXTryStmt::Create(CGF.getContext(), Loc, TryBody, Catch);
247247
CGF.EnterCXXTryStmt(*TryStmt);
248+
CGF.EmitStmt(TryBody);
249+
// We don't use EmitCXXTryStmt here. We need to store to ResumeEHVar that
250+
// doesn't exist in the body.
251+
Builder.CreateFlagStore(false, Coro.ResumeEHVar);
252+
CGF.ExitCXXTryStmt(*TryStmt);
253+
LValueOrRValue Res;
254+
// We are not supposed to obtain the value from init suspend await_resume().
255+
Res.RV = RValue::getIgnored();
256+
return Res;
248257
}
249258

250259
LValueOrRValue Res;
@@ -253,11 +262,6 @@ static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
253262
else
254263
Res.RV = CGF.EmitAnyExpr(S.getResumeExpr(), aggSlot, ignoreResult);
255264

256-
if (TryStmt) {
257-
Builder.CreateFlagStore(false, Coro.ResumeEHVar);
258-
CGF.ExitCXXTryStmt(*TryStmt);
259-
}
260-
261265
return Res;
262266
}
263267

0 commit comments

Comments
 (0)