Skip to content

Commit c496c2a

Browse files
nate-chandlerbnbarham
authored andcommitted
[NFC] Coro: Re-cover this switch.
It became uncovered in swiftlang#10120 . Fix that here. (cherry picked from commit 82d3bcd)
1 parent 81e60e2 commit c496c2a

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

llvm/lib/Transforms/Coroutines/Coroutines.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -523,39 +523,38 @@ static void addCallToCallGraph(CallGraph *CG, CallInst *Call, Function *Callee){
523523

524524
Value *coro::Shape::emitAlloc(IRBuilder<> &Builder, Value *Size,
525525
CallGraph *CG) const {
526-
unsigned sizeParamIndex = UINT_MAX;
527526
switch (ABI) {
528527
case coro::ABI::Switch:
529528
llvm_unreachable("can't allocate memory in coro switch-lowering");
530529

531530
case coro::ABI::Retcon:
532531
case coro::ABI::RetconOnce:
533-
sizeParamIndex = 0;
534-
break;
535-
case coro::ABI::RetconOnceDynamic:
536-
sizeParamIndex = 1;
537-
break;
532+
case coro::ABI::RetconOnceDynamic: {
533+
unsigned sizeParamIndex = 0;
534+
SmallVector<Value *, 2> Args;
535+
if (ABI == coro::ABI::RetconOnceDynamic) {
536+
sizeParamIndex = 1;
537+
Args.push_back(RetconLowering.Allocator);
538+
}
539+
auto Alloc = RetconLowering.Alloc;
540+
Size = Builder.CreateIntCast(
541+
Size, Alloc->getFunctionType()->getParamType(sizeParamIndex),
542+
/*is signed*/ false);
543+
Args.push_back(Size);
544+
if (ABI == coro::ABI::RetconOnce) {
545+
ConstantInt *TypeId = RetconLowering.TypeId;
546+
if (TypeId != nullptr)
547+
Args.push_back(TypeId);
548+
}
549+
auto *Call = Builder.CreateCall(Alloc, Args);
550+
propagateCallAttrsFromCallee(Call, Alloc);
551+
addCallToCallGraph(CG, Call, Alloc);
552+
return Call;
553+
}
538554
case coro::ABI::Async:
539555
llvm_unreachable("can't allocate memory in coro async-lowering");
540556
}
541-
auto Alloc = RetconLowering.Alloc;
542-
Size = Builder.CreateIntCast(
543-
Size, Alloc->getFunctionType()->getParamType(sizeParamIndex),
544-
/*is signed*/ false);
545-
SmallVector<Value *, 2> Args;
546-
if (ABI == coro::ABI::RetconOnceDynamic) {
547-
Args.push_back(RetconLowering.Allocator);
548-
}
549-
Args.push_back(Size);
550-
if (ABI == coro::ABI::RetconOnce) {
551-
ConstantInt *TypeId = RetconLowering.TypeId;
552-
if (TypeId != nullptr)
553-
Args.push_back(TypeId);
554-
}
555-
auto *Call = Builder.CreateCall(Alloc, Args);
556-
propagateCallAttrsFromCallee(Call, Alloc);
557-
addCallToCallGraph(CG, Call, Alloc);
558-
return Call;
557+
llvm_unreachable("Unknown coro::ABI enum");
559558
}
560559

561560
void coro::Shape::emitDealloc(IRBuilder<> &Builder, Value *Ptr,

0 commit comments

Comments
 (0)