From 3560ee6c9594ebfc646bc9c75b04aad39b084a11 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 27 Aug 2017 16:58:56 +0200 Subject: [PATCH] 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. --- module/language/c99/compiler.mes | 19 ++++++++----------- scaffold/tests/23-pointer.c | 15 +++++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index e0a1df3f..f8566850 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -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)) diff --git a/scaffold/tests/23-pointer.c b/scaffold/tests/23-pointer.c index e16cb079..0ae2d78c 100644 --- a/scaffold/tests/23-pointer.c +++ b/scaffold/tests/23-pointer.c @@ -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; }