Skip to content

Commit

Permalink
Fix temp local confusion in field assignment (#1109)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Feb 14, 2020
1 parent e0ccf0a commit fa5d4db
Show file tree
Hide file tree
Showing 10 changed files with 3,489 additions and 657 deletions.
21 changes: 11 additions & 10 deletions src/compiler.ts
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
@@ -0,0 +1,6 @@
{
"asc_flags": [
"--runtime half",
"--use ASC_RTRACE=1"
]
}

0 comments on commit fa5d4db

Please sign in to comment.