altos/lisp: Eliminate compiler warning about array bounds at -O3
authorKeith Packard <keithp@keithp.com>
Wed, 16 Nov 2016 22:12:59 +0000 (14:12 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 20 Feb 2017 19:16:51 +0000 (11:16 -0800)
Using ao_lisp_pool - 4 caused the compiler to whinge about computing
an address outside the bounds of the array. Sigh. Restructure the code
to do the adjustment-by-4 in the integer computations instead of the
pointer ones.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lisp/ao_lisp.h
src/lisp/ao_lisp_mem.c
src/lisp/ao_lisp_poly.c
src/test/Makefile

index ea8d98b5b57eb9cea7d6bc4bbee02007e972a543..25d13fa3f7c94a51e14ddbc8ce721f7982cf6aa4 100644 (file)
@@ -118,9 +118,6 @@ ao_lisp_is_const(ao_poly poly) {
        return poly & AO_LISP_CONST;
 }
 
-#define AO_LISP_POOL_BASE      (ao_lisp_pool - 4)
-#define AO_LISP_CONST_BASE     (ao_lisp_const - 4)
-
 #define AO_LISP_IS_CONST(a)    (ao_lisp_const <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_lisp_const + AO_LISP_POOL_CONST)
 #define AO_LISP_IS_POOL(a)     (ao_lisp_pool <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_lisp_pool + AO_LISP_POOL)
 
index 53ebf757d25825151d827f1f1b8d9bebc2262262..12a5ba5502a32e158f284c8864de7028ef5d18cf 100644 (file)
@@ -252,23 +252,6 @@ static inline uint16_t pool_offset(void *addr) {
        return ((uint8_t *) addr) - ao_lisp_pool;
 }
 
-/*
- * Convert back and forth between 'poly's used
- * as short addresses in the pool and addresses.
- * These are used in the chunk code.
- */
-static inline ao_poly pool_poly(void *addr) {
-#if DBG_MEM
-       if (!AO_LISP_IS_POOL(addr))
-               ao_lisp_abort();
-#endif
-       return ((uint8_t *) addr) - AO_LISP_POOL_BASE;
-}
-
-static inline void *pool_ref(ao_poly p) {
-       return AO_LISP_POOL_BASE + p;
-}
-
 static inline void mark(uint8_t *tag, int offset) {
        int     byte = offset >> 5;
        int     bit = (offset >> 2) & 7;
index 9717fd73131b30712bf7a033f874417b8016034c..236176e76baffc91fc0bfeeedc9c78511b6d465d 100644 (file)
@@ -89,8 +89,8 @@ ao_lisp_ref(ao_poly poly) {
        if (poly == AO_LISP_NIL)
                return NULL;
        if (poly & AO_LISP_CONST)
-               return (void *) (AO_LISP_CONST_BASE + (poly & AO_LISP_REF_MASK));
-       return (void *) (AO_LISP_POOL_BASE + (poly & AO_LISP_REF_MASK));
+               return (void *) (ao_lisp_const + (poly & AO_LISP_REF_MASK) - 4);
+       return (void *) (ao_lisp_pool + (poly & AO_LISP_REF_MASK) - 4);
 }
 
 ao_poly
@@ -99,6 +99,6 @@ ao_lisp_poly(const void *addr, ao_poly type) {
        if (a == NULL)
                return AO_LISP_NIL;
        if (AO_LISP_IS_CONST(a))
-               return AO_LISP_CONST | (a - AO_LISP_CONST_BASE) | type;
-       return (a - AO_LISP_POOL_BASE) | type;
+               return AO_LISP_CONST | (a - ao_lisp_const + 4) | type;
+       return (a - ao_lisp_pool + 4) | type;
 }
index fae46ac8848b56be6bc8b40f91e45f4c27729b4a..0eaa94214786a3b7ed51ac03d702e661b5f38b57 100644 (file)
@@ -10,7 +10,7 @@ INCS=ao_kalman.h ao_ms5607.h ao_log.h ao_data.h altitude-pa.h altitude.h ao_quat
 
 KALMAN=make-kalman 
 
-CFLAGS=-I.. -I. -I../kernel -I../drivers -I../micropeak -I../product -I../lisp -O3 -g -Wall -DAO_LISP_TEST -no-pie
+CFLAGS=-I.. -I. -I../kernel -I../drivers -I../micropeak -I../product -I../lisp -O0 -g -Wall -DAO_LISP_TEST -no-pie
 
 all: $(PROGS) ao_aprs_data.wav