@@ -78,9 +78,21 @@ static bool performTransform(SILFunction &fn) {
78
78
auto subMap =
79
79
astType->getContextSubstitutionMap (nom->getModuleContext (), nom);
80
80
SILBuilderWithScope builder (dvi);
81
+
82
+ SILValue value = dvi->getOperand ();
83
+ auto conv = deinitFunc->getConventionsInContext ();
84
+ if (conv.getSILArgumentConvention (conv.getSILArgIndexOfSelf ())
85
+ .isIndirectConvention ()) {
86
+ auto *asi =
87
+ builder.createAllocStack (dvi->getLoc (), value->getType ());
88
+ builder.emitStoreValueOperation (dvi->getLoc (), value, asi,
89
+ StoreOwnershipQualifier::Init);
90
+ value = asi;
91
+ }
81
92
auto *funcRef = builder.createFunctionRef (dvi->getLoc (), deinitFunc);
82
- builder.createApply (dvi->getLoc (), funcRef, subMap,
83
- dvi->getOperand ());
93
+ builder.createApply (dvi->getLoc (), funcRef, subMap, value);
94
+ if (isa<AllocStackInst>(value))
95
+ builder.createDeallocStack (dvi->getLoc (), value);
84
96
dvi->eraseFromParent ();
85
97
changed = true ;
86
98
continue ;
@@ -105,9 +117,15 @@ static bool performTransform(SILFunction &fn) {
105
117
auto *funcRef = builder.createFunctionRef (dai->getLoc (), deinitFunc);
106
118
auto subMap = destroyType.getASTType ()->getContextSubstitutionMap (
107
119
nom->getModuleContext (), nom);
108
- auto loadedValue = builder.emitLoadValueOperation (
109
- dai->getLoc (), dai->getOperand (), LoadOwnershipQualifier::Take);
110
- builder.createApply (dai->getLoc (), funcRef, subMap, loadedValue);
120
+
121
+ auto conv = deinitFunc->getConventionsInContext ();
122
+ auto argConv =
123
+ conv.getSILArgumentConvention (conv.getSILArgIndexOfSelf ());
124
+ SILValue value = dai->getOperand ();
125
+ if (!argConv.isIndirectConvention ())
126
+ value = builder.emitLoadValueOperation (
127
+ dai->getLoc (), dai->getOperand (), LoadOwnershipQualifier::Take);
128
+ builder.createApply (dai->getLoc (), funcRef, subMap, value);
111
129
dai->eraseFromParent ();
112
130
changed = true ;
113
131
continue ;
0 commit comments