Update alias type sameness check

This one seems to be fairly robust. Fixes alias being used to cast
pointers (maybe a better way, but this works for now).
This commit is contained in:
Bill Currie 2019-06-18 08:53:05 +09:00
parent f7825fe7cf
commit fe73547f43
3 changed files with 31 additions and 2 deletions

View file

@ -159,9 +159,11 @@ int is_vector (const type_t *type) __attribute__((pure));
int is_quaternion (const type_t *type) __attribute__((pure));
int is_math (const type_t *type) __attribute__((pure));
int is_pointer (const type_t *type) __attribute__((pure));
int is_field (const type_t *type) __attribute__((pure));
int is_struct (const type_t *type) __attribute__((pure));
int is_array (const type_t *type) __attribute__((pure));
int is_func (const type_t *type) __attribute__((pure));
int type_compatible (const type_t *dst, const type_t *src);
int type_assignable (const type_t *dst, const type_t *src);
int type_size (const type_t *type) __attribute__((pure));

View file

@ -868,9 +868,9 @@ expr_alias (sblock_t *sblock, expr_t *e, operand_t **op)
}
type = e->e.expr.type;
sblock = statement_subexpr (sblock, e->e.expr.e1, &aop);
if (aop->type == type) {
if (type_compatible (aop->type, type)) {
if (offset) {
internal_error (e, "offset alias of same type");
internal_error (e, "offset alias of same size type");
}
*op = aop;
return sblock;

View file

@ -734,6 +734,14 @@ is_pointer (const type_t *type)
return 0;
}
int
is_field (const type_t *type)
{
if (type->type == ev_field)
return 1;
return 0;
}
int
is_array (const type_t *type)
{
@ -750,6 +758,25 @@ is_func (const type_t *type)
return 0;
}
int
type_compatible (const type_t *dst, const type_t *src)
{
// same type
if (dst == src) {
return 1;
}
if (is_field (dst) && is_field (src)) {
return 1;
}
if (is_func (dst) && is_func (src)) {
return 1;
}
if (is_pointer (dst) && is_pointer (src)) {
return 1;
}
return 0;
}
int
type_assignable (const type_t *dst, const type_t *src)
{