Skip to content

Commit 0317ee6

Browse files
Merge pull request #3347 from swiftwasm/katei/cherry-pick-5.5-81751d916802dd6c0f9bbff32a0f902f1bae5d14
Cherry-pick to 5.5 branch: [WASM] Fix KeyPath optimization bug around signature match
2 parents 886cd62 + 93f4461 commit 0317ee6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ getAccessorForComputedComponent(IRGenModule &IGM,
256256
forwardingSubs,
257257
&ignoreWitnessMetadata,
258258
forwardedArgs);
259+
} else if (IGM.Triple.isOSBinFormatWasm()) {
260+
// wasm: Add null swift.type pointer to match signature even when there is
261+
// no generic environment.
262+
forwardedArgs.add(llvm::ConstantPointerNull::get(IGM.TypeMetadataPtrTy));
259263
}
260264
auto fnPtr =
261265
FunctionPointer::forDirect(IGM, accessorFn, /*secondaryValue*/ nullptr,

lib/SILOptimizer/Utils/KeyPathProjector.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,22 @@ class GettablePropertyProjector : public ComponentProjector {
237237
assert(getter->getArguments().size() == 2 + target.isOSBinFormatWasm());
238238

239239
auto ref = builder.createFunctionRef(loc, getter);
240-
builder.createApply(loc, ref, subs, {addr, parentValue});
240+
241+
std::vector<SILValue> args{addr, parentValue};
242+
// FIXME(wasm): For wasm, KeyPath getter always take indices parameter
243+
// to match callee and caller signature. So need to pass stub pointer.
244+
// See also: getOrCreateKeyPathSetter and getOrCreateKeyPathGetter
245+
if (builder.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
246+
auto IntTy = SILType::getBuiltinIntegerType(32, builder.getASTContext());
247+
auto UnsafeRawPointerTy = SILType::getRawPointerType(builder.getASTContext());
248+
auto zeroVal = SILValue(builder.createIntegerLiteral(loc, IntTy, 0));
249+
auto stackBuffer = SILValue(builder.createAllocStack(loc, IntTy));
250+
builder.createStore(loc, zeroVal, stackBuffer, StoreOwnershipQualifier::Unqualified);
251+
auto nonePointer = builder.createUncheckedAddrCast(loc, stackBuffer, UnsafeRawPointerTy);
252+
args.push_back(SILValue(nonePointer));
253+
}
254+
255+
builder.createApply(loc, ref, subs, args);
241256

242257
// If we were previously accessing a class member, we're done now.
243258
insertEndAccess(beginAccess, builder);

0 commit comments

Comments
 (0)