From 5a088649705859705864e8b820d0f1dad88f3a84 Mon Sep 17 00:00:00 2001 From: johanknol Date: Thu, 27 Sep 2001 10:09:03 +0000 Subject: [PATCH] more pointer issues git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1315 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- device/lib/gbz80/printf.c | 2 +- device/lib/vprintf.c | 8 +++----- device/lib/z80/printf.c | 2 +- src/SDCCicode.c | 28 ++++++++++++++++++++++++---- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/device/lib/gbz80/printf.c b/device/lib/gbz80/printf.c index d584bdb8..2379d8ad 100644 --- a/device/lib/gbz80/printf.c +++ b/device/lib/gbz80/printf.c @@ -22,7 +22,7 @@ STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(ch (*emitter)(_hex[u%base], pData); } -STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pData, va_list va) +STATIC void _printf(char *format, void (*emitter)(char, void *), void *pData, va_list va) { while (*format) { if (*format == '%') { diff --git a/device/lib/vprintf.c b/device/lib/vprintf.c index 77bd361f..bbff51b3 100644 --- a/device/lib/vprintf.c +++ b/device/lib/vprintf.c @@ -44,12 +44,10 @@ #define NULL_STRING_LENGTH 6 #endif -/* XSPEC is defined in stdio.h and used here to place - auto variables in XSEG */ - /****************************************************************************/ -typedef char * ptr_t; +//typedef char * ptr_t; +#define ptr_t char * #ifdef toupper #undef toupper @@ -256,7 +254,7 @@ static void output_float (float f, unsigned char reqWidth, /*--------------------------------------------------------------------------*/ -int vsprintf (const char *buf, const char *format, va_list ap) +int vsprintf (const char *buf, char *format, va_list ap) { static bit left_justify; static bit zero_padding; diff --git a/device/lib/z80/printf.c b/device/lib/z80/printf.c index d584bdb8..2379d8ad 100644 --- a/device/lib/z80/printf.c +++ b/device/lib/z80/printf.c @@ -22,7 +22,7 @@ STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(ch (*emitter)(_hex[u%base], pData); } -STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pData, va_list va) +STATIC void _printf(char *format, void (*emitter)(char, void *), void *pData, va_list va) { while (*format) { if (*format == '%') { diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 628a1dba..0c512bbf 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1578,6 +1578,7 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) sym_link *optype; sym_link *opetype = getSpec (optype = operandType (op)); sym_link *restype; + int errors=0; /* one of them has size zero then error */ if (IS_VOID (optype)) @@ -1595,10 +1596,9 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) return operandFromValue (valCastLiteral (type, operandLitValue (op))); - /* if casting to/from pointers, do some checking */ if (IS_PTR(type)) { // to a pointer - if (!IS_PTR(optype)) { // from a non pointer + if (!IS_PTR(optype) && !IS_FUNC(optype)) { // from a non pointer if (IS_INTEGRAL(optype)) { // maybe this is NULL, than it's ok. if (!(IS_LITERAL(optype) && (SPEC_CVAL(optype).v_ulong ==0))) { @@ -1606,20 +1606,29 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) // no way to set the storage if (IS_LITERAL(optype)) { werror(E_LITERAL_GENERIC); + errors++; } else { werror(E_NONPTR2_GENPTR); + errors++; } } else if (implicit) { werror(W_INTEGRAL2PTR_NOCAST); + errors++; } } - } else { // shouldn't do that with float, array or structure - werror(E_INCOMPAT_TYPES); + } else { + // shouldn't do that with float, array or structure unless to void + if (!IS_VOID(getSpec(type)) && + !(IS_CODEPTR(type) && IS_FUNC(optype))) { + werror(E_INCOMPAT_TYPES); + errors++; + } } } else { // from a pointer to a pointer if (implicit) { // if not to generic, they have to match if ((!IS_GENPTR(type) && (DCL_TYPE(optype) != DCL_TYPE(type)))) { werror(E_INCOMPAT_PTYPES); + errors++; } } } @@ -1628,12 +1637,23 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) if (implicit) { // sneaky if (IS_INTEGRAL(type)) { werror(W_PTR2INTEGRAL_NOCAST); + errors++; } else { // shouldn't do that with float, array or structure werror(E_INCOMPAT_TYPES); + errors++; } } } } + if (errors) { + /* fprintf (stderr, "%s%s %d: ", op->operand.symOperand->name, + implicit?"(implicit)":"", errors); */ + fprintf (stderr, "from type '"); + printTypeChain (optype, stderr); + fprintf (stderr, "' to type '"); + printTypeChain (type, stderr); + fprintf (stderr, "'\n"); + } /* if they are the same size create an assignment */ if (getSize (type) == getSize (optype) && -- 2.30.2