From 1780bdacc6be8d7f1fc487882ee1b3b1d318dd9d Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 22 Nov 2025 14:08:55 +0100 Subject: c: fix static eval for address of some array refs --- c/c.c | 4 +++- c/eval.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/c/c.c b/c/c.c index 1f466bb..534fba6 100644 --- a/c/c.c +++ b/c/c.c @@ -1255,7 +1255,9 @@ expr2reloc(union ref *psym, vlong *paddend, const struct expr *ex) { if (ex->t == EADDROF && globsym(psym, ex->sub)) { *paddend = 0; - } else if (ex->t == EADDROF && (ex->sub->t == EGETF && globsym(psym, ex->sub->sub))) { + } else if (ex->t == EADDROF && ex->sub->t == EGETF && globsym(psym, ex->sub->sub)) { + *paddend = ex->sub->fld.off; + } else if (ex->t == EGETF && ex->ty.t == TYARRAY && globsym(psym, ex->sub)) { *paddend = ex->sub->fld.off; } else if (globsym(psym, ex) && in_range(ex->ty.t, TYARRAY, TYFUNC)) { *paddend = 0; diff --git a/c/eval.c b/c/eval.c index ce77c6e..000a627 100644 --- a/c/eval.c +++ b/c/eval.c @@ -167,6 +167,8 @@ isaddrconst(struct expr *ex) return isaddrconst(ex->sub) || (eval(ex->sub, EVSTATICINI) && ex->sub->t == ENUMLIT); if (ex->t == EADDROF && (isglobsym(ex->sub) || (ex->sub->t == EGETF && isglobsym(ex->sub->sub)))) return 1; + if (ex->t == EGETF && ex->ty.t == TYARRAY && isglobsym(ex->sub)) + return 1; if (isglobsym(ex) && in_range(ex->ty.t, TYARRAY, TYFUNC)) return 1; if (ex->t == ESUB) @@ -294,7 +296,8 @@ eval(struct expr *ex, enum evalmode mode) struct expr *e = ex; while (e->t == ECAST) e = e->sub; if (e != ex) { - e->ty = ex->ty; + if (e->ty.t != TYARRAY) + e->ty = ex->ty; *ex = *e; } return 1; -- cgit v1.2.3