From 661651374d7b67aca713b215c01b13b2782c4b37 Mon Sep 17 00:00:00 2001 From: tecodev Date: Fri, 7 Mar 2008 22:21:24 +0000 Subject: [PATCH] * src/regression/init0.c: new test for initialized arrays of function pointers * src/regression/Makefile: made a bit more flexible, added init0.c * src/pic/glue.c (emitIvals): hacky fix for initializing from function pointers, closes #1427663 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5074 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 15 +++++++++++--- src/pic/glue.c | 14 ++++++++++++- src/regression/Makefile | 14 ++++++++----- src/regression/init0.c | 45 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 src/regression/init0.c diff --git a/ChangeLog b/ChangeLog index 7c7c4a31..b1302b64 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-03-07 Raphael Neider + + * src/regression/init0.c: new test for initialized arrays of function + pointers + * src/regression/Makefile: made a bit more flexible, added init0.c + * src/pic/glue.c (emitIvals): hacky fix for initializing from function + pointers, closes #1427663 + 2008-03-05 Borut Razem * dos/sdccman.lyx: docummented predefined macros SDCC_REVISION, @@ -23,7 +31,8 @@ * src/SDCCutil.c, * src/SDCCutil.h: added getBuildDate() * src/SDCCmain.c (printVersionInfo), - * src/SDCCglue.c (initialComments): use getBuildDate() instead of __DATE__ + * src/SDCCglue.c (initialComments): use getBuildDate() instead of + __DATE__ * src/*/ralloc.c: removed IS_OP_RUONLY macro * src/ds390/ralloc.c (packRegisters), * src/mcs51/ralloc.c (packRegisters), @@ -85,8 +94,8 @@ 2008-02-27 Maarten Brock - * src/mcs51/gen.c (genUnpackBits): don't generate ifxJump, instead return - ifx condition + * src/mcs51/gen.c (genUnpackBits): don't generate ifxJump, instead + return ifx condition (genNearPointerGet, genPagedPointerGet, genFarPointerGet, genCodePointerGet, genGenPointerGet): cleanup aop before generating ifxJump to fix bug 1838000 diff --git a/src/pic/glue.c b/src/pic/glue.c index 1ba22eee..24ba689b 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -1819,8 +1819,20 @@ emitIvals(struct dbuf_s *oBuf, symbol *sym, initList *list, long lit, int size) } for (i=0; i < size; i++) { - char *text = op ? aopGet(AOP(op), i, 0, 0) + char *text; + + /* + * FIXME: This is hacky and needs some more thought. + */ + if (op && IS_SYMOP(op) && IS_FUNC(OP_SYM_TYPE(op))) { + /* This branch is introduced to fix #1427663. */ + PCOI(AOP(op)->aopu.pcop)->offset+=i; + text = get_op(AOP(op)->aopu.pcop, NULL, 0); + PCOI(AOP(op)->aopu.pcop)->offset-=i; + } else { + text = op ? aopGet(AOP(op), i, 0, 0) : get_op(newpCodeOpImmd(str, i, 0, inCodeSpace, 0), NULL, 0); + } // if if (in_code) { dbuf_printf (oBuf, "\tretlw %s\n", text); } else { diff --git a/src/regression/Makefile b/src/regression/Makefile index 641c9975..4a5468a8 100644 --- a/src/regression/Makefile +++ b/src/regression/Makefile @@ -49,12 +49,15 @@ #Q ?= # be verbose Q ?= @ # be quiet -CC = sdcc +SDCC_SRC=../.. +SDCC_BIN=../.. + +CC = $(SDCC_BIN)/bin/sdcc LINKER = gplink -USE_PIC16 ?= 1 +USE_PIC16 ?= 0 ifeq ($(strip $(filter 1 yes,$(USE_PIC16))),) TARGETPIC = 16f877 -TARGETPIC = 16f84 +#TARGETPIC = 16f84 CFLAGS = -mpic14 -p$(TARGETPIC) DIR = pic else @@ -64,8 +67,8 @@ DIR = pic16 endif CFLAGS += -Wl,-q CFLAGS += -Wl,--map -CFLAGS += -I ../../device/include/$(DIR) -CFLAGS += -L ../../device/lib/$(DIR)/bin +CFLAGS += -I $(SDCC_SRC)/device/include/$(DIR) +CFLAGS += -L $(SDCC_BIN)/device/lib/$(DIR)/bin #CFLAGS += --no-pcode-opt #CFLAGS += -V @@ -108,6 +111,7 @@ SRC = add.c \ configword.c \ empty.c \ for.c \ + init0.c \ inline.c \ mult1.c \ nestfor.c \ diff --git a/src/regression/init0.c b/src/regression/init0.c new file mode 100644 index 00000000..fc711e44 --- /dev/null +++ b/src/regression/init0.c @@ -0,0 +1,45 @@ +#include "gpsim_assert.h" + +unsigned failures = 0; + +void +done(void) +{ + ASSERT(MANGLE(failures) == 0); + PASSED(); +} + +typedef void (void_void_f)(void); + +void +foo(void) { + failures--; +} + +void +bar(void) { + failures -= 2; +} + +static void_void_f * +funcs[] = { + &foo, + &bar, + (void *)0 +}; + +void +main(void) +{ + void_void_f **ptr; + failures = 3; + + ptr = &funcs[0]; + while (*ptr) { + (**ptr)(); + ptr++; + } // while + + done(); +} + -- 2.30.2