mescc: Tinycc support: bugfix for char **pp = *p.
* module/language/c99/compiler.mes (ptr-declr->pointer): Grok ***. (decl->info): Bugfix for char **pp = *p, cleanup. * mlibc/libc-mes.c (getenv): Update for bugfix. * scaffold/tests/23-pointer.c (test): Test it.
This commit is contained in:
parent
91f9817a44
commit
7e795763f3
|
@ -338,7 +338,7 @@ char **g_environment;
|
|||
char *
|
||||
getenv (char const* s)
|
||||
{
|
||||
char **p = *g_environment;
|
||||
char **p = g_environment;
|
||||
int length = strlen (s);
|
||||
while (*p)
|
||||
{
|
||||
|
|
|
@ -1530,6 +1530,7 @@
|
|||
(pmatch o
|
||||
((pointer) 1)
|
||||
((pointer (pointer)) 2)
|
||||
((pointer (pointer (pointer))) 3)
|
||||
(_ (error "ptr-declr->pointer unsupported: " o))))
|
||||
|
||||
(define (init-declr->name o)
|
||||
|
@ -1747,26 +1748,6 @@
|
|||
(clone info #:locals (add-local locals name type 0))
|
||||
(clone info #:globals (append globals (list (ident->global-entry name type 0 0)))))))
|
||||
|
||||
;; char **p;
|
||||
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
|
||||
(if (.function info)
|
||||
(let ((locals (add-local locals name type 2)))
|
||||
(clone info #:locals locals))
|
||||
(let ((globals (append globals (list (ident->global-entry name type 2 0)))))
|
||||
(clone info #:globals globals))))
|
||||
|
||||
;; char **p = *x;
|
||||
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer (pointer)) (ident ,name)) (initzer (de-ref (p-expr (ident ,value)))))))
|
||||
(let ((type (decl->ast-type type))
|
||||
(info (append-text info (ast->comment o))))
|
||||
(if (.function info)
|
||||
(let* ((locals (add-local locals name type 2))
|
||||
(info (clone info #:locals locals)))
|
||||
(append-text info (append ((ident-address->accu info) value)
|
||||
(wrap-as (i386:mem->accu))
|
||||
((accu->ident info) name))))
|
||||
(error "TODO" o))))
|
||||
|
||||
;; struct foo bar[2];
|
||||
;; char arena[20000];
|
||||
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (array-of (ident ,name) ,count))))
|
||||
|
|
|
@ -28,10 +28,23 @@ test ()
|
|||
{
|
||||
if (*g_chars != 'X') return 1;
|
||||
g_arena[0] = 'A';
|
||||
if (*g_chars != 'A') return 1;
|
||||
if (*g_chars != 'A') return 2;
|
||||
char *x = g_arena;
|
||||
if (*x++ != 'A') return 1;
|
||||
if (*x++ != 'A') return 3;
|
||||
*x++ = 'C';
|
||||
if (g_chars[1] != 'C') return 1;
|
||||
if (g_chars[1] != 'C') return 4;
|
||||
|
||||
char **pp = &x;
|
||||
if (**pp != 'X') return 5;
|
||||
|
||||
char *p = *pp;
|
||||
if (*p != 'X') return 6;
|
||||
|
||||
char ***ppp = &pp;
|
||||
//if (***ppp != 'X') return 7;
|
||||
|
||||
char **pp2 = *ppp;
|
||||
if (**pp2 != 'X') return 8;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue