Skip to content

Fix temp local confusion in field assignment #1109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5871,8 +5871,8 @@ export class Compiler extends DiagnosticEmitter {
let alreadyRetained = this.skippedAutoreleases.has(valueExpr);
if (flow.isAnyLocalFlag(localIndex, LocalFlags.ANY_RETAINED)) {
valueExpr = this.makeReplace(
module.local_get(localIndex, type.toNativeType()),
valueExpr,
module.local_get(localIndex, type.toNativeType()),
alreadyRetained
);
if (tee) { // local = REPLACE(local, value)
Expand Down Expand Up @@ -5927,8 +5927,8 @@ export class Compiler extends DiagnosticEmitter {
let alreadyRetained = this.skippedAutoreleases.has(valueExpr);
valueExpr = module.global_set(global.internalName,
this.makeReplace(
module.global_get(global.internalName, nativeType), // oldRef
valueExpr, // newRef
valueExpr,
module.global_get(global.internalName, nativeType),
alreadyRetained
)
);
Expand Down Expand Up @@ -5979,7 +5979,8 @@ export class Compiler extends DiagnosticEmitter {
var nativeThisType = thisType.toNativeType();

if (fieldType.isManaged && thisType.isManaged) {
let tempThis = flow.getTempLocal(thisType);
let tempThis = flow.getTempLocal(thisType, findUsedLocals(valueExpr));
// set before and read after valueExpr executes below ^
let alreadyRetained = this.skippedAutoreleases.has(valueExpr);
let ret: ExpressionRef;
if (tee) { // ((t1 = this).field = REPLACE(t1.field, t2 = value)), t2
Expand All @@ -5990,11 +5991,11 @@ export class Compiler extends DiagnosticEmitter {
module.store(fieldType.byteSize,
module.local_tee(tempThis.index, thisExpr),
this.makeReplace(
module.load(fieldType.byteSize, fieldType.is(TypeFlags.SIGNED), // oldRef
module.local_tee(tempValue.index, valueExpr),
module.load(fieldType.byteSize, fieldType.is(TypeFlags.SIGNED),
module.local_get(tempThis.index, nativeThisType),
nativeFieldType, field.memoryOffset
),
module.local_tee(tempValue.index, valueExpr), // newRef
alreadyRetained
),
nativeFieldType, field.memoryOffset
Expand All @@ -6007,11 +6008,11 @@ export class Compiler extends DiagnosticEmitter {
ret = module.store(fieldType.byteSize,
module.local_tee(tempThis.index, thisExpr),
this.makeReplace(
module.load(fieldType.byteSize, fieldType.is(TypeFlags.SIGNED), // oldRef
valueExpr,
module.load(fieldType.byteSize, fieldType.is(TypeFlags.SIGNED),
module.local_get(tempThis.index, nativeThisType),
nativeFieldType, field.memoryOffset
),
valueExpr, // newRef
alreadyRetained
),
nativeFieldType, field.memoryOffset
Expand Down Expand Up @@ -6733,10 +6734,10 @@ export class Compiler extends DiagnosticEmitter {

/** Makes a replace, retaining the new expression's value and releasing the old expression's value, in this order. */
makeReplace(
/** Old value being replaced. */
oldExpr: ExpressionRef,
/** New value being assigned. */
newExpr: ExpressionRef,
/** Old value being replaced. */
oldExpr: ExpressionRef,
/** Whether the new value is already retained. */
alreadyRetained: bool = false,
): ExpressionRef {
Expand Down
6 changes: 6 additions & 0 deletions tests/compiler/issues/1095.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"asc_flags": [
"--runtime half",
"--use ASC_RTRACE=1"
]
}
Loading