* src/regression/init0.c: new test for initialized arrays of function
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 7 Mar 2008 22:21:24 +0000 (22:21 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 7 Mar 2008 22:21:24 +0000 (22:21 +0000)
  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
src/pic/glue.c
src/regression/Makefile
src/regression/init0.c [new file with mode: 0644]

index 7c7c4a311c21723a6f106b051a0867db005dbfe4..b1302b643b9d7645040ccc1d6f42db04998075d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-07 Raphael Neider <rneider AT web.de>
+
+       * 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 <borut.razem AT siol.net>
 
        * 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 <sourceforge.brock AT dse.nl>
 
-       * 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
index 1ba22eee9fa9bdec2cd3c24769836239402ab860..24ba689bf1921a8bf70b9dfde28654510c0e3ee6 100644 (file)
@@ -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 {
index 641c99754d90328e5bf7a0599c143b2d1859958e..4a5468a884a31ddbf73377a96621276068126f27 100644 (file)
 #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 (file)
index 0000000..fc711e4
--- /dev/null
@@ -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();
+}
+