From 8e6223aa3e8082a6f4be63a3aa2d05d4d7a8c4a5 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Wed, 23 Apr 2008 13:27:33 +0000 Subject: [PATCH] * src/SDCCglue.c (printIvalType, printIvalBitFields): fixed bug 1856409 * 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 | 5 +++ src/SDCCglue.c | 48 ++++++++++++++++++--------- support/regression/tests/bug1856409.c | 34 +++++++++++++++++++ 3 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 support/regression/tests/bug1856409.c diff --git a/ChangeLog b/ChangeLog index 646a53ce..19fd8384 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-04-23 Maarten Brock + + * src/SDCCglue.c (printIvalType, printIvalBitFields): fixed bug 1856409 + * support/regression/tests/bug1856409.c: new, added + 2008-04-20 Maarten Brock * src/z80/peep.c, diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 7aed6a58..fed61f89 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -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 index 00000000..1fb232ea --- /dev/null +++ b/support/regression/tests/bug1856409.c @@ -0,0 +1,34 @@ +/* + bug 1856409 + storage: static code, +*/ + +#include +#include + +#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)); +} -- 2.47.2