mescc: Tinycc support: fix *--p = 'x'.

* module/language/c99/compiler.mes (expr->accu): Respect size in *--p = 'x'.
* scaffold/tests/23-pointer.c (test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-08-27 16:58:56 +02:00
parent 19ea4fa268
commit 3560ee6c95
2 changed files with 17 additions and 17 deletions

View file

@ -916,14 +916,14 @@
(type (ident->type info name))
(ptr (ident->pointer info name))
(size (if (> ptr 1) 4 1)))
(append-text info ((ident-add info) name size)))) ;; FIXME: size
(append-text info ((ident-add info) name size))))
((assn-expr (de-ref (post-dec (p-expr (ident ,name)))) (op ,op) ,b)
(let* ((info ((expr->accu info) `(assn-expr (de-ref (p-expr (ident ,name))) (op ,op) ,b)))
(type (ident->type info name))
(ptr (ident->pointer info name))
(size (if (> ptr 1) 4 1)))
(append-text info ((ident-add info) name (- size))))) ;; FIXME: size
(append-text info ((ident-add info) name (- size)))))
((assn-expr ,a (op ,op) ,b)
(let* ((info (append-text info (ast->comment o)))
@ -984,18 +984,15 @@
((1) (wrap-as (i386:byte-accu->base-mem)))
((2) (wrap-as (i386:word-accu->base-mem)))
(else (wrap-as (i386:accu->base-mem)))))))
((de-ref (p-expr (ident ,name)))
(let* ((type (ident->type info name))
(ptr (ident->pointer info name))
(size (if (= ptr 1) (ast-type->size info type)
4)))
(append-text info (append (wrap-as (i386:accu->base))
((base->ident-address info) name))))) ; FIXME: size
((de-ref ,expr)
(let* ((info ((expr->base info) expr))
(ptr (expr->pointer info expr))
(size (expr->size info expr)))
(append-text info (wrap-as (i386:accu->base-mem)))))
(size (if (= ptr 1) (expr->size info expr)
4)))
(append-text info (case size
((1) (wrap-as (i386:byte-accu->base-mem)))
((2) (wrap-as (i386:word-accu->base-mem)))
(else (wrap-as (i386:accu->base-mem)))))))
((array-ref ,index (d-sel (ident ,field) (p-expr (ident ,struct))))
(let* ((info ((expr->base* info) a))
(type (ident->type info struct))

View file

@ -39,22 +39,25 @@ test ()
if (*x++ != 'A') return 3;
*x++ = 'C';
if (g_chars[1] != 'C') return 4;
if (g_chars[2] != 'X') return 5;
*--x = 'X';
if (g_chars[1] != 'X') return 7;
char **pp = &x;
if (**pp != 'X') return 5;
if (**pp != 'X') return 7;
char *p = *pp;
if (*p != 'X') return 6;
if (*p != 'X') return 8;
char ***ppp = &pp;
//if (***ppp != 'X') return 7;
if (***ppp != 'X') return 9;
char **pp2 = *ppp;
if (**pp2 != 'X') return 8;
if (**pp2 != 'X') return 10;
struct foo *f = 0;
if (f) return 9;
if (file) return 10;
if (f) return 11;
if (file) return 12;
return 0;
}