* support/Util/SDCCerr.h,
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 7 Feb 2004 08:21:56 +0000 (08:21 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 7 Feb 2004 08:21:56 +0000 (08:21 +0000)
* 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
src/SDCCast.c
src/SDCCicode.c
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 97788cf24116d959f483b3f4144faef01554a5db..b3c5516f1a472602b8511f883a14d7a4f7dcd94a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-02-07 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * 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 <epetrich AT ivorytower.norman.ok.us>
 
        * src/pic16/gen.c (genCmpEq, shiftRLong): fixed declarations
index 29ac0a73fca8523130e9c9b51b3c399a900da27e..134f9cc56259c2eb3820b3380a0df27e9d60be76 100644 (file)
@@ -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);
index e0191b114faca281d64da9fcf59859341a0afab2..34d5437540c6125cef986479e30be5e8d9f84e78 100644 (file)
@@ -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;
index e54434c05e10e8de6c194c0057ac3094c89789e4..b5a92ec46978b2e256115f21fc7251634cf64a97 100644 (file)
@@ -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" },
 };
 
 /*
index a675d2457a652bf59d6028011416e640c6d49359..0565f37f2f3258e0abd9d85344b20293b1d94696 100644 (file)
@@ -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.