diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index cdd5f060..0a3cb882 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -182,6 +182,7 @@ lib/tests/scaffold/7u-struct-size10.c lib/tests/scaffold/7u-vstack.c lib/tests/scaffold/70-array-in-struct-init.c lib/tests/scaffold/70-struct-short-enum-init.c +lib/tests/scaffold/70-struct-post.c lib/tests/setjmp/80-setjmp.c lib/tests/stdio/80-sscanf.c lib/tests/stdlib/80-qsort.c diff --git a/lib/tests/scaffold/70-struct-post.c b/lib/tests/scaffold/70-struct-post.c new file mode 100644 index 00000000..262c003c --- /dev/null +++ b/lib/tests/scaffold/70-struct-post.c @@ -0,0 +1,40 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +struct foo +{ + int bar; +}; + +int +main () +{ + struct foo f; + struct foo *p = &f; + //eputs ("p-f="); eputs (itoa (p-&f)); eputs ("\n"); + int i = 22; + *p++ = f; + //eputs ("p-f="); eputs (itoa (p-&f)); eputs ("\n"); + if (p - &f != 1) + return 1; + return 0; +} diff --git a/module/mescc/compile.scm b/module/mescc/compile.scm index 4a5907ea..11e3d94c 100644 --- a/module/mescc/compile.scm +++ b/module/mescc/compile.scm @@ -1314,7 +1314,9 @@ (type (ident->type info name)) (rank (ident->rank info name)) (reg-size (->size "*" info)) - (size (if (> rank 1) reg-size 1))) + (size (cond ((= rank 1) (ast-type->size info `(p-expr (ident ,name)))) + ((> rank 1) reg-size) + (else 1)))) (append-text info ((ident-add info) name size)))) ((assn-expr (de-ref (post-dec (p-expr (ident ,name)))) (op ,op) ,b) @@ -1322,7 +1324,9 @@ (type (ident->type info name)) (rank (ident->rank info name)) (reg-size (->size "*" info)) - (size (if (> rank 1) reg-size 1))) + (size (cond ((= rank 1) (ast-type->size info `(p-expr (ident ,name)))) + ((> rank 1) reg-size) + (else 1)))) (append-text info ((ident-add info) name (- size))))) ((assn-expr ,a (op ,op) ,b)