Skip to content

Commit 90b5195

Browse files
authored
Merge pull request #3334 from swiftwasm/katei/cherry-pick-81751d916802dd6c0f9bbff32a0f902f1bae5d14
2 parents 8833463 + 79ea4ce commit 90b5195

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
@@ -233,7 +233,22 @@ class GettablePropertyProjector : public ComponentProjector {
233233
assert(getter->getConventions().getNumSILArguments());
234234

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

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

0 commit comments

Comments
 (0)