From 589a7d9c77e21f8425d4c96bdc8446c84df27dca Mon Sep 17 00:00:00 2001 From: epetrich Date: Sat, 7 Feb 2004 08:21:56 +0000 Subject: [PATCH] * support/Util/SDCCerr.h, * support/Util/SDCCerr.c, * src/SDCCast.c (decorateType, sizeofOp): complain when sizeof is used with an incomplete type (fixed bug #883734) * src/SDCCicode.c (geniCodeCast): fixed bug #890510 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3173 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 8 ++++++++ src/SDCCast.c | 12 ++++++++++-- src/SDCCicode.c | 6 ++++++ support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 1 + 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 97788cf2..b3c5516f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-02-07 Erik Petrich + + * support/Util/SDCCerr.h, + * support/Util/SDCCerr.c, + * src/SDCCast.c (decorateType, sizeofOp): complain when sizeof is used + with an incomplete type (fixed bug #883734) + * src/SDCCicode.c (geniCodeCast): fixed bug #890510 + 2004-02-07 Erik Petrich * src/pic16/gen.c (genCmpEq, shiftRLong): fixed declarations diff --git a/src/SDCCast.c b/src/SDCCast.c index 29ac0a73..134f9cc5 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -3717,8 +3717,13 @@ decorateType (ast * tree, RESULT_TYPE resultType) /*----------------------------*/ case SIZEOF: /* evaluate wihout code generation */ /* change the type to a integer */ + { + int size = getSize (tree->right->ftype); + SNPRINTF(buffer, sizeof(buffer), "%d", size); + if (!size && !IS_VOID(tree->right->ftype)) + werrorfl (tree->filename, tree->lineno, E_SIZEOF_INCOMPLETE_TYPE); + } tree->type = EX_VALUE; - SNPRINTF(buffer, sizeof(buffer), "%d", (getSize (tree->right->ftype))); tree->opval.val = constVal (buffer); tree->right = tree->left = NULL; TETYPE (tree) = getSpec (TTYPE (tree) = @@ -4200,12 +4205,15 @@ value * sizeofOp (sym_link * type) { char buff[10]; + int size; /* make sure the type is complete and sane */ checkTypeSanity(type, "(sizeof)"); /* get the size and convert it to character */ - SNPRINTF (buff, sizeof(buff), "%d", getSize (type)); + SNPRINTF (buff, sizeof(buff), "%d", size = getSize (type)); + if (!size && !IS_VOID(type)) + werror (E_SIZEOF_INCOMPLETE_TYPE); /* now convert into value */ return constVal (buff); diff --git a/src/SDCCicode.c b/src/SDCCicode.c index e0191b11..34d54375 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1862,6 +1862,12 @@ geniCodeCast (sym_link * type, operand * op, bool implicit) return op; } + if (IS_ITEMP (op) && IS_ARRAY (OP_SYMBOL (op)->type)) + { + geniCodeArray2Ptr (op); + op->isaddr = 0; + } + /* if the operand is already the desired type then do nothing */ if (compareType (type, optype) == 1) return op; diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index e54434c0..b5a92ec4 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -407,6 +407,8 @@ struct "enumeration constant not an integer" }, { W_DEPRECATED_PRAGMA, ERROR_LEVEL_WARNING, "pragma %s is deprecated, please see documentation for details" }, +{ E_SIZEOF_INCOMPLETE_TYPE, ERROR_LEVEL_ERROR, + "sizeof applied to an incomplete type" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index a675d245..0565f37f 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -191,6 +191,7 @@ SDCCERR - SDCC Standard error handler #define E_BAD_TAG 173 /* '%s' is not a %s tag */ #define E_ENUM_NON_INTEGER 174 /* enumeration constant not an integer */ #define W_DEPRECATED_PRAGMA 175 /* deprecated pragma */ +#define E_SIZEOF_INCOMPLETE_TYPE 176 /* sizeof applied to an incomplete type */ /** Describes the maximum error level that will be logged. Any level * includes all of the levels listed after it. -- 2.30.2