fix pretty bad bug in alias analysis
When a temporary marked local is escaping, the whole slot must be marked as such. To solve this, Alias now holds a pointer to the alias information of the slot. For simplicity of the code, this pointer is always valid and fetching ->type out of it is meaningful.
This commit is contained in:
parent
5165fcae76
commit
a35dc8c495
2 changed files with 11 additions and 4 deletions
14
alias.c
14
alias.c
|
@ -10,6 +10,7 @@ getalias(Alias *a, Ref r, Fn *fn)
|
||||||
die("unreachable");
|
die("unreachable");
|
||||||
case RTmp:
|
case RTmp:
|
||||||
*a = fn->tmp[r.val].alias;
|
*a = fn->tmp[r.val].alias;
|
||||||
|
a->type = a->slot->type;
|
||||||
assert(a->type != ABot);
|
assert(a->type != ABot);
|
||||||
break;
|
break;
|
||||||
case RCon:
|
case RCon:
|
||||||
|
@ -20,6 +21,7 @@ getalias(Alias *a, Ref r, Fn *fn)
|
||||||
} else
|
} else
|
||||||
a->type = ACon;
|
a->type = ACon;
|
||||||
a->offset = c->bits.i;
|
a->offset = c->bits.i;
|
||||||
|
a->slot = a;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,9 +81,12 @@ alias(Ref p, int sp, Ref q, int sq, int *delta, Fn *fn)
|
||||||
int
|
int
|
||||||
escapes(Ref r, Fn *fn)
|
escapes(Ref r, Fn *fn)
|
||||||
{
|
{
|
||||||
|
Alias *a;
|
||||||
|
|
||||||
if (rtype(r) != RTmp)
|
if (rtype(r) != RTmp)
|
||||||
return 1;
|
return 1;
|
||||||
return fn->tmp[r.val].alias.type != ALoc;
|
a = &fn->tmp[r.val].alias;
|
||||||
|
return !(a->type & 1) || a->slot->type == AEsc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -92,9 +97,8 @@ esc(Ref r, Fn *fn)
|
||||||
assert(rtype(r) <= RType);
|
assert(rtype(r) <= RType);
|
||||||
if (rtype(r) == RTmp) {
|
if (rtype(r) == RTmp) {
|
||||||
a = &fn->tmp[r.val].alias;
|
a = &fn->tmp[r.val].alias;
|
||||||
assert(a->type != ABot);
|
if (a->slot->type == ALoc)
|
||||||
if (a->type == ALoc)
|
a->slot->type = AEsc;
|
||||||
a->type = AEsc;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +120,7 @@ fillalias(Fn *fn)
|
||||||
a->type = AUnk;
|
a->type = AUnk;
|
||||||
a->base = p->to;
|
a->base = p->to;
|
||||||
a->offset = 0;
|
a->offset = 0;
|
||||||
|
a->slot = a;
|
||||||
}
|
}
|
||||||
for (i=b->ins; i<&b->ins[b->nins]; ++i) {
|
for (i=b->ins; i<&b->ins[b->nins]; ++i) {
|
||||||
a = 0;
|
a = 0;
|
||||||
|
@ -129,6 +134,7 @@ fillalias(Fn *fn)
|
||||||
a->type = AUnk;
|
a->type = AUnk;
|
||||||
a->base = i->to;
|
a->base = i->to;
|
||||||
a->offset = 0;
|
a->offset = 0;
|
||||||
|
a->slot = a;
|
||||||
}
|
}
|
||||||
if (i->op == Ocopy) {
|
if (i->op == Ocopy) {
|
||||||
assert(a);
|
assert(a);
|
||||||
|
|
1
all.h
1
all.h
|
@ -391,6 +391,7 @@ struct Alias {
|
||||||
Ref base;
|
Ref base;
|
||||||
char label[NString];
|
char label[NString];
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
|
Alias *slot;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Tmp {
|
struct Tmp {
|
||||||
|
|
Loading…
Add table
Reference in a new issue