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-07-21 22:40:42 +02:00
parent 2f77f506b1
commit 2611a64b2e
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/7u-vstack.c
lib/tests/scaffold/70-array-in-struct-init.c lib/tests/scaffold/70-array-in-struct-init.c
lib/tests/scaffold/70-struct-short-enum-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/setjmp/80-setjmp.c
lib/tests/stdio/80-sscanf.c lib/tests/stdio/80-sscanf.c
lib/tests/stdlib/80-qsort.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)) (type (ident->type info name))
(rank (ident->rank info name)) (rank (ident->rank info name))
(reg-size (->size "*" info)) (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)))) (append-text info ((ident-add info) name size))))
((assn-expr (de-ref (post-dec (p-expr (ident ,name)))) (op ,op) ,b) ((assn-expr (de-ref (post-dec (p-expr (ident ,name)))) (op ,op) ,b)
@ -1322,7 +1324,9 @@
(type (ident->type info name)) (type (ident->type info name))
(rank (ident->rank info name)) (rank (ident->rank info name))
(reg-size (->size "*" info)) (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))))) (append-text info ((ident-add info) name (- size)))))
((assn-expr ,a (op ,op) ,b) ((assn-expr ,a (op ,op) ,b)