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:
parent
19ea4fa268
commit
3560ee6c95
|
@ -916,14 +916,14 @@
|
||||||
(type (ident->type info name))
|
(type (ident->type info name))
|
||||||
(ptr (ident->pointer info name))
|
(ptr (ident->pointer info name))
|
||||||
(size (if (> ptr 1) 4 1)))
|
(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)
|
((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)))
|
(let* ((info ((expr->accu info) `(assn-expr (de-ref (p-expr (ident ,name))) (op ,op) ,b)))
|
||||||
(type (ident->type info name))
|
(type (ident->type info name))
|
||||||
(ptr (ident->pointer info name))
|
(ptr (ident->pointer info name))
|
||||||
(size (if (> ptr 1) 4 1)))
|
(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)
|
((assn-expr ,a (op ,op) ,b)
|
||||||
(let* ((info (append-text info (ast->comment o)))
|
(let* ((info (append-text info (ast->comment o)))
|
||||||
|
@ -984,18 +984,15 @@
|
||||||
((1) (wrap-as (i386:byte-accu->base-mem)))
|
((1) (wrap-as (i386:byte-accu->base-mem)))
|
||||||
((2) (wrap-as (i386:word-accu->base-mem)))
|
((2) (wrap-as (i386:word-accu->base-mem)))
|
||||||
(else (wrap-as (i386: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)
|
((de-ref ,expr)
|
||||||
(let* ((info ((expr->base info) expr))
|
(let* ((info ((expr->base info) expr))
|
||||||
(ptr (expr->pointer info expr))
|
(ptr (expr->pointer info expr))
|
||||||
(size (expr->size info expr)))
|
(size (if (= ptr 1) (expr->size info expr)
|
||||||
(append-text info (wrap-as (i386:accu->base-mem)))))
|
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))))
|
((array-ref ,index (d-sel (ident ,field) (p-expr (ident ,struct))))
|
||||||
(let* ((info ((expr->base* info) a))
|
(let* ((info ((expr->base* info) a))
|
||||||
(type (ident->type info struct))
|
(type (ident->type info struct))
|
||||||
|
|
|
@ -39,22 +39,25 @@ test ()
|
||||||
if (*x++ != 'A') return 3;
|
if (*x++ != 'A') return 3;
|
||||||
*x++ = 'C';
|
*x++ = 'C';
|
||||||
if (g_chars[1] != 'C') return 4;
|
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;
|
char **pp = &x;
|
||||||
if (**pp != 'X') return 5;
|
if (**pp != 'X') return 7;
|
||||||
|
|
||||||
char *p = *pp;
|
char *p = *pp;
|
||||||
if (*p != 'X') return 6;
|
if (*p != 'X') return 8;
|
||||||
|
|
||||||
char ***ppp = &pp;
|
char ***ppp = &pp;
|
||||||
//if (***ppp != 'X') return 7;
|
if (***ppp != 'X') return 9;
|
||||||
|
|
||||||
char **pp2 = *ppp;
|
char **pp2 = *ppp;
|
||||||
if (**pp2 != 'X') return 8;
|
if (**pp2 != 'X') return 10;
|
||||||
|
|
||||||
struct foo *f = 0;
|
struct foo *f = 0;
|
||||||
if (f) return 9;
|
if (f) return 11;
|
||||||
if (file) return 10;
|
if (file) return 12;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue