From d64a304a831e4d8c6e402c416877843dd4830822 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 4 Aug 2017 11:40:04 +0200 Subject: [PATCH] mescc: Tinycc support: ((unsigned char*)str)[i]. * module/language/c99/compiler.mes (expr->accu*): Consider size of expr array deref. * scaffold/tests/7d-cast-char.c: Test it. --- module/language/c99/compiler.mes | 4 +++- scaffold/tests/7d-cast-char.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index c633ad36..0928f469 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -1176,7 +1176,9 @@ ((array-ref ,index ,array) (let* ((info ((expr->accu info) index)) - (size 4) ;; FIXME + (ptr (expr->pointer info array)) + (size (if (= ptr 1) (expr->size info array) + 4)) (info (append-text info (wrap-as (append (i386:accu->base) (if (eq? size 1) '() (append diff --git a/scaffold/tests/7d-cast-char.c b/scaffold/tests/7d-cast-char.c index 063045ff..8aaf5a63 100644 --- a/scaffold/tests/7d-cast-char.c +++ b/scaffold/tests/7d-cast-char.c @@ -29,5 +29,10 @@ test () int i = ((unsigned char *)s)[0]; if (i != 'i') return 2; + c = s[1]; + if (c != 'n') return 3; + i = ((unsigned char *)s)[1]; + if (i != 'n') return 3; + return 0; }