Skip to content

Commit 6e6328d

Browse files
authored
Merge pull request #80882 from eeckstein/fix-warning
IRGen: fix a compiler warning
2 parents 5762912 + db65f2f commit 6e6328d

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,40 @@ CanType irgen::getArgumentLoweringType(CanType type, SILParameterInfo paramInfo,
862862
llvm_unreachable("unhandled convention");
863863
}
864864

865+
llvm::Constant *irgen::getCoroFrameAllocStubFn(IRGenModule &IGM) {
866+
return IGM.getOrCreateHelperFunction(
867+
"__swift_coroFrameAllocStub", IGM.Int8PtrTy,
868+
{IGM.SizeTy, IGM.Int64Ty},
869+
[&](IRGenFunction &IGF) {
870+
auto parameters = IGF.collectParameters();
871+
auto *size = parameters.claimNext();
872+
auto coroAllocPtr = IGF.IGM.getCoroFrameAllocFn();
873+
auto coroAllocFn = dyn_cast<llvm::Function>(coroAllocPtr);
874+
coroAllocFn->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
875+
auto *coroFrameAllocFn = IGF.IGM.getOpaquePtr(coroAllocPtr);
876+
auto *nullSwiftCoroFrameAlloc = IGF.Builder.CreateCmp(
877+
llvm::CmpInst::Predicate::ICMP_NE, coroFrameAllocFn,
878+
llvm::ConstantPointerNull::get(
879+
cast<llvm::PointerType>(coroFrameAllocFn->getType())));
880+
auto *coroFrameAllocReturn = IGF.createBasicBlock("return-coroFrameAlloc");
881+
auto *mallocReturn = IGF.createBasicBlock("return-malloc");
882+
IGF.Builder.CreateCondBr(nullSwiftCoroFrameAlloc, coroFrameAllocReturn, mallocReturn);
883+
884+
IGF.Builder.emitBlock(coroFrameAllocReturn);
885+
auto *mallocTypeId = parameters.claimNext();
886+
auto *coroFrameAllocCall = IGF.Builder.CreateCall(IGF.IGM.getCoroFrameAllocFunctionPointer(), {size, mallocTypeId});
887+
IGF.Builder.CreateRet(coroFrameAllocCall);
888+
889+
IGF.Builder.emitBlock(mallocReturn);
890+
auto *mallocCall = IGF.Builder.CreateCall(IGF.IGM.getMallocFunctionPointer(), {size});
891+
IGF.Builder.CreateRet(mallocCall);
892+
},
893+
/*setIsNoInline=*/false,
894+
/*forPrologue=*/false,
895+
/*isPerformanceConstraint=*/false,
896+
/*optionalLinkageOverride=*/nullptr, llvm::CallingConv::C);
897+
}
898+
865899
static Size getOffsetOfOpaqueIsolationField(IRGenModule &IGM,
866900
const LoadableTypeInfo &isolationTI) {
867901
auto offset = IGM.RefCountedStructSize;

lib/IRGen/GenFunc.h

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,39 +64,7 @@ namespace irgen {
6464

6565
/// Stub function that weakly links againt the swift_coroFrameAlloc
6666
/// function. This is required for back-deployment.
67-
static llvm::Constant *getCoroFrameAllocStubFn(IRGenModule &IGM) {
68-
return IGM.getOrCreateHelperFunction(
69-
"__swift_coroFrameAllocStub", IGM.Int8PtrTy,
70-
{IGM.SizeTy, IGM.Int64Ty},
71-
[&](IRGenFunction &IGF) {
72-
auto parameters = IGF.collectParameters();
73-
auto *size = parameters.claimNext();
74-
auto coroAllocPtr = IGF.IGM.getCoroFrameAllocFn();
75-
auto coroAllocFn = dyn_cast<llvm::Function>(coroAllocPtr);
76-
coroAllocFn->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
77-
auto *coroFrameAllocFn = IGF.IGM.getOpaquePtr(coroAllocPtr);
78-
auto *nullSwiftCoroFrameAlloc = IGF.Builder.CreateCmp(
79-
llvm::CmpInst::Predicate::ICMP_NE, coroFrameAllocFn,
80-
llvm::ConstantPointerNull::get(
81-
cast<llvm::PointerType>(coroFrameAllocFn->getType())));
82-
auto *coroFrameAllocReturn = IGF.createBasicBlock("return-coroFrameAlloc");
83-
auto *mallocReturn = IGF.createBasicBlock("return-malloc");
84-
IGF.Builder.CreateCondBr(nullSwiftCoroFrameAlloc, coroFrameAllocReturn, mallocReturn);
85-
86-
IGF.Builder.emitBlock(coroFrameAllocReturn);
87-
auto *mallocTypeId = parameters.claimNext();
88-
auto *coroFrameAllocCall = IGF.Builder.CreateCall(IGF.IGM.getCoroFrameAllocFunctionPointer(), {size, mallocTypeId});
89-
IGF.Builder.CreateRet(coroFrameAllocCall);
90-
91-
IGF.Builder.emitBlock(mallocReturn);
92-
auto *mallocCall = IGF.Builder.CreateCall(IGF.IGM.getMallocFunctionPointer(), {size});
93-
IGF.Builder.CreateRet(mallocCall);
94-
},
95-
/*setIsNoInline=*/false,
96-
/*forPrologue=*/false,
97-
/*isPerformanceConstraint=*/false,
98-
/*optionalLinkageOverride=*/nullptr, llvm::CallingConv::C);
99-
}
67+
llvm::Constant *getCoroFrameAllocStubFn(IRGenModule &IGM);
10068
} // end namespace irgen
10169
} // end namespace swift
10270

0 commit comments

Comments
 (0)