aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-30 20:20:06 +0200
committerlemon <lsof@mailbox.org>2022-08-30 20:20:06 +0200
commitf1d4407044b5cd5eaabf0a53d1d7cb5d8b270ea6 (patch)
tree10f845b0ffa0eaf63a7bd48b6fc6c1f2582617ef /src
parentdd3b12d8114176d8433f961a11b7f53c1083ade0 (diff)
fix some type size errors
Diffstat (limited to 'src')
-rw-r--r--src/fmt.cff1
-rw-r--r--src/llvm.cff8
-rw-r--r--src/parse.cff6
-rw-r--r--src/type.cff2
4 files changed, 7 insertions, 10 deletions
diff --git a/src/fmt.cff b/src/fmt.cff
index 699777a..befde61 100644
--- a/src/fmt.cff
+++ b/src/fmt.cff
@@ -35,6 +35,7 @@ extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, ap va_list)
static buf [100]u8 = {};
fn pritok(proc typeof(proc), parg *void, quote bool, tok *const Tok) void {
+ if tok == #null { ps("(???)"); return; }
switch tok.t {
case :int;
sprintf(buf, "%lld", tok.u.int);
diff --git a/src/llvm.cff b/src/llvm.cff
index def9346..bb6af3f 100644
--- a/src/llvm.cff
+++ b/src/llvm.cff
@@ -56,17 +56,15 @@ extern fn genagg(ty *const Type) void {
gen("{ %t, ", agg.enumty);
let size = ty.size;
let ty *const Type = #null;
+ let off isize #?;
foreach (fld, i, agg.flds) {
if ty == #null or (fld.ty != #null and fld.ty.align > ty.align) {
ty = fld.ty;
+ off = fld.off;
}
}
ty = ty ?? ty_void;
- gen(" %t ", ty);
- if ty.size < size {
- gen(", [%z x i8] ", size - ty.size);
- }
- gen("}");
+ gen(" %t, [%z x i8] }", ty, size - ty.size - off);
}
}
diff --git a/src/parse.cff b/src/parse.cff
index 46d71d8..bd5262e 100644
--- a/src/parse.cff
+++ b/src/parse.cff
@@ -689,7 +689,7 @@ fn parseenum(P *Parser, name *const u8, lax bool) *const Type {
: max < 1i64 << 31 ? ty_i32
: ty_i64);
static id int = 0;
- return interntype(&Type{ .u: :Enum { intty, name, lax, id++, vals->move(P.alloc) }});
+ return interntype(&Type{ intty.size, intty.align, .u: :Enum { intty, name, lax, id++, vals->move(P.alloc) }});
}
fn isdecltokt(t TokT) bool {
@@ -735,7 +735,6 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
let size = 0z, align = 1z;
let flds Vec<AggField> = {};
let havedecls = #f;
- let f0align = 0zs;
while !lexmatch(P, &tok, '}') {
if isdecltokt(lexpeek(P).t) {
havedecls = #t;
@@ -747,7 +746,6 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
if !(kind == :EUnion and lexpeek(P).t == ',') {
type = parsetype(P);
- f0align = MAX(type.align, f0align);
}
if type != #null and !completetype(type) {
err(P, tok.loc, "field `%s' is of incomplete type (%t)", name, type);
@@ -793,7 +791,7 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
}
agg.enumty = interntype(&enumty);
- let off = f0align < 0 ? 0z : ALIGNUP(enumty.size, f0align);
+ let off = ALIGNUP(enumty.size, ty.align);
ty.size += off;
align = MAX(align, enumty.align);
ty.size = ALIGNUP(ty.size, align);
diff --git a/src/type.cff b/src/type.cff
index a17205e..2e4d840 100644
--- a/src/type.cff
+++ b/src/type.cff
@@ -200,7 +200,7 @@ extern fn putprimtypes(env *Env) void {
{ "va_list",&ty_c_valist,{ .u: :VaList }},
};
- foreach(type, _, types[0::]) {
+ foreach_ptr(type, _, types[0::]) {
let ty = &type.ty;
let gty = type.gty;
switch {