Skip to content

Commit 27e54ed

Browse files
committed
Fix missing autorelease in trampolines
1 parent e80ca10 commit 27e54ed

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/compiler.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6354,8 +6354,8 @@ export class Compiler extends DiagnosticEmitter {
63546354
var originalName = original.internalName;
63556355
var originalParameterTypes = originalSignature.parameterTypes;
63566356
var originalParameterDeclarations = original.prototype.signatureNode.parameters;
6357-
var commonReturnType = originalSignature.returnType;
6358-
var commonThisType = originalSignature.thisType;
6357+
var returnType = originalSignature.returnType;
6358+
var thisType = originalSignature.thisType;
63596359
var isInstance = original.is(CommonFlags.INSTANCE);
63606360

63616361
// arguments excl. `this`, operands incl. `this`
@@ -6386,7 +6386,7 @@ export class Compiler extends DiagnosticEmitter {
63866386
assert(operandIndex == minOperands);
63876387

63886388
// create the trampoline element
6389-
var trampolineSignature = new Signature(originalParameterTypes, commonReturnType, commonThisType);
6389+
var trampolineSignature = new Signature(originalParameterTypes, returnType, thisType);
63906390
trampolineSignature.requiredParameters = maxArguments;
63916391
trampolineSignature.parameterNames = originalSignature.parameterNames;
63926392
trampoline = new Function(
@@ -6401,7 +6401,8 @@ export class Compiler extends DiagnosticEmitter {
64016401
// compile initializers of omitted arguments in scope of the trampoline function
64026402
// this is necessary because initializers might need additional locals and a proper this context
64036403
var previousFlow = this.currentFlow;
6404-
this.currentFlow = trampoline.flow;
6404+
var flow = trampoline.flow;
6405+
this.currentFlow = flow;
64056406

64066407
// create a br_table switching over the number of optional parameters provided
64076408
var numNames = numOptional + 1; // incl. outer block
@@ -6452,25 +6453,28 @@ export class Compiler extends DiagnosticEmitter {
64526453
]);
64536454
forwardedOperands[operandIndex] = module.local_get(operandIndex, type.toNativeType());
64546455
}
6455-
this.currentFlow = previousFlow;
64566456
assert(operandIndex == maxOperands);
64576457

6458+
var stmts: ExpressionRef[] = [ body ];
6459+
var theCall = module.call(originalName, forwardedOperands, returnType.toNativeType());
6460+
if (returnType != Type.void) {
6461+
this.performAutoreleasesWithValue(flow, theCall, returnType, stmts);
6462+
} else {
6463+
stmts.push(theCall);
6464+
this.performAutoreleases(flow, stmts);
6465+
}
6466+
flow.freeScopedLocals();
6467+
this.currentFlow = previousFlow;
6468+
64586469
var funcRef = module.addFunction(
64596470
trampoline.internalName,
64606471
this.ensureFunctionType(
64616472
trampolineSignature.parameterTypes,
6462-
trampolineSignature.returnType,
6463-
trampolineSignature.thisType
6473+
returnType,
6474+
thisType
64646475
),
64656476
typesToNativeTypes(trampoline.additionalLocals),
6466-
module.block(null, [
6467-
body,
6468-
module.call(
6469-
originalName,
6470-
forwardedOperands,
6471-
commonReturnType.toNativeType()
6472-
)
6473-
], commonReturnType.toNativeType())
6477+
module.block(null, stmts, returnType.toNativeType())
64746478
);
64756479
trampoline.finalize(module, funcRef);
64766480
return trampoline;

0 commit comments

Comments
 (0)