* src/SDCCglue.c (printIvalType, printIvalBitFields): fixed bug 1856409
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 23 Apr 2008 13:27:33 +0000 (13:27 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 23 Apr 2008 13:27:33 +0000 (13:27 +0000)
* support/regression/tests/bug1856409.c: new, added

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5144 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCglue.c
support/regression/tests/bug1856409.c [new file with mode: 0644]

index 646a53cefc2fd01245edcd177862c3a56666b347..19fd838488c410a0ca184a97bb1287fb4613e561 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-23 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/SDCCglue.c (printIvalType, printIvalBitFields): fixed bug 1856409
+       * support/regression/tests/bug1856409.c: new, added
+
 2008-04-20 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/z80/peep.c,
index 7aed6a580456f63c456c665ceb9af7c44a785d5a..fed61f89773ab1a04a98cb739c954fc1bd125920 100644 (file)
@@ -647,6 +647,13 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, struct dbuf_s * o
     val = constCharVal (0);
   }
 
+  /* check if the literal value is within bounds */
+  if (checkConstantRange (type, val->etype, '=', FALSE) == CCR_OVL &&
+      !options.lessPedantic)
+    {
+      werror (W_LIT_OVERFLOW);
+    }
+
   if (val->type != type) {
     val = valCastLiteral(type, floatFromVal(val));
   }
@@ -698,7 +705,6 @@ void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf)
   unsigned long ival = 0;
   int size =0;
 
-
   do {
     unsigned long i;
     val = list2val(lilist);
@@ -711,7 +717,15 @@ void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf)
       size = ((SPEC_BLEN (lsym->etype) / 8) +
               (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
     }
+
+    /* check if the literal value is within bounds */
+    if (checkConstantRange (lsym->etype, val->etype, '=', FALSE) == CCR_OVL &&
+        !options.lessPedantic)
+      {
+        werror (W_LIT_OVERFLOW);
+      }
     i = ulFromVal(val);
+    i &= (1 << SPEC_BLEN (lsym->etype)) - 1;
     i <<= SPEC_BSTR (lsym->etype);
     ival |= i;
     if (! ( lsym->next &&
@@ -1244,21 +1258,23 @@ emitStaticSeg (memmap * map, struct dbuf_s * oBuf)
         }
 
       /* print extra debug info if required */
-      if (options.debug) {
-
-        if (!sym->level)
-          {                     /* global */
-            if (IS_STATIC (sym->etype))
-              dbuf_printf (oBuf, "F%s$", moduleName);        /* scope is file */
-            else
-              dbuf_printf (oBuf, "G$");      /* scope is global */
-          }
-        else
-          /* symbol is local */
-          dbuf_printf (oBuf, "L%s$",
-                   (sym->localof ? sym->localof->name : "-null-"));
-        dbuf_printf (oBuf, "%s$%d$%d", sym->name, sym->level, sym->block);
-      }
+      if (options.debug)
+        {
+          if (!sym->level)
+            {                     /* global */
+              if (IS_STATIC (sym->etype))
+                dbuf_printf (oBuf, "F%s$", moduleName);        /* scope is file */
+              else
+                dbuf_printf (oBuf, "G$");      /* scope is global */
+            }
+          else
+            {
+              /* symbol is local */
+              dbuf_printf (oBuf, "L%s$",
+                           (sym->localof ? sym->localof->name : "-null-"));
+            }
+          dbuf_printf (oBuf, "%s$%d$%d", sym->name, sym->level, sym->block);
+        }
 
       /* if it has an absolute address and no initializer */
       if (SPEC_ABSA (sym->etype) && !sym->ival)
diff --git a/support/regression/tests/bug1856409.c b/support/regression/tests/bug1856409.c
new file mode 100644 (file)
index 0000000..1fb232e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+    bug 1856409
+    storage: static code,
+*/
+
+#include <stdint.h>
+#include <testfwk.h>
+
+#ifndef PORT_HOST
+#pragma disable_warning 158 //no warning about overflow in constant (W_LIT_OVERFLOW)
+#endif
+
+typedef struct {
+       unsigned int e:2;
+       unsigned int f:3;
+       unsigned int g:3;
+} Ta;
+
+void
+testBug(void)
+{
+       {storage} Ta aa = {1, 29, 0};
+       {storage} uint16_t xx = 100000;
+       char t;
+
+       t = aa.e;
+       ASSERT(t ==  (1 & 3));
+       t = aa.f;
+       ASSERT(t == (29 & 7));
+       t = aa.g;
+       ASSERT(t ==  (0 & 7));
+
+       ASSERT(xx == (uint16_t)(100000 & 65535));
+}