* src/SDCCsymt.c, src/SDCCglue.c,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 31 Aug 2008 09:10:06 +0000 (09:10 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 31 Aug 2008 09:10:06 +0000 (09:10 +0000)
  support/regression/tests/bug-1981238.c:
  applied patch 2076664: fix #1981238 + SIGSEGV in SDCCGlue.c
  thanks to RvS

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

ChangeLog
src/SDCCglue.c
src/SDCCsymt.c
support/regression/tests/bug-1981238.c [new file with mode: 0644]

index 7beca775b86a1d4a2b2c6c8ad8db7fe2d9b21b87..1628450580f1f4bb9a0186283e2192c25b91bb54 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,10 @@
          1444425: onebyte.c regression tes fails on pic16
          are fiexed, probably by fixing
          2048464: PIC16: fix genUminus - addresses not.c regression test
+       * src/SDCCsymt.c, src/SDCCglue.c,
+         support/regression/tests/bug-1981238.c:
+         applied patch 2076664: fix #1981238 + SIGSEGV in SDCCGlue.c
+         thanks to RvS
 
 2008-08-30 Borut Razem <borut.razem AT siol.net>
 
index fed61f89773ab1a04a98cb739c954fc1bd125920..4194fa1c79c0d41bb16ea086b9226961ff44bfdf 100644 (file)
@@ -703,48 +703,60 @@ void printIvalBitFields(symbol **sym, initList **ilist, struct dbuf_s * oBuf)
   symbol *lsym = *sym;
   initList *lilist = *ilist ;
   unsigned long ival = 0;
-  int size =0;
-
-  do {
-    unsigned long i;
-    val = list2val(lilist);
-    if (size) {
-      if (SPEC_BLEN(lsym->etype) > 8) {
-        size += ((SPEC_BLEN (lsym->etype) / 8) +
-                 (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
-      }
-    } else {
-      size = ((SPEC_BLEN (lsym->etype) / 8) +
-              (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
-    }
+  int size = 0;
+
+  do
+    {
+      unsigned long i;
+      val = list2val (lilist);
+      if (size)
+        {
+          if (SPEC_BLEN (lsym->etype) > 8)
+            {
+              size += ((SPEC_BLEN (lsym->etype) / 8) +
+                       (SPEC_BLEN (lsym->etype) % 8 ? 1 : 0));
+            }
+        }
+      else
+        {
+          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 &&
+      /* check if the literal value is within bounds */
+      if (val &&
+        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 &&
-          (IS_BITFIELD(lsym->next->type)) &&
-          (SPEC_BSTR(lsym->next->etype)))) break;
-    lsym = lsym->next;
-    lilist = lilist ? lilist->next : NULL;
-  } while (1);
-  switch (size) {
+        {
+          werror (W_LIT_OVERFLOW);
+        }
+
+      i = ulFromVal (val);
+      i &= (1 << SPEC_BLEN (lsym->etype)) - 1;
+      i <<= SPEC_BSTR (lsym->etype);
+      ival |= i;
+      if (!(lsym->next &&
+        (IS_BITFIELD (lsym->next->type)) &&
+        (SPEC_BSTR (lsym->next->etype))))
+        break;
+      lsym = lsym->next;
+      lilist = lilist ? lilist->next : NULL;
+    }
+  while (1);
+
+  switch (size)
+  {
   case 1:
-    dbuf_tprintf (oBuf, "\t!db !constbyte\n",ival);
+    dbuf_tprintf (oBuf, "\t!db !constbyte\n", ival);
     break;
 
   case 2:
-    dbuf_tprintf (oBuf, "\t!dw !constword\n",ival);
+    dbuf_tprintf (oBuf, "\t!dw !constword\n", ival);
     break;
+
   case 4:
     dbuf_tprintf (oBuf, "\t!dw  !constword,!constword\n",
-             (ival >> 16) & 0xffff, (ival & 0xffff));
+      (ival >> 16) & 0xffff, (ival & 0xffff));
     break;
   }
   *sym = lsym;
index 94ad4d70705893e2e8879f845a49f35395165c9f..a27c0ec60c9f80a5486768c1f2b253fbbb6ec088 100644 (file)
@@ -1280,16 +1280,17 @@ compStructSize (int su, structdef * sdef)
       if (!loop->etype->select.s.b_signed)
         SPEC_USIGN(loop->etype) = 1;
 
-      SPEC_BLEN (loop->etype) = loop->bitVar;
-
       if (loop->bitVar == BITVAR_PAD) {
         /* A zero length bitfield forces padding */
-        SPEC_BSTR (loop->etype) = bitOffset;
         SPEC_BLEN (loop->etype) = 0;
-        bitOffset = 8;
+        SPEC_BSTR (loop->etype) = bitOffset;
+        if (bitOffset > 0)
+          bitOffset = 8; /* padding is not needed when at bit 0 */
         loop->offset = sum;
       }
       else {
+        SPEC_BLEN (loop->etype) = loop->bitVar;
+
         if (bitOffset == 8) {
           bitOffset = 0;
           sum++;
diff --git a/support/regression/tests/bug-1981238.c b/support/regression/tests/bug-1981238.c
new file mode 100644 (file)
index 0000000..e9b4cb9
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+    bug1981238.c
+*/
+#include <testfwk.h>
+
+code struct {
+  char x:1;
+  char :0;
+  char d:2;
+  char b:6;
+} pad ={1, 2, 1};
+
+code struct {
+  int p:1;
+  int q:7;
+  int :0;
+  int s:1;
+  int t:7;
+} noPad ={1, 120, 1, 1, 127};
+
+code struct {
+  char :0;
+  char b;
+} initialNoPad[] ={{1, 2}, {3,4}};
+
+void testBitfield (void)
+{
+  ASSERT (sizeof (pad) == 2);
+  ASSERT (sizeof (noPad) == 2);
+  ASSERT (sizeof (initialNoPad[0]) == 1);
+}