mescc: Bugfix non-char* *x x[] test.

* module/language/c99/compiler.mes (expr->pointer): New function.
  (test-jump-label->info): Use it to fix non char* while (*x | x[i]).
This commit is contained in:
Jan Nieuwenhuizen 2017-07-23 08:44:48 +02:00
parent 3af652a4d0
commit b44825a035

View file

@ -1151,6 +1151,7 @@
(define (ast-type->type info o) (define (ast-type->type info o)
(pmatch o (pmatch o
((p-expr ,expr) (ast-type->type info (p-expr->type info o)))
((decl-spec-list (type-spec (fixed-type ,type))) ((decl-spec-list (type-spec (fixed-type ,type)))
(ast-type->type info type)) (ast-type->type info type))
((decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type))) ((decl-spec-list (type-qual ,qual) (type-spec (fixed-type ,type)))
@ -1342,11 +1343,19 @@
(info (append-text info (wrap-as `((#:label ,skip-b-label)))))) (info (append-text info (wrap-as `((#:label ,skip-b-label))))))
info)) info))
((array-ref . _) ((jump i386:jump-byte-z ((array-ref ,index ,expr) (let* ((ptr (expr->pointer info expr))
(wrap-as (i386:accu-zero?))) o)) (size (if (= ptr 1) (ast-type->size info expr)
4)))
((jump (if (= size 1) i386:jump-byte-z
i386:jump-z)
(wrap-as (i386:accu-zero?))) o)))
((de-ref _) ((jump i386:jump-byte-z ((de-ref ,expr) (let* ((ptr (expr->pointer info expr))
(wrap-as (i386:accu-zero?))) o)) (size (if (= ptr 1) (ast-type->size info expr)
4)))
((jump (if (= size 1) i386:jump-byte-z
i386:jump-z)
(wrap-as (i386:accu-zero?))) o)))
((assn-expr (p-expr (ident ,name)) ,op ,expr) ((assn-expr (p-expr (ident ,name)) ,op ,expr)
((jump i386:jump-z ((jump i386:jump-z
@ -1448,6 +1457,11 @@
(if local (local:pointer local) (if local (local:pointer local)
(or (and=> (ident->decl info o) global:pointer) 0)))) (or (and=> (ident->decl info o) global:pointer) 0))))
(define (expr->pointer info o)
(pmatch o
((p-expr (ident ,name)) (ident->pointer info name))
(_ (stderr "expr->pointer: unsupported: ~s\n" o) 0)))
(define (p-expr->type info o) (define (p-expr->type info o)
(pmatch o (pmatch o
((p-expr (ident ,name)) (ident->type info name)) ((p-expr (ident ,name)) (ident->type info name))