mescc: Add 70-struct-post.c test with fix.

* lib/tests/scaffold/70-struct-post.c: New file.
* build-aux/check-mescc.sh (TESTS): Add it.
* module/mescc/compile.scm (expr->register): Use type size for rank
0 (WAS: 1).
This commit is contained in:
Jan Nieuwenhuizen 2019-03-31 22:40:42 +02:00
parent 46f3112956
commit 0cfdb5e9d8
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
3 changed files with 47 additions and 2 deletions

View File

@ -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

View File

@ -0,0 +1,40 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
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;
}

View File

@ -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)