Fix casting arrays to pointers

This commit is contained in:
Bill Currie 2019-06-09 22:55:38 +09:00
parent 3196bcc851
commit 00f12263ca
2 changed files with 7 additions and 3 deletions

View file

@ -2537,8 +2537,9 @@ cast_expr (type_t *type, expr_t *e)
&& !(is_scalar (type) && is_scalar (e_type))) { && !(is_scalar (type) && is_scalar (e_type))) {
return cast_error (e, e_type, type); return cast_error (e, e_type, type);
} }
if (is_array (e_type)) if (is_array (e_type)) {
return address_expr (e, 0, 0); return address_expr (e, 0, type->t.fldptr.type);
}
if (is_constant (e) && is_scalar (type) && is_scalar (e_type)) { if (is_constant (e) && is_scalar (type) && is_scalar (e_type)) {
ex_value_t *val = 0; ex_value_t *val = 0;
if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const) { if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const) {

View file

@ -7,14 +7,17 @@ typedef struct {
int ofs[]; int ofs[];
} valstruct_t; } valstruct_t;
int foo[5] = {1, 2, 3, 4, 5};
valstruct_t *vs; valstruct_t *vs;
int dst; int dst;
int int
main () main ()
{ {
vs = (valstruct_t *)foo;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
dst = vs.ofs[i]; dst = vs.ofs[i];
} }
return 1; printf("dst = %d\n", dst);
return dst != 4;
} }