Skip to content

Commit e7ec8c2

Browse files
committed
[Async CC] Handle contextless fn ptrs in getAsyncFunctionAndSize.
Now that AsyncFunctionPointers are destructured in getAsyncFunctionAndSize--rather than just calling through to FunctionPointer::getPointer--in order to avoid authing the same pointer-to-AsyncFunctionPointer twice in a row, that function must now also handle the case--previously handled within FunctionPointer::getPointer--where a FunctionPointer whose Kind is AsyncFunctionPointer but which has isFunctionPointerWithoutContext set to true. Here, that consideration is done.
1 parent c73e3c1 commit e7ec8c2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,12 +1867,15 @@ std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
18671867
FunctionPointer functionPointer, llvm::Value *thickContext,
18681868
std::pair<bool, bool> values, Size initialContextSize) {
18691869
assert(values.first || values.second);
1870+
assert(functionPointer.getKind() ==
1871+
FunctionPointer::KindTy::AsyncFunctionPointer);
18701872
bool emitFunction = values.first;
18711873
bool emitSize = values.second;
18721874
// TODO: This calculation should be extracted out into standalone functions
18731875
// emitted on-demand per-module to improve codesize.
18741876
switch (representation) {
18751877
case SILFunctionTypeRepresentation::Thick: {
1878+
assert(!functionPointer.useStaticContextSize());
18761879
// If the called function is thick, the size of the called function's
18771880
// async context is not statically knowable.
18781881
//
@@ -2034,17 +2037,22 @@ std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
20342037
IGF.Builder.CreateBitCast(ptr, IGF.IGM.AsyncFunctionPointerPtrTy);
20352038
llvm::Value *fn = nullptr;
20362039
if (emitFunction) {
2037-
llvm::Value *addrPtr = IGF.Builder.CreateStructGEP(afpPtr, 0);
2038-
fn = IGF.emitLoadOfRelativePointer(
2039-
Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false,
2040-
/*expectedType*/ functionPointer.getFunctionType()->getPointerTo());
2040+
if (functionPointer.useStaticContextSize()) {
2041+
fn = functionPointer.getRawPointer();
2042+
} else {
2043+
llvm::Value *addrPtr = IGF.Builder.CreateStructGEP(afpPtr, 0);
2044+
fn = IGF.emitLoadOfRelativePointer(
2045+
Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false,
2046+
/*expectedType*/ functionPointer.getFunctionType()->getPointerTo());
2047+
}
20412048
}
20422049
llvm::Value *size = nullptr;
20432050
if (emitSize) {
20442051
if (functionPointer.useStaticContextSize()) {
20452052
size = llvm::ConstantInt::get(IGF.IGM.Int32Ty,
20462053
initialContextSize.getValue());
2047-
} else {
2054+
} else {
2055+
assert(!functionPointer.useStaticContextSize());
20482056
auto *sizePtr = IGF.Builder.CreateStructGEP(afpPtr, 1);
20492057
size = IGF.Builder.CreateLoad(sizePtr, IGF.IGM.getPointerAlignment());
20502058
}

0 commit comments

Comments
 (0)