From: borutr Date: Sun, 31 Aug 2008 09:10:06 +0000 (+0000) Subject: * src/SDCCsymt.c, src/SDCCglue.c, X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=122a98623b6e7e3811469a36163421079652966a * src/SDCCsymt.c, src/SDCCglue.c, 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 --- diff --git a/ChangeLog b/ChangeLog index 7beca775..16284505 100644 --- 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 diff --git a/src/SDCCglue.c b/src/SDCCglue.c index fed61f89..4194fa1c 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -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; diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 94ad4d70..a27c0ec6 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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 index 00000000..e9b4cb9d --- /dev/null +++ b/support/regression/tests/bug-1981238.c @@ -0,0 +1,31 @@ +/* + bug1981238.c +*/ +#include + +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); +}