From: MaartenBrock Date: Sun, 28 Oct 2007 19:35:15 +0000 (+0000) Subject: * device/include/stdarg.h: fixed bug in va_start macro for --xstack X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=985fbcbf3b741fd691ac2350fa3a425893d4f2d4 * device/include/stdarg.h: fixed bug in va_start macro for --xstack * src/hc08/gen.c (aopForRemat): aop->aopu.aop_immd.from_cast_remat not set, aop->aopu.aop_immd.aop_immd2 not filled with (generic) pointer type * src/SDCCicode.c (geniCodeCast): fixed bug 880197 * support/regression/tests/bug-880197.c: new, added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4947 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 79e0c97b..c03c9c86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-10-28 Maarten Brock + + * device/include/stdarg.h: fixed bug in va_start macro for --xstack + * src/hc08/gen.c (aopForRemat): aop->aopu.aop_immd.from_cast_remat not set, + aop->aopu.aop_immd.aop_immd2 not filled with (generic) pointer type + * src/SDCCicode.c (geniCodeCast): fixed bug 880197 + * support/regression/tests/bug-880197.c: new, added + 2007-10-28 Borut Razem * support/regression/Makefile.in, diff --git a/device/include/stdarg.h b/device/include/stdarg.h index 671b0e2b..fcb5ed58 100644 --- a/device/include/stdarg.h +++ b/device/include/stdarg.h @@ -1,5 +1,5 @@ /*-----------------------------------------------------------------------------------*/ -/* stdarg.h - ANSI macros for variable parameter list */ +/* stdarg.h - ANSI macros for variable parameter list */ /*-----------------------------------------------------------------------------------*/ #ifndef __SDC51_STDARG_H @@ -8,26 +8,26 @@ #if defined(__z80) || defined(__gbz80) || defined(__hc08) typedef unsigned char * va_list; -#define va_start(list, last) list = (unsigned char *)&last + sizeof(last) -#define va_arg(list, type) *((type *)((list += sizeof(type)) - sizeof(type))) +#define va_start(marker, last) { marker = (unsigned char *)&last + sizeof(last); } +#define va_arg(marker, type) *((type *)((marker += sizeof(type)) - sizeof(type))) #elif defined(__ds390) || defined(__ds400) -typedef unsigned char * va_list ; -#define va_arg(marker,type) *((type *)(marker -= sizeof(type))) -#define va_start(marker,first) { marker = &first; } +typedef unsigned char * va_list; +#define va_start(marker, first) { marker = &first; } +#define va_arg(marker, type) *((type *)(marker -= sizeof(type))) #elif defined(SDCC_USE_XSTACK) -typedef unsigned char __pdata * va_list ; -#define va_arg(marker,type) *((type __data *)(marker -= sizeof(type))) -#define va_start(marker,first) { marker = (va_list)((char __pdata *)&first); } +typedef unsigned char __pdata * va_list; +#define va_start(marker, first) { marker = (va_list)((char __pdata *)&first); } +#define va_arg(marker, type) *((type __pdata *)(marker -= sizeof(type))) #else -typedef unsigned char __data * va_list ; -#define va_arg(marker,type) *((type __data * )(marker -= sizeof(type))) -#define va_start(marker,first) { marker = (va_list) ((char __data * )&first); } +typedef unsigned char __data * va_list; +#define va_start(marker, first) { marker = (va_list) ((char __data * )&first); } +#define va_arg(marker, type) *((type __data * )(marker -= sizeof(type))) #endif diff --git a/src/SDCCicode.c b/src/SDCCicode.c index fe436aa4..aa2c62cc 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -2067,7 +2067,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) !IS_FIXED (type) && !IS_FIXED (optype) && ((IS_SPEC (type) && IS_SPEC (optype)) || - (!IS_SPEC (type) && !IS_SPEC (optype)))) + (IS_DECL (type) && IS_DECL (optype) && DCL_TYPE (type) == DCL_TYPE (optype)))) { ic = newiCode ('=', NULL, op); IC_RESULT (ic) = newiTempOperand (type, 0); diff --git a/src/hc08/gen.c b/src/hc08/gen.c index e42d174f..c2213ffc 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -1488,14 +1488,14 @@ aopForSym (iCode * ic, symbol * sym, bool result) } /*-----------------------------------------------------------------*/ -/* aopForRemat - rematerialzes an object */ +/* aopForRemat - rematerializes an object */ /*-----------------------------------------------------------------*/ static asmop * aopForRemat (symbol * sym) { iCode *ic = sym->rematiCode; asmop *aop = NULL; - int ptr_type=0; + int ptr_type = 0; int val = 0; for (;;) @@ -1504,17 +1504,18 @@ aopForRemat (symbol * sym) val += (int) operandLitValue (IC_RIGHT (ic)); else if (ic->op == '-') val -= (int) operandLitValue (IC_RIGHT (ic)); - else if (IS_CAST_ICODE(ic)) { - sym_link *from_type = operandType(IC_RIGHT(ic)); - aop->aopu.aop_immd.from_cast_remat = 1; - ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; - ptr_type = DCL_TYPE(from_type); - if (ptr_type == IPOINTER) { - // bug #481053 - ptr_type = POINTER; - } - continue ; - } else break; + else if (IS_CAST_ICODE(ic)) + { + sym_link *from_type = operandType(IC_RIGHT(ic)); + ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; + ptr_type = DCL_TYPE(from_type); + if (ptr_type == IPOINTER) + {// bug #481053 + ptr_type = POINTER; + } + continue ; + } + else break; ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; } @@ -1522,37 +1523,35 @@ aopForRemat (symbol * sym) if (ic->op == ADDRESS_OF) { if (val) - sprintf (buffer, "(%s %c 0x%04x)", - OP_SYMBOL (IC_LEFT (ic))->rname, - val >= 0 ? '+' : '-', - abs (val) & 0xffff); + { + SNPRINTF (buffer, sizeof(buffer), + "(%s %c 0x%04x)", + OP_SYMBOL (IC_LEFT (ic))->rname, + val >= 0 ? '+' : '-', + abs (val) & 0xffff); + } else - strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname); + { + strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer)); + } aop = newAsmop (AOP_IMMD); - aop->aopu.aop_immd.aop_immd1 = Safe_calloc (1, strlen (buffer) + 1); - strcpy (aop->aopu.aop_immd.aop_immd1, buffer); + aop->aopu.aop_immd.aop_immd1 = Safe_strdup(buffer); /* set immd2 field if required */ - if (aop->aopu.aop_immd.from_cast_remat) - { - sprintf(buffer,"#0x%02x",ptr_type); - aop->aopu.aop_immd.aop_immd2 = Safe_calloc (1, strlen (buffer) + 1); - strcpy (aop->aopu.aop_immd.aop_immd2, buffer); - } } else if (ic->op == '=') { val += (int) operandLitValue (IC_RIGHT (ic)); val &= 0xffff; - sprintf (buffer, "0x%04x", val); + SNPRINTF (buffer, sizeof(buffer), "0x%04x", val); aop = newAsmop (AOP_LIT); aop->aopu.aop_lit = constVal (buffer); } else - werror (E_INTERNAL_ERROR, __FILE__, __LINE__, - "unexpected rematerialization"); - - + { + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "unexpected rematerialization"); + } return aop; } @@ -2026,10 +2025,14 @@ aopAdrStr (asmop * aop, int loffset, bool bit16) return zero; case AOP_IMMD: - if (aop->aopu.aop_immd.from_cast_remat && (loffset == (aop->size-1))) { - sprintf(s,"%s",aop->aopu.aop_immd.aop_immd2); - } else if (bit16) - sprintf (s, "#%s", aop->aopu.aop_immd.aop_immd1); + if (aop->aopu.aop_immd.from_cast_remat && (loffset == (aop->size-1))) + { + sprintf(s,"%s",aop->aopu.aop_immd.aop_immd2); + } + else if (bit16) + { + sprintf (s, "#%s", aop->aopu.aop_immd.aop_immd1); + } else if (loffset) { if (loffset!=1) diff --git a/support/regression/tests/bug-880197.c b/support/regression/tests/bug-880197.c new file mode 100644 index 00000000..e5eb393c --- /dev/null +++ b/support/regression/tests/bug-880197.c @@ -0,0 +1,21 @@ +/* + bug 880197 +*/ + +#include + +// no need to call this, it generates compiler error: +// error: FATAL Compiler Internal Error in file 'gen.c' +// line number '8381' : genPointerSet: illegal pointer type +// Contact Author with source code + +void +writeflash(code unsigned char *cp, unsigned char val) +{ + *(xdata unsigned char *)cp = val; +} + +void +testBug(void) +{ +}