From 6bcc9a91e32c13f7970d6bfb6ba75fd2ec759cf9 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 11 May 2018 17:13:07 +0200 Subject: [PATCH] mescc: Tinycc support: Sizeof struct destruct. --- module/language/c99/compiler.mes | 13 ++++--------- scaffold/tests/t.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 27ab2b36..33a7a56c 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -243,7 +243,6 @@ ((d-sel (ident ,field) ,struct) (let ((type0 (ast->type struct info))) - (stderr "type0=~s\n" type0) (ast->type (field-type info type0 field) info))) ((i-sel (ident ,field) ,struct) @@ -1378,14 +1377,10 @@ (* (expr->number info a) (expr->number info b))) ((sub ,a ,b) (- (expr->number info a) (expr->number info b))) - ((sizeof-type (type-name (decl-spec-list (type-spec ,type)))) - (ast-type->size info type)) - ((sizeof-expr (d-sel (ident ,field) (p-expr (ident ,struct)))) - (let ((type (ident->type info struct))) - (field-size info type field))) - ((sizeof-expr (i-sel (ident ,field) (p-expr (ident ,struct)))) - (let ((type (ident->type info struct))) - (field-size info type field))) + ((sizeof-type ,type) + (->size (ast->type type info))) + ((sizeof-expr ,expr) + (->size (ast->type expr info))) ((lshift ,x ,y) (ash (expr->number info x) (expr->number info y))) ((rshift ,x ,y) diff --git a/scaffold/tests/t.c b/scaffold/tests/t.c index b7181f97..a102f602 100644 --- a/scaffold/tests/t.c +++ b/scaffold/tests/t.c @@ -33,7 +33,8 @@ char *env[] = {"foo", "bar", "baz", 0}; char *list[2] = {"foo\n", "bar\n"}; struct foo {int length; char* string;}; -struct foo f = {3, "foo"}; +struct foo g_f = {3, "foo"}; +struct foo g_g = &g_f; struct foo g_foes[2]; int g_foe; @@ -45,7 +46,7 @@ struct here {int and;} there; int test (struct foo* p) { - struct foo *g = &f; + struct foo *g = &g_f; g[0].length = 0; p[0].length = 0; } @@ -89,9 +90,9 @@ main (int argc, char* argv[]) return 14; if (env[3]) return 15; - if (f.length != 3) + if (g_f.length != 3) return 16; - if (strcmp (f.string, "foo")) + if (strcmp (g_f.string, "foo")) return 17; struct foo g = {4, "baar"}; if (g.length != 4) @@ -121,6 +122,9 @@ main (int argc, char* argv[]) if (u.foo != 3) return 24; if (u.bla != 4) return 25; + char buf[sizeof (g_f.string)]; + char buf1[sizeof (g_g->string)]; + i = 1; int lst[6] = {-1, 1 - 1, i, 2, 3}; for (int i = 0; i < 4; i++)