From d2f701b8252adfbe28562cfab82d39467ce863ef Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 25 Jul 2017 17:01:37 +0200 Subject: [PATCH] mescc: Tinycc support: bugfix struct pointer. * module/language/c99/compiler.mes (decl->info): Only set non-pointer struct to -1. * scaffold/tests/23-pointer.c (test): Test it. --- module/language/c99/compiler.mes | 2 +- scaffold/tests/23-pointer.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 91d60269..5a9a9754 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -1925,7 +1925,7 @@ (info (append-text info (ast->comment o))) (globals (append globals initzer-globals)) (info (clone info #:globals globals)) - (pointer (if (and (pair? type) (equal? (car type) "tag")) -1 pointer)) + (pointer (if (and (zero? pointer) (pair? type) (equal? (car type) "tag")) -1 pointer)) (size (if (zero? pointer) (ast-type->size info type) 4))) (if (.function info) diff --git a/scaffold/tests/23-pointer.c b/scaffold/tests/23-pointer.c index c8e2694f..e16cb079 100644 --- a/scaffold/tests/23-pointer.c +++ b/scaffold/tests/23-pointer.c @@ -23,6 +23,12 @@ char g_arena[4] = "XXX"; char *g_chars = g_arena; +struct foo { + int fd; +}; + +struct foo *file; + int test () { @@ -46,5 +52,9 @@ test () char **pp2 = *ppp; if (**pp2 != 'X') return 8; + struct foo *f = 0; + if (f) return 9; + if (file) return 10; + return 0; }