Treat aliased values as constant

One step closer to cast address initializers working.
This commit is contained in:
Bill Currie 2020-02-15 15:37:16 +09:00
parent ce9902baed
commit e4eb793fb3
2 changed files with 17 additions and 1 deletions

View file

@ -585,8 +585,20 @@ initialize_def (symbol_t *sym, expr_t *init, defspace_t *space,
// fold_constants takes care of int/float conversions
append_expr (local_expr, fold_constants (init));
} else {
int offset = 0;
if (!is_constant (init)) {
error (init, "non-constant initializier");
return;
}
while ((init->type == ex_uexpr || init->type == ex_expr)
&& init->e.expr.op == 'A') {
if (init->type == ex_expr) {
offset += expr_integer (init->e.expr.e2);
}
init = init->e.expr.e1;
}
if (init->type != ex_value) { //FIXME enum etc
error (0, "non-constant initializier");
internal_error (0, "initializier not a value");
return;
}
if (init->e.value->lltype == ev_pointer

View file

@ -777,6 +777,10 @@ new_short_expr (short short_val)
int
is_constant (expr_t *e)
{
while ((e->type == ex_uexpr || e->type == ex_expr)
&& e->e.expr.op == 'A') {
e = e->e.expr.e1;
}
if (e->type == ex_nil || e->type == ex_value || e->type == ex_labelref
|| (e->type == ex_symbol && e->e.symbol->sy_type == sy_const)
|| (e->type == ex_symbol && e->e.symbol->sy_type == sy_var