Skip to content

Commit e68c766

Browse files
committed
Use IRGenFunction::coerceValue suggested by @aschwaighofer.
1 parent 31dc5d7 commit e68c766

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,20 +1244,8 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
12441244
// cast to the result type - it could be substituted.
12451245
if (origConv.getSILResultType().hasTypeParameter()) {
12461246
auto ResType = fwd->getReturnType();
1247-
if (auto *structType = dyn_cast<llvm::StructType>(ResType)) {
1248-
// Cast all struct elements to the desired type.
1249-
llvm::Value *castResult = llvm::UndefValue::get(structType);
1250-
for (auto i : range(structType->getStructNumElements())) {
1251-
auto desiredEltTy = structType->getElementType(i);
1252-
auto elt = subIGF.Builder.CreateExtractValue(callResult, {i});
1253-
auto castElt = subIGF.Builder.CreateBitCast(elt, desiredEltTy);
1254-
castResult =
1255-
subIGF.Builder.CreateInsertValue(castResult, castElt, {i});
1256-
}
1257-
callResult = castResult;
1258-
}
1259-
else
1260-
callResult = subIGF.Builder.CreateBitCast(callResult, ResType);
1247+
if (ResType != callResult->getType())
1248+
callResult = subIGF.coerceValue(callResult, ResType, subIGF.IGM.DataLayout);
12611249
}
12621250
subIGF.Builder.CreateRet(callResult);
12631251
}

0 commit comments

Comments
 (0)