From 8649f7a923acf62a478349328c31ec9abb15038b Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 25 Aug 2017 06:58:15 +0200 Subject: [PATCH] mescc: Tinycc support: pointer arithmetic with &variable. * module/language/c99/compiler.mes (expr->pointer): Handle ref. * scaffold/tests/76-pointer-arithmetic.c: Test it. --- module/language/c99/compiler.mes | 1 + scaffold/tests/76-pointer-arithmetic.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index cbc7ca92..c64429b7 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -1736,6 +1736,7 @@ ((pre-dec ,a) (expr->pointer info a)) ((post-inc ,a) (expr->pointer info a)) ((post-dec ,a) (expr->pointer info a)) + ((ref-to ,expr) (1+ (expr->pointer info expr))) ((array-ref ,index ,array) (1- (expr->pointer info array))) diff --git a/scaffold/tests/76-pointer-arithmetic.c b/scaffold/tests/76-pointer-arithmetic.c index 2edb00a4..39469d43 100644 --- a/scaffold/tests/76-pointer-arithmetic.c +++ b/scaffold/tests/76-pointer-arithmetic.c @@ -75,6 +75,7 @@ test () if (pfoo != 12) return 17; int one = 1; + int two = 2; pfoo = pfoo - one; eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); if (pfoo) return 18; @@ -91,5 +92,7 @@ test () eputs ("pfoo="); eputs (itoa (pfoo)); eputs ("\n"); if (pfoo != 12) return 21; + if (&one - 1 != &two) return 22; + return 0; }