clang 18.0.0git
CGCoroutine.cpp
Go to the documentation of this file.
1//===----- CGCoroutine.cpp - Emit LLVM Code for C++ coroutines ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code dealing with C++ code generation of coroutines.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CGCleanup.h"
14#include "CodeGenFunction.h"
15#include "llvm/ADT/ScopeExit.h"
16#include "clang/AST/StmtCXX.h"
18
19using namespace clang;
20using namespace CodeGen;
21
22using llvm::Value;
23using llvm::BasicBlock;
24
25namespace {
26enum class AwaitKind { Init, Normal, Yield, Final };
27static constexpr llvm::StringLiteral AwaitKindStr[] = {"init", "await", "yield",
28 "final"};
29}
30
32 // What is the current await expression kind and how many
33 // await/yield expressions were encountered so far.
34 // These are used to generate pretty labels for await expressions in LLVM IR.
35 AwaitKind CurrentAwaitKind = AwaitKind::Init;
36 unsigned AwaitNum = 0;
37 unsigned YieldNum = 0;
38
39 // How many co_return statements are in the coroutine. Used to decide whether
40 // we need to add co_return; equivalent at the end of the user authored body.
41 unsigned CoreturnCount = 0;
42
43 // A branch to this block is emitted when coroutine needs to suspend.
44 llvm::BasicBlock *SuspendBB = nullptr;
45
46 // The promise type's 'unhandled_exception' handler, if it defines one.
48
49 // A temporary i1 alloca that stores whether 'await_resume' threw an
50 // exception. If it did, 'true' is stored in this variable, and the coroutine
51 // body must be skipped. If the promise type does not define an exception
52 // handler, this is null.
53 llvm::Value *ResumeEHVar = nullptr;
54
55 // Stores the jump destination just before the coroutine memory is freed.
56 // This is the destination that every suspend point jumps to for the cleanup
57 // branch.
59
60 // Stores the jump destination just before the final suspend. The co_return
61 // statements jumps to this point after calling return_xxx promise member.
63
64 // Stores the llvm.coro.id emitted in the function so that we can supply it
65 // as the first argument to coro.begin, coro.alloc and coro.free intrinsics.
66 // Note: llvm.coro.id returns a token that cannot be directly expressed in a
67 // builtin.
68 llvm::CallInst *CoroId = nullptr;
69
70 // Stores the llvm.coro.begin emitted in the function so that we can replace
71 // all coro.frame intrinsics with direct SSA value of coro.begin that returns
72 // the address of the coroutine frame of the current coroutine.
73 llvm::CallInst *CoroBegin = nullptr;
74
75 // Stores the last emitted coro.free for the deallocate expressions, we use it
76 // to wrap dealloc code with if(auto mem = coro.free) dealloc(mem).
77 llvm::CallInst *LastCoroFree = nullptr;
78
79 // If coro.id came from the builtin, remember the expression to give better
80 // diagnostic. If CoroIdExpr is nullptr, the coro.id was created by
81 // EmitCoroutineBody.
82 CallExpr const *CoroIdExpr = nullptr;
83};
84
85// Defining these here allows to keep CGCoroData private to this file.
88
90 CodeGenFunction::CGCoroInfo &CurCoro,
91 llvm::CallInst *CoroId,
92 CallExpr const *CoroIdExpr = nullptr) {
93 if (CurCoro.Data) {
94 if (CurCoro.Data->CoroIdExpr)
95 CGF.CGM.Error(CoroIdExpr->getBeginLoc(),
96 "only one __builtin_coro_id can be used in a function");
97 else if (CoroIdExpr)
98 CGF.CGM.Error(CoroIdExpr->getBeginLoc(),
99 "__builtin_coro_id shall not be used in a C++ coroutine");
100 else
101 llvm_unreachable("EmitCoroutineBodyStatement called twice?");
102
103 return;
104 }
105
106 CurCoro.Data = std::unique_ptr<CGCoroData>(new CGCoroData);
107 CurCoro.Data->CoroId = CoroId;
108 CurCoro.Data->CoroIdExpr = CoroIdExpr;
109}
110
111// Synthesize a pretty name for a suspend point.
112static SmallString<32> buildSuspendPrefixStr(CGCoroData &Coro, AwaitKind Kind) {
113 unsigned No = 0;
114 switch (Kind) {
115 case AwaitKind::Init:
116 case AwaitKind::Final:
117 break;
118 case AwaitKind::Normal:
119 No = ++Coro.AwaitNum;
120 break;
121 case AwaitKind::Yield:
122 No = ++Coro.YieldNum;
123 break;
124 }
125 SmallString<32> Prefix(AwaitKindStr[static_cast<unsigned>(Kind)]);
126 if (No > 1) {
127 Twine(No).toVector(Prefix);
128 }
129 return Prefix;
130}
131
132static bool memberCallExpressionCanThrow(const Expr *E) {
133 if (const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
134 if (const auto *Proto =
135 CE->getMethodDecl()->getType()->getAs<FunctionProtoType>())
136 if (isNoexceptExceptionSpec(Proto->getExceptionSpecType()) &&
137 Proto->canThrow() == CT_Cannot)
138 return false;
139 return true;
140}
141
142// Emit suspend expression which roughly looks like:
143//
144// auto && x = CommonExpr();
145// if (!x.await_ready()) {
146// llvm_coro_save();
147// x.await_suspend(...); (*)
148// llvm_coro_suspend(); (**)
149// }
150// x.await_resume();
151//
152// where the result of the entire expression is the result of x.await_resume()
153//
154// (*) If x.await_suspend return type is bool, it allows to veto a suspend:
155// if (x.await_suspend(...))
156// llvm_coro_suspend();
157//
158// (**) llvm_coro_suspend() encodes three possible continuations as
159// a switch instruction:
160//
161// %where-to = call i8 @llvm.coro.suspend(...)
162// switch i8 %where-to, label %coro.ret [ ; jump to epilogue to suspend
163// i8 0, label %yield.ready ; go here when resumed
164// i8 1, label %yield.cleanup ; go here when destroyed
165// ]
166//
167// See llvm's docs/Coroutines.rst for more details.
168//
169namespace {
170 struct LValueOrRValue {
171 LValue LV;
172 RValue RV;
173 };
174}
175static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Coro,
176 CoroutineSuspendExpr const &S,
177 AwaitKind Kind, AggValueSlot aggSlot,
178 bool ignoreResult, bool forLValue) {
179 auto *E = S.getCommonExpr();
180
181 auto Binder =
182 CodeGenFunction::OpaqueValueMappingData::bind(CGF, S.getOpaqueValue(), E);
183 auto UnbindOnExit = llvm::make_scope_exit([&] { Binder.unbind(CGF); });
184
185 auto Prefix = buildSuspendPrefixStr(Coro, Kind);
186 BasicBlock *ReadyBlock = CGF.createBasicBlock(Prefix + Twine(".ready"));
187 BasicBlock *SuspendBlock = CGF.createBasicBlock(Prefix + Twine(".suspend"));
188 BasicBlock *CleanupBlock = CGF.createBasicBlock(Prefix + Twine(".cleanup"));
189
190 // If expression is ready, no need to suspend.
191 CGF.EmitBranchOnBoolExpr(S.getReadyExpr(), ReadyBlock, SuspendBlock, 0);
192
193 // Otherwise, emit suspend logic.
194 CGF.EmitBlock(SuspendBlock);
195
196 auto &Builder = CGF.Builder;
197 llvm::Function *CoroSave = CGF.CGM.getIntrinsic(llvm::Intrinsic::coro_save);
198 auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
199 auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
200
201 CGF.CurCoro.InSuspendBlock = true;
202 auto *SuspendRet = CGF.EmitScalarExpr(S.getSuspendExpr());
203 CGF.CurCoro.InSuspendBlock = false;
204
205 if (SuspendRet != nullptr && SuspendRet->getType()->isIntegerTy(1)) {
206 // Veto suspension if requested by bool returning await_suspend.
207 BasicBlock *RealSuspendBlock =
208 CGF.createBasicBlock(Prefix + Twine(".suspend.bool"));
209 CGF.Builder.CreateCondBr(SuspendRet, RealSuspendBlock, ReadyBlock);
210 CGF.EmitBlock(RealSuspendBlock);
211 }
212
213 // Emit the suspend point.
214 const bool IsFinalSuspend = (Kind == AwaitKind::Final);
215 llvm::Function *CoroSuspend =
216 CGF.CGM.getIntrinsic(llvm::Intrinsic::coro_suspend);
217 auto *SuspendResult = Builder.CreateCall(
218 CoroSuspend, {SaveCall, Builder.getInt1(IsFinalSuspend)});
219
220 // Create a switch capturing three possible continuations.
221 auto *Switch = Builder.CreateSwitch(SuspendResult, Coro.SuspendBB, 2);
222 Switch->addCase(Builder.getInt8(0), ReadyBlock);
223 Switch->addCase(Builder.getInt8(1), CleanupBlock);
224
225 // Emit cleanup for this suspend point.
226 CGF.EmitBlock(CleanupBlock);
228
229 // Emit await_resume expression.
230 CGF.EmitBlock(ReadyBlock);
231
232 // Exception handling requires additional IR. If the 'await_resume' function
233 // is marked as 'noexcept', we avoid generating this additional IR.
234 CXXTryStmt *TryStmt = nullptr;
235 if (Coro.ExceptionHandler && Kind == AwaitKind::Init &&
236 memberCallExpressionCanThrow(S.getResumeExpr())) {
237 Coro.ResumeEHVar =
238 CGF.CreateTempAlloca(Builder.getInt1Ty(), Prefix + Twine("resume.eh"));
240
241 auto Loc = S.getResumeExpr()->getExprLoc();
242 auto *Catch = new (CGF.getContext())
243 CXXCatchStmt(Loc, /*exDecl=*/nullptr, Coro.ExceptionHandler);
244 auto *TryBody = CompoundStmt::Create(CGF.getContext(), S.getResumeExpr(),
245 FPOptionsOverride(), Loc, Loc);
246 TryStmt = CXXTryStmt::Create(CGF.getContext(), Loc, TryBody, Catch);
247 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.
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;
257 }
258
259 LValueOrRValue Res;
260 if (forLValue)
261 Res.LV = CGF.EmitLValue(S.getResumeExpr());
262 else
263 Res.RV = CGF.EmitAnyExpr(S.getResumeExpr(), aggSlot, ignoreResult);
264
265 return Res;
266}
267
269 AggValueSlot aggSlot,
270 bool ignoreResult) {
271 return emitSuspendExpression(*this, *CurCoro.Data, E,
272 CurCoro.Data->CurrentAwaitKind, aggSlot,
273 ignoreResult, /*forLValue*/false).RV;
274}
276 AggValueSlot aggSlot,
277 bool ignoreResult) {
278 return emitSuspendExpression(*this, *CurCoro.Data, E, AwaitKind::Yield,
279 aggSlot, ignoreResult, /*forLValue*/false).RV;
280}
281
283 ++CurCoro.Data->CoreturnCount;
284 const Expr *RV = S.getOperand();
285 if (RV && RV->getType()->isVoidType() && !isa<InitListExpr>(RV)) {
286 // Make sure to evaluate the non initlist expression of a co_return
287 // with a void expression for side effects.
288 RunCleanupsScope cleanupScope(*this);
289 EmitIgnoredExpr(RV);
290 }
291 EmitStmt(S.getPromiseCall());
293}
294
295
296#ifndef NDEBUG
298 const CoroutineSuspendExpr *E) {
299 const auto *RE = E->getResumeExpr();
300 // Is it possible for RE to be a CXXBindTemporaryExpr wrapping
301 // a MemberCallExpr?
302 assert(isa<CallExpr>(RE) && "unexpected suspend expression type");
303 return cast<CallExpr>(RE)->getCallReturnType(Ctx);
304}
305#endif
306
307LValue
309 assert(getCoroutineSuspendExprReturnType(getContext(), E)->isReferenceType() &&
310 "Can't have a scalar return unless the return type is a "
311 "reference type!");
312 return emitSuspendExpression(*this, *CurCoro.Data, *E,
313 CurCoro.Data->CurrentAwaitKind, AggValueSlot::ignored(),
314 /*ignoreResult*/false, /*forLValue*/true).LV;
315}
316
317LValue
319 assert(getCoroutineSuspendExprReturnType(getContext(), E)->isReferenceType() &&
320 "Can't have a scalar return unless the return type is a "
321 "reference type!");
322 return emitSuspendExpression(*this, *CurCoro.Data, *E,
323 AwaitKind::Yield, AggValueSlot::ignored(),
324 /*ignoreResult*/false, /*forLValue*/true).LV;
325}
326
327// Hunts for the parameter reference in the parameter copy/move declaration.
328namespace {
329struct GetParamRef : public StmtVisitor<GetParamRef> {
330public:
331 DeclRefExpr *Expr = nullptr;
332 GetParamRef() {}
333 void VisitDeclRefExpr(DeclRefExpr *E) {
334 assert(Expr == nullptr && "multilple declref in param move");
335 Expr = E;
336 }
337 void VisitStmt(Stmt *S) {
338 for (auto *C : S->children()) {
339 if (C)
340 Visit(C);
341 }
342 }
343};
344}
345
346// This class replaces references to parameters to their copies by changing
347// the addresses in CGF.LocalDeclMap and restoring back the original values in
348// its destructor.
349
350namespace {
351 struct ParamReferenceReplacerRAII {
352 CodeGenFunction::DeclMapTy SavedLocals;
353 CodeGenFunction::DeclMapTy& LocalDeclMap;
354
355 ParamReferenceReplacerRAII(CodeGenFunction::DeclMapTy &LocalDeclMap)
356 : LocalDeclMap(LocalDeclMap) {}
357
358 void addCopy(DeclStmt const *PM) {
359 // Figure out what param it refers to.
360
361 assert(PM->isSingleDecl());
362 VarDecl const*VD = static_cast<VarDecl const*>(PM->getSingleDecl());
363 Expr const *InitExpr = VD->getInit();
364 GetParamRef Visitor;
365 Visitor.Visit(const_cast<Expr*>(InitExpr));
366 assert(Visitor.Expr);
367 DeclRefExpr *DREOrig = Visitor.Expr;
368 auto *PD = DREOrig->getDecl();
369
370 auto it = LocalDeclMap.find(PD);
371 assert(it != LocalDeclMap.end() && "parameter is not found");
372 SavedLocals.insert({ PD, it->second });
373
374 auto copyIt = LocalDeclMap.find(VD);
375 assert(copyIt != LocalDeclMap.end() && "parameter copy is not found");
376 it->second = copyIt->getSecond();
377 }
378
379 ~ParamReferenceReplacerRAII() {
380 for (auto&& SavedLocal : SavedLocals) {
381 LocalDeclMap.insert({SavedLocal.first, SavedLocal.second});
382 }
383 }
384 };
385}
386
387// For WinEH exception representation backend needs to know what funclet coro.end
388// belongs to. That information is passed in a funclet bundle.
392
393 if (llvm::Instruction *EHPad = CGF.CurrentFuncletPad)
394 BundleList.emplace_back("funclet", EHPad);
395
396 return BundleList;
397}
398
399namespace {
400// We will insert coro.end to cut any of the destructors for objects that
401// do not need to be destroyed once the coroutine is resumed.
402// See llvm/docs/Coroutines.rst for more details about coro.end.
403struct CallCoroEnd final : public EHScopeStack::Cleanup {
404 void Emit(CodeGenFunction &CGF, Flags flags) override {
405 auto &CGM = CGF.CGM;
406 auto *NullPtr = llvm::ConstantPointerNull::get(CGF.Int8PtrTy);
407 llvm::Function *CoroEndFn = CGM.getIntrinsic(llvm::Intrinsic::coro_end);
408 // See if we have a funclet bundle to associate coro.end with. (WinEH)
409 auto Bundles = getBundlesForCoroEnd(CGF);
410 auto *CoroEnd =
411 CGF.Builder.CreateCall(CoroEndFn,
412 {NullPtr, CGF.Builder.getTrue(),
413 llvm::ConstantTokenNone::get(CoroEndFn->getContext())},
414 Bundles);
415 if (Bundles.empty()) {
416 // Otherwise, (landingpad model), create a conditional branch that leads
417 // either to a cleanup block or a block with EH resume instruction.
418 auto *ResumeBB = CGF.getEHResumeBlock(/*isCleanup=*/true);
419 auto *CleanupContBB = CGF.createBasicBlock("cleanup.cont");
420 CGF.Builder.CreateCondBr(CoroEnd, ResumeBB, CleanupContBB);
421 CGF.EmitBlock(CleanupContBB);
422 }
423 }
424};
425}
426
427namespace {
428// Make sure to call coro.delete on scope exit.
429struct CallCoroDelete final : public EHScopeStack::Cleanup {
430 Stmt *Deallocate;
431
432 // Emit "if (coro.free(CoroId, CoroBegin)) Deallocate;"
433
434 // Note: That deallocation will be emitted twice: once for a normal exit and
435 // once for exceptional exit. This usage is safe because Deallocate does not
436 // contain any declarations. The SubStmtBuilder::makeNewAndDeleteExpr()
437 // builds a single call to a deallocation function which is safe to emit
438 // multiple times.
439 void Emit(CodeGenFunction &CGF, Flags) override {
440 // Remember the current point, as we are going to emit deallocation code
441 // first to get to coro.free instruction that is an argument to a delete
442 // call.
443 BasicBlock *SaveInsertBlock = CGF.Builder.GetInsertBlock();
444
445 auto *FreeBB = CGF.createBasicBlock("coro.free");
446 CGF.EmitBlock(FreeBB);
447 CGF.EmitStmt(Deallocate);
448
449 auto *AfterFreeBB = CGF.createBasicBlock("after.coro.free");
450 CGF.EmitBlock(AfterFreeBB);
451
452 // We should have captured coro.free from the emission of deallocate.
453 auto *CoroFree = CGF.CurCoro.Data->LastCoroFree;
454 if (!CoroFree) {
455 CGF.CGM.Error(Deallocate->getBeginLoc(),
456 "Deallocation expressoin does not refer to coro.free");
457 return;
458 }
459
460 // Get back to the block we were originally and move coro.free there.
461 auto *InsertPt = SaveInsertBlock->getTerminator();
462 CoroFree->moveBefore(InsertPt);
463 CGF.Builder.SetInsertPoint(InsertPt);
464
465 // Add if (auto *mem = coro.free) Deallocate;
466 auto *NullPtr = llvm::ConstantPointerNull::get(CGF.Int8PtrTy);
467 auto *Cond = CGF.Builder.CreateICmpNE(CoroFree, NullPtr);
468 CGF.Builder.CreateCondBr(Cond, FreeBB, AfterFreeBB);
469
470 // No longer need old terminator.
471 InsertPt->eraseFromParent();
472 CGF.Builder.SetInsertPoint(AfterFreeBB);
473 }
474 explicit CallCoroDelete(Stmt *DeallocStmt) : Deallocate(DeallocStmt) {}
475};
476}
477
478namespace {
479struct GetReturnObjectManager {
480 CodeGenFunction &CGF;
481 CGBuilderTy &Builder;
482 const CoroutineBodyStmt &S;
483 // When true, performs RVO for the return object.
484 bool DirectEmit = false;
485
486 Address GroActiveFlag;
487 CodeGenFunction::AutoVarEmission GroEmission;
488
489 GetReturnObjectManager(CodeGenFunction &CGF, const CoroutineBodyStmt &S)
490 : CGF(CGF), Builder(CGF.Builder), S(S), GroActiveFlag(Address::invalid()),
491 GroEmission(CodeGenFunction::AutoVarEmission::invalid()) {
492 // The call to get_­return_­object is sequenced before the call to
493 // initial_­suspend and is invoked at most once, but there are caveats
494 // regarding on whether the prvalue result object may be initialized
495 // directly/eager or delayed, depending on the types involved.
496 //
497 // More info at https://github.com/cplusplus/papers/issues/1414
498 //
499 // The general cases:
500 // 1. Same type of get_return_object and coroutine return type (direct
501 // emission):
502 // - Constructed in the return slot.
503 // 2. Different types (delayed emission):
504 // - Constructed temporary object prior to initial suspend initialized with
505 // a call to get_return_object()
506 // - When coroutine needs to to return to the caller and needs to construct
507 // return value for the coroutine it is initialized with expiring value of
508 // the temporary obtained above.
509 //
510 // Direct emission for void returning coroutines or GROs.
511 DirectEmit = [&]() {
512 auto *RVI = S.getReturnValueInit();
513 assert(RVI && "expected RVI");
514 auto GroType = RVI->getType();
515 return CGF.getContext().hasSameType(GroType, CGF.FnRetTy);
516 }();
517 }
518
519 // The gro variable has to outlive coroutine frame and coroutine promise, but,
520 // it can only be initialized after coroutine promise was created, thus, we
521 // split its emission in two parts. EmitGroAlloca emits an alloca and sets up
522 // cleanups. Later when coroutine promise is available we initialize the gro
523 // and sets the flag that the cleanup is now active.
524 void EmitGroAlloca() {
525 if (DirectEmit)
526 return;
527
528 auto *GroDeclStmt = dyn_cast_or_null<DeclStmt>(S.getResultDecl());
529 if (!GroDeclStmt) {
530 // If get_return_object returns void, no need to do an alloca.
531 return;
532 }
533
534 auto *GroVarDecl = cast<VarDecl>(GroDeclStmt->getSingleDecl());
535
536 // Set GRO flag that it is not initialized yet
537 GroActiveFlag = CGF.CreateTempAlloca(Builder.getInt1Ty(), CharUnits::One(),
538 "gro.active");
539 Builder.CreateStore(Builder.getFalse(), GroActiveFlag);
540
541 GroEmission = CGF.EmitAutoVarAlloca(*GroVarDecl);
542 auto *GroAlloca = dyn_cast_or_null<llvm::AllocaInst>(
543 GroEmission.getOriginalAllocatedAddress().getPointer());
544 assert(GroAlloca && "expected alloca to be emitted");
545 GroAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,
546 llvm::MDNode::get(CGF.CGM.getLLVMContext(), {}));
547
548 // Remember the top of EHStack before emitting the cleanup.
549 auto old_top = CGF.EHStack.stable_begin();
550 CGF.EmitAutoVarCleanups(GroEmission);
551 auto top = CGF.EHStack.stable_begin();
552
553 // Make the cleanup conditional on gro.active
554 for (auto b = CGF.EHStack.find(top), e = CGF.EHStack.find(old_top); b != e;
555 b++) {
556 if (auto *Cleanup = dyn_cast<EHCleanupScope>(&*b)) {
557 assert(!Cleanup->hasActiveFlag() && "cleanup already has active flag?");
558 Cleanup->setActiveFlag(GroActiveFlag);
559 Cleanup->setTestFlagInEHCleanup();
560 Cleanup->setTestFlagInNormalCleanup();
561 }
562 }
563 }
564
565 void EmitGroInit() {
566 if (DirectEmit) {
567 // ReturnValue should be valid as long as the coroutine's return type
568 // is not void. The assertion could help us to reduce the check later.
569 assert(CGF.ReturnValue.isValid() == (bool)S.getReturnStmt());
570 // Now we have the promise, initialize the GRO.
571 // We need to emit `get_return_object` first. According to:
572 // [dcl.fct.def.coroutine]p7
573 // The call to get_return_­object is sequenced before the call to
574 // initial_suspend and is invoked at most once.
575 //
576 // So we couldn't emit return value when we emit return statment,
577 // otherwise the call to get_return_object wouldn't be in front
578 // of initial_suspend.
579 if (CGF.ReturnValue.isValid()) {
580 CGF.EmitAnyExprToMem(S.getReturnValue(), CGF.ReturnValue,
581 S.getReturnValue()->getType().getQualifiers(),
582 /*IsInit*/ true);
583 }
584 return;
585 }
586
587 if (!GroActiveFlag.isValid()) {
588 // No Gro variable was allocated. Simply emit the call to
589 // get_return_object.
590 CGF.EmitStmt(S.getResultDecl());
591 return;
592 }
593
594 CGF.EmitAutoVarInit(GroEmission);
595 Builder.CreateStore(Builder.getTrue(), GroActiveFlag);
596 }
597};
598} // namespace
599
601 const CoroutineBodyStmt &S, Stmt *Body) {
602 CGF.EmitStmt(Body);
603 const bool CanFallthrough = CGF.Builder.GetInsertBlock();
604 if (CanFallthrough)
605 if (Stmt *OnFallthrough = S.getFallthroughHandler())
606 CGF.EmitStmt(OnFallthrough);
607}
608
610 auto *NullPtr = llvm::ConstantPointerNull::get(Builder.getPtrTy());
611 auto &TI = CGM.getContext().getTargetInfo();
612 unsigned NewAlign = TI.getNewAlign() / TI.getCharWidth();
613
614 auto *EntryBB = Builder.GetInsertBlock();
615 auto *AllocBB = createBasicBlock("coro.alloc");
616 auto *InitBB = createBasicBlock("coro.init");
617 auto *FinalBB = createBasicBlock("coro.final");
618 auto *RetBB = createBasicBlock("coro.ret");
619
620 auto *CoroId = Builder.CreateCall(
621 CGM.getIntrinsic(llvm::Intrinsic::coro_id),
622 {Builder.getInt32(NewAlign), NullPtr, NullPtr, NullPtr});
623 createCoroData(*this, CurCoro, CoroId);
624 CurCoro.Data->SuspendBB = RetBB;
625 assert(ShouldEmitLifetimeMarkers &&
626 "Must emit lifetime intrinsics for coroutines");
627
628 // Backend is allowed to elide memory allocations, to help it, emit
629 // auto mem = coro.alloc() ? 0 : ... allocation code ...;
630 auto *CoroAlloc = Builder.CreateCall(
631 CGM.getIntrinsic(llvm::Intrinsic::coro_alloc), {CoroId});
632
633 Builder.CreateCondBr(CoroAlloc, AllocBB, InitBB);
634
635 EmitBlock(AllocBB);
636 auto *AllocateCall = EmitScalarExpr(S.getAllocate());
637 auto *AllocOrInvokeContBB = Builder.GetInsertBlock();
638
639 // Handle allocation failure if 'ReturnStmtOnAllocFailure' was provided.
640 if (auto *RetOnAllocFailure = S.getReturnStmtOnAllocFailure()) {
641 auto *RetOnFailureBB = createBasicBlock("coro.ret.on.failure");
642
643 // See if allocation was successful.
644 auto *NullPtr = llvm::ConstantPointerNull::get(Int8PtrTy);
645 auto *Cond = Builder.CreateICmpNE(AllocateCall, NullPtr);
646 // Expect the allocation to be successful.
647 emitCondLikelihoodViaExpectIntrinsic(Cond, Stmt::LH_Likely);
648 Builder.CreateCondBr(Cond, InitBB, RetOnFailureBB);
649
650 // If not, return OnAllocFailure object.
651 EmitBlock(RetOnFailureBB);
652 EmitStmt(RetOnAllocFailure);
653 }
654 else {
655 Builder.CreateBr(InitBB);
656 }
657
658 EmitBlock(InitBB);
659
660 // Pass the result of the allocation to coro.begin.
661 auto *Phi = Builder.CreatePHI(VoidPtrTy, 2);
662 Phi->addIncoming(NullPtr, EntryBB);
663 Phi->addIncoming(AllocateCall, AllocOrInvokeContBB);
664 auto *CoroBegin = Builder.CreateCall(
665 CGM.getIntrinsic(llvm::Intrinsic::coro_begin), {CoroId, Phi});
666 CurCoro.Data->CoroBegin = CoroBegin;
667
668 GetReturnObjectManager GroManager(*this, S);
669 GroManager.EmitGroAlloca();
670
671 CurCoro.Data->CleanupJD = getJumpDestInCurrentScope(RetBB);
672 {
674 ParamReferenceReplacerRAII ParamReplacer(LocalDeclMap);
675 CodeGenFunction::RunCleanupsScope ResumeScope(*this);
676 EHStack.pushCleanup<CallCoroDelete>(NormalAndEHCleanup, S.getDeallocate());
677
678 // Create mapping between parameters and copy-params for coroutine function.
679 llvm::ArrayRef<const Stmt *> ParamMoves = S.getParamMoves();
680 assert(
681 (ParamMoves.size() == 0 || (ParamMoves.size() == FnArgs.size())) &&
682 "ParamMoves and FnArgs should be the same size for coroutine function");
683 if (ParamMoves.size() == FnArgs.size() && DI)
684 for (const auto Pair : llvm::zip(FnArgs, ParamMoves))
686 {std::get<0>(Pair), std::get<1>(Pair)});
687
688 // Create parameter copies. We do it before creating a promise, since an
689 // evolution of coroutine TS may allow promise constructor to observe
690 // parameter copies.
691 for (auto *PM : S.getParamMoves()) {
692 EmitStmt(PM);
693 ParamReplacer.addCopy(cast<DeclStmt>(PM));
694 // TODO: if(CoroParam(...)) need to surround ctor and dtor
695 // for the copy, so that llvm can elide it if the copy is
696 // not needed.
697 }
698
699 EmitStmt(S.getPromiseDeclStmt());
700
701 Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
702 auto *PromiseAddrVoidPtr =
703 new llvm::BitCastInst(PromiseAddr.getPointer(), VoidPtrTy, "", CoroId);
704 // Update CoroId to refer to the promise. We could not do it earlier because
705 // promise local variable was not emitted yet.
706 CoroId->setArgOperand(1, PromiseAddrVoidPtr);
707
708 // Now we have the promise, initialize the GRO
709 GroManager.EmitGroInit();
710
711 EHStack.pushCleanup<CallCoroEnd>(EHCleanup);
712
713 CurCoro.Data->CurrentAwaitKind = AwaitKind::Init;
714 CurCoro.Data->ExceptionHandler = S.getExceptionHandler();
715 EmitStmt(S.getInitSuspendStmt());
716 CurCoro.Data->FinalJD = getJumpDestInCurrentScope(FinalBB);
717
718 CurCoro.Data->CurrentAwaitKind = AwaitKind::Normal;
719
720 if (CurCoro.Data->ExceptionHandler) {
721 // If we generated IR to record whether an exception was thrown from
722 // 'await_resume', then use that IR to determine whether the coroutine
723 // body should be skipped.
724 // If we didn't generate the IR (perhaps because 'await_resume' was marked
725 // as 'noexcept'), then we skip this check.
726 BasicBlock *ContBB = nullptr;
727 if (CurCoro.Data->ResumeEHVar) {
728 BasicBlock *BodyBB = createBasicBlock("coro.resumed.body");
729 ContBB = createBasicBlock("coro.resumed.cont");
730 Value *SkipBody = Builder.CreateFlagLoad(CurCoro.Data->ResumeEHVar,
731 "coro.resumed.eh");
732 Builder.CreateCondBr(SkipBody, ContBB, BodyBB);
733 EmitBlock(BodyBB);
734 }
735
736 auto Loc = S.getBeginLoc();
737 CXXCatchStmt Catch(Loc, /*exDecl=*/nullptr,
738 CurCoro.Data->ExceptionHandler);
739 auto *TryStmt =
740 CXXTryStmt::Create(getContext(), Loc, S.getBody(), &Catch);
741
742 EnterCXXTryStmt(*TryStmt);
743 emitBodyAndFallthrough(*this, S, TryStmt->getTryBlock());
744 ExitCXXTryStmt(*TryStmt);
745
746 if (ContBB)
747 EmitBlock(ContBB);
748 }
749 else {
750 emitBodyAndFallthrough(*this, S, S.getBody());
751 }
752
753 // See if we need to generate final suspend.
754 const bool CanFallthrough = Builder.GetInsertBlock();
755 const bool HasCoreturns = CurCoro.Data->CoreturnCount > 0;
756 if (CanFallthrough || HasCoreturns) {
757 EmitBlock(FinalBB);
758 CurCoro.Data->CurrentAwaitKind = AwaitKind::Final;
759 EmitStmt(S.getFinalSuspendStmt());
760 } else {
761 // We don't need FinalBB. Emit it to make sure the block is deleted.
762 EmitBlock(FinalBB, /*IsFinished=*/true);
763 }
764 }
765
766 EmitBlock(RetBB);
767 // Emit coro.end before getReturnStmt (and parameter destructors), since
768 // resume and destroy parts of the coroutine should not include them.
769 llvm::Function *CoroEnd = CGM.getIntrinsic(llvm::Intrinsic::coro_end);
770 Builder.CreateCall(CoroEnd,
771 {NullPtr, Builder.getFalse(),
772 llvm::ConstantTokenNone::get(CoroEnd->getContext())});
773
774 if (Stmt *Ret = S.getReturnStmt()) {
775 // Since we already emitted the return value above, so we shouldn't
776 // emit it again here.
777 if (GroManager.DirectEmit)
778 cast<ReturnStmt>(Ret)->setRetValue(nullptr);
779 EmitStmt(Ret);
780 }
781
782 // LLVM require the frontend to mark the coroutine.
783 CurFn->setPresplitCoroutine();
784
786 RD && RD->hasAttr<CoroOnlyDestroyWhenCompleteAttr>())
787 CurFn->setCoroDestroyOnlyWhenComplete();
788}
789
790// Emit coroutine intrinsic and patch up arguments of the token type.
792 unsigned int IID) {
794 switch (IID) {
795 default:
796 break;
797 // The coro.frame builtin is replaced with an SSA value of the coro.begin
798 // intrinsic.
799 case llvm::Intrinsic::coro_frame: {
800 if (CurCoro.Data && CurCoro.Data->CoroBegin) {
801 return RValue::get(CurCoro.Data->CoroBegin);
802 }
803 CGM.Error(E->getBeginLoc(), "this builtin expect that __builtin_coro_begin "
804 "has been used earlier in this function");
805 auto *NullPtr = llvm::ConstantPointerNull::get(Builder.getPtrTy());
806 return RValue::get(NullPtr);
807 }
808 case llvm::Intrinsic::coro_size: {
809 auto &Context = getContext();
810 CanQualType SizeTy = Context.getSizeType();
811 llvm::IntegerType *T = Builder.getIntNTy(Context.getTypeSize(SizeTy));
812 llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::coro_size, T);
813 return RValue::get(Builder.CreateCall(F));
814 }
815 case llvm::Intrinsic::coro_align: {
816 auto &Context = getContext();
817 CanQualType SizeTy = Context.getSizeType();
818 llvm::IntegerType *T = Builder.getIntNTy(Context.getTypeSize(SizeTy));
819 llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::coro_align, T);
820 return RValue::get(Builder.CreateCall(F));
821 }
822 // The following three intrinsics take a token parameter referring to a token
823 // returned by earlier call to @llvm.coro.id. Since we cannot represent it in
824 // builtins, we patch it up here.
825 case llvm::Intrinsic::coro_alloc:
826 case llvm::Intrinsic::coro_begin:
827 case llvm::Intrinsic::coro_free: {
828 if (CurCoro.Data && CurCoro.Data->CoroId) {
829 Args.push_back(CurCoro.Data->CoroId);
830 break;
831 }
832 CGM.Error(E->getBeginLoc(), "this builtin expect that __builtin_coro_id has"
833 " been used earlier in this function");
834 // Fallthrough to the next case to add TokenNone as the first argument.
835 [[fallthrough]];
836 }
837 // @llvm.coro.suspend takes a token parameter. Add token 'none' as the first
838 // argument.
839 case llvm::Intrinsic::coro_suspend:
840 Args.push_back(llvm::ConstantTokenNone::get(getLLVMContext()));
841 break;
842 }
843 for (const Expr *Arg : E->arguments())
844 Args.push_back(EmitScalarExpr(Arg));
845 // @llvm.coro.end takes a token parameter. Add token 'none' as the last
846 // argument.
847 if (IID == llvm::Intrinsic::coro_end)
848 Args.push_back(llvm::ConstantTokenNone::get(getLLVMContext()));
849
850 llvm::Function *F = CGM.getIntrinsic(IID);
851 llvm::CallInst *Call = Builder.CreateCall(F, Args);
852
853 // Note: The following code is to enable to emit coro.id and coro.begin by
854 // hand to experiment with coroutines in C.
855 // If we see @llvm.coro.id remember it in the CoroData. We will update
856 // coro.alloc, coro.begin and coro.free intrinsics to refer to it.
857 if (IID == llvm::Intrinsic::coro_id) {
858 createCoroData(*this, CurCoro, Call, E);
859 }
860 else if (IID == llvm::Intrinsic::coro_begin) {
861 if (CurCoro.Data)
862 CurCoro.Data->CoroBegin = Call;
863 }
864 else if (IID == llvm::Intrinsic::coro_free) {
865 // Remember the last coro_free as we need it to build the conditional
866 // deletion of the coroutine frame.
867 if (CurCoro.Data)
868 CurCoro.Data->LastCoroFree = Call;
869 }
870 return RValue::get(Call);
871}
static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Coro, CoroutineSuspendExpr const &S, AwaitKind Kind, AggValueSlot aggSlot, bool ignoreResult, bool forLValue)
static bool memberCallExpressionCanThrow(const Expr *E)
static SmallString< 32 > buildSuspendPrefixStr(CGCoroData &Coro, AwaitKind Kind)
static QualType getCoroutineSuspendExprReturnType(const ASTContext &Ctx, const CoroutineSuspendExpr *E)
static void createCoroData(CodeGenFunction &CGF, CodeGenFunction::CGCoroInfo &CurCoro, llvm::CallInst *CoroId, CallExpr const *CoroIdExpr=nullptr)
Definition: CGCoroutine.cpp:89
static void emitBodyAndFallthrough(CodeGenFunction &CGF, const CoroutineBodyStmt &S, Stmt *Body)
static SmallVector< llvm::OperandBundleDef, 1 > getBundlesForCoroEnd(CodeGenFunction &CGF)
__device__ __2f16 b
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2551
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2307
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:749
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:25
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2847
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1608
arg_range arguments()
Definition: Expr.h:3086
static CharUnits One()
One - Construct a CharUnits quantity of one.
Definition: CharUnits.h:58
Represents a 'co_await' expression.
Definition: ExprCXX.h:5037
An aligned address.
Definition: Address.h:29
llvm::Value * getPointer() const
Definition: Address.h:51
bool isValid() const
Definition: Address.h:47
An aggregate value slot.
Definition: CGValue.h:512
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
Definition: CGValue.h:580
llvm::StoreInst * CreateFlagStore(bool Value, llvm::Value *Addr)
Emit a store to an i1 flag variable.
Definition: CGBuilder.h:125
llvm::LoadInst * CreateFlagLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Emit a load from an i1 flag variable.
Definition: CGBuilder.h:119
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:55
ParamDecl2StmtTy & getCoroutineParameterMappings()
Definition: CGDebugInfo.h:607
static OpaqueValueMappingData bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const Expr *e)
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
LValue EmitCoawaitLValue(const CoawaitExpr *E)
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
llvm::BasicBlock * getEHResumeBlock(bool isCleanup)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
void EmitAutoVarInit(const AutoVarEmission &emission)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
LValue EmitCoyieldLValue(const CoyieldExpr *E)
RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID)
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
void EmitCoroutineBody(const CoroutineBodyStmt &S)
void EmitBranchThroughCleanup(JumpDest Dest)
EmitBranchThroughCleanup - Emit a branch from the current insert block through the normal cleanup han...
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
void EmitAutoVarCleanups(const AutoVarEmission &emission)
llvm::SmallVector< const ParmVarDecl *, 4 > FnArgs
Save Parameter Decl for coroutine.
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
void EmitCoreturnStmt(const CoreturnStmt &S)
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock=false)
llvm::Instruction * CurrentFuncletPad
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs=std::nullopt)
EmitStmt - Emit the code for the statement.
llvm::LLVMContext & getLLVMContext()
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
ASTContext & getContext() const
llvm::LLVMContext & getLLVMContext()
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
Information for lazily generating a cleanup.
Definition: EHScopeStack.h:141
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
Definition: EHScopeStack.h:393
iterator find(stable_iterator save) const
Turn a stable reference to a scope depth into a unstable pointer to the EH stack.
Definition: CGCleanup.h:575
LValue - This represents an lvalue references.
Definition: CGValue.h:171
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
static RValue getIgnored()
Definition: CGValue.h:84
static RValue get(llvm::Value *V)
Definition: CGValue.h:89
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:382
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition: StmtCXX.h:473
Represents the body of a coroutine.
Definition: StmtCXX.h:320
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Definition: ExprCXX.h:4944
Expr * getResumeExpr() const
Definition: ExprCXX.h:5005
Represents a 'co_yield' expression.
Definition: ExprCXX.h:5118
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1248
ValueDecl * getDecl()
Definition: Expr.h:1316
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1493
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
Definition: Stmt.h:1506
const Decl * getSingleDecl() const
Definition: Stmt.h:1508
bool hasAttr() const
Definition: DeclBase.h:581
This represents one expression.
Definition: Expr.h:110
QualType getType() const
Definition: Expr.h:142
Represents difference between two FPOptions values.
Definition: LangOptions.h:829
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4160
A (possibly-)qualified type.
Definition: Type.h:736
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:184
Stmt - This represents one statement.
Definition: Stmt.h:84
@ LH_Likely
Branch has the [[likely]] attribute.
Definition: Stmt.h:1301
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with '::operator new(size_t)' is g...
Definition: TargetInfo.h:716
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1819
bool isVoidType() const
Definition: Type.h:7352
Represents a variable declaration or definition.
Definition: Decl.h:916
const Expr * getInit() const
Definition: Decl.h:1350
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
Definition: EHScopeStack.h:80
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
CodeGenFunction::JumpDest FinalJD
Definition: CGCoroutine.cpp:62
CallExpr const * CoroIdExpr
Definition: CGCoroutine.cpp:82
CodeGenFunction::JumpDest CleanupJD
Definition: CGCoroutine.cpp:58
llvm::BasicBlock * SuspendBB
Definition: CGCoroutine.cpp:44
llvm::CallInst * CoroId
Definition: CGCoroutine.cpp:68
llvm::CallInst * CoroBegin
Definition: CGCoroutine.cpp:73
llvm::CallInst * LastCoroFree
Definition: CGCoroutine.cpp:77
A jump destination is an abstract label, branching to which may require a jump out through normal cle...