From 7e7397e33149e0a075535a1a19511b00827693eb Mon Sep 17 00:00:00 2001 From: borutr Date: Sat, 15 Nov 2008 17:27:17 +0000 Subject: [PATCH] * support/regression/tests/bitfields.c: added test case for RFE #2291335 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5268 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 4 +++- src/SDCCglue.c | 9 ++++--- src/pic16/glue.c | 1 + support/regression/tests/bitfields.c | 35 +++++++++++++++++++++++++++- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05aa48cd..c40df206 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,9 @@ * src/pic16/glue.c, src/SDCC.y, src/SDCCast.c, src/SDCCglue.c, src/SDCCsymt.c, src/SDCCsymt.h: - unnamed bitfields are not initialized (gcc, msvc comatibility) + fixed RFE #2291335 : Unnamed bit-field initialization + * support/regression/tests/bitfields.c: + added test case for RFE #2291335 2008-11-11 Raphael Neider diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 060ef515..c65ca88a 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -660,6 +660,7 @@ printIvalBitFields (symbol **sym, initList **ilist, struct dbuf_s * oBuf) if (0 == SPEC_BLEN (lsym->etype)) { /* bit-field structure member with a width of 0 */ + lsym = lsym->next; break; } else if (!SPEC_BUNNAMED (lsym->etype)) @@ -744,9 +745,11 @@ printIvalStruct (symbol * sym, sym_link * type, if (IS_BITFIELD (sflds->type)) printIvalBitFields(&sflds, &iloop, oBuf); else - printIval (sym, sflds->type, iloop, oBuf, 1); - sflds = sflds->next; - iloop = iloop ? iloop->next : NULL; + { + printIval (sym, sflds->type, iloop, oBuf, 1); + sflds = sflds->next; + iloop = iloop ? iloop->next : NULL; + } } } diff --git a/src/pic16/glue.c b/src/pic16/glue.c index 374537b0..2d1b5316 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -792,6 +792,7 @@ pic16_printIvalBitFields (symbol **sym, initList **ilist, char ptype, void *p) if (0 == SPEC_BLEN (lsym->etype)) { /* bit-field structure member with a width of 0 */ + lsym = lsym->next; break; } else if (!SPEC_BUNNAMED (lsym->etype)) diff --git a/support/regression/tests/bitfields.c b/support/regression/tests/bitfields.c index 1d3b2f2c..a7882e9f 100644 --- a/support/regression/tests/bitfields.c +++ b/support/regression/tests/bitfields.c @@ -22,7 +22,6 @@ struct { long l17_15 : 15; } l_bf; - struct { unsigned int b0 : 1; unsigned int b1 : 1; @@ -387,3 +386,37 @@ testSignedBitfields(void) ASSERT(s_bf.s8_9 > 0); #endif /* !SDCC_pic16 */ } + +/* test case for enhancement request #2291335 : Unnamed bit-field initialization */ + +struct s2291335_1 { + int a : 2; + char : 2; + int b : 2; +}; + +struct s2291335_2 { + int a : 2; + char : 0; + int b : 2; +}; + +struct s2291335_1 gs2291335_1 = {1, 2}; +struct s2291335_2 gs2291335_2 = {1, 2}; + +void +__test2291335(void) +{ + struct s2291335_1 ls2291335_1 = {1, 2}; + struct s2291335_2 ls2291335_2 = {1, 2}; + + ASSERT(gs2291335_1.a == 1); + ASSERT(gs2291335_1.b == 2); + ASSERT(gs2291335_2.a == 1); + ASSERT(gs2291335_2.b == 2); + + ASSERT(ls2291335_1.a == 1); + ASSERT(ls2291335_1.b == 2); + ASSERT(ls2291335_2.a == 1); + ASSERT(ls2291335_2.b == 2); +} -- 2.30.2