Skip to content

Commit 158ec12

Browse files
committed
IRGen: Forward return value from equals/hash helpers when thunking generic helpers.
1 parent c1fcfa0 commit 158ec12

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ getAccessorForComputedComponent(IRGenModule &IGM,
111111
return accessorFn;
112112
}
113113

114-
auto accessorFnTy = accessorFn->getType()->getPointerElementType();
114+
auto accessorFnTy = cast<llvm::FunctionType>(
115+
accessorFn->getType()->getPointerElementType());;
115116

116117
// Otherwise, we need a thunk to unmarshal the generic environment from the
117118
// argument area. It'd be nice to have a good way to represent this
@@ -140,7 +141,7 @@ getAccessorForComputedComponent(IRGenModule &IGM,
140141

141142
SmallVector<llvm::Type *, 4> thunkParams;
142143
for (unsigned i = 0; i < numArgsToForward; ++i)
143-
thunkParams.push_back(accessorFnTy->getFunctionParamType(i));
144+
thunkParams.push_back(accessorFnTy->getParamType(i));
144145

145146
switch (whichAccessor) {
146147
case Getter:
@@ -153,7 +154,8 @@ getAccessorForComputedComponent(IRGenModule &IGM,
153154
}
154155
thunkParams.push_back(IGM.SizeTy);
155156

156-
auto thunkType = llvm::FunctionType::get(IGM.VoidTy, thunkParams,
157+
auto thunkType = llvm::FunctionType::get(accessorFnTy->getReturnType(),
158+
thunkParams,
157159
/*vararg*/ false);
158160

159161
auto accessorThunk = llvm::Function::Create(thunkType,
@@ -228,9 +230,12 @@ getAccessorForComputedComponent(IRGenModule &IGM,
228230
forwardedArgs);
229231
auto fnPtr = FunctionPointer::forDirect(IGM, accessorFn,
230232
accessor->getLoweredFunctionType());
231-
IGF.Builder.CreateCall(fnPtr, forwardedArgs.claimAll());
233+
auto call = IGF.Builder.CreateCall(fnPtr, forwardedArgs.claimAll());
232234

233-
IGF.Builder.CreateRetVoid();
235+
if (call->getType()->isVoidTy())
236+
IGF.Builder.CreateRetVoid();
237+
else
238+
IGF.Builder.CreateRet(call);
234239
}
235240

236241
return accessorThunk;

0 commit comments

Comments
 (0)