@@ -1868,14 +1868,14 @@ void SILGenFunction::emitAssignOrInit(SILLocation loc, ManagedValue selfValue,
1868
1868
// Emit the init accessor function partially applied to the base.
1869
1869
SILValue initFRef = emitGlobalFunctionRef (
1870
1870
loc, getAccessorDeclRef (field->getOpaqueAccessor (AccessorKind::Init)));
1871
+
1872
+ auto initTy = initFRef->getType ().castTo <SILFunctionType>();
1873
+
1871
1874
if (!substitutions.empty ()) {
1872
1875
// If there are substitutions we need to emit partial apply to
1873
1876
// apply substitutions to the init accessor reference type.
1874
- auto initTy =
1875
- initFRef->getType ().castTo <SILFunctionType>()->substGenericArgs (
1876
- SGM.M , substitutions, getTypeExpansionContext ());
1877
-
1878
- SILFunctionConventions setterConv (initTy, SGM.M );
1877
+ initTy = initTy->substGenericArgs (SGM.M , substitutions,
1878
+ getTypeExpansionContext ());
1879
1879
1880
1880
// Emit partial apply without argument to produce a substituted
1881
1881
// init accessor reference.
@@ -1885,6 +1885,20 @@ void SILGenFunction::emitAssignOrInit(SILLocation loc, ManagedValue selfValue,
1885
1885
initFRef = emitManagedRValueWithCleanup (initPAI).getValue ();
1886
1886
}
1887
1887
1888
+ // Check whether value is supposed to be passed indirectly and
1889
+ // materialize if required.
1890
+ {
1891
+ SILFunctionConventions initConv (initTy, SGM.M );
1892
+
1893
+ auto newValueArgIdx = initConv.getSILArgIndexOfFirstParam ();
1894
+ // If we need the argument in memory, materialize an address.
1895
+ if (initConv.getSILArgumentConvention (newValueArgIdx)
1896
+ .isIndirectConvention () &&
1897
+ !newValue.getType ().isAddress ()) {
1898
+ newValue = newValue.materialize (*this , loc);
1899
+ }
1900
+ }
1901
+
1888
1902
SILValue setterFRef;
1889
1903
if (auto *setter = field->getOpaqueAccessor (AccessorKind::Set)) {
1890
1904
setterFRef = emitApplyOfSetterToBase (loc, SILDeclRef (setter), selfValue,
0 commit comments