qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit 12755db1aaea6f4ba1f380f5f34842b4e2a28f26
parent f4e0bfbbb9a69ff4ced213ec10d28411c093e495
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date:   Mon, 25 Apr 2016 10:37:27 -0400

fix type size computations in parser

The type sizes are important to get right because
the ABI relies on them when it emits memory blits
to pass/return structs.

Diffstat:
Mall.h | 2+-
Mparse.c | 21++++++++++-----------
2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/all.h b/all.h @@ -431,7 +431,7 @@ struct Fn { struct Typ { char name[NString]; int dark; - uint size; + ulong size; int align; struct { diff --git a/parse.c b/parse.c @@ -791,7 +791,8 @@ static void parsetyp() { Typ *ty; - int t, n, sz, al, s, a, c, flt; + int t, n, c, a, al, flt; + ulong sz, s; if (ntyp >= NTyp) err("too many type definitions"); @@ -851,14 +852,12 @@ parsetyp() t = nextnl(); } else c = 1; - while (c-- > 0) - if (n < NSeg) { - ty->seg[n].isflt = flt; - ty->seg[n].ispad = 0; - ty->seg[n].len = s; - sz += a + s; - n++; - } + sz += a + c*s; + for (; c>0 && n<NSeg; c--, n++) { + ty->seg[n].isflt = flt; + ty->seg[n].ispad = 0; + ty->seg[n].len = s; + } if (t != Tcomma) break; t = nextnl(); @@ -871,8 +870,8 @@ parsetyp() ty->align = al; else al = ty->align; - a = (1 << al) - 1; - ty->size = (sz + a) & ~a; + a = 1 << al; + ty->size = (sz + a - 1) & -a; } if (t != Trbrace) err(", or } expected");