[Issue 3398] Attributes inside a union screws data alignment
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 9 00:32:05 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3398
--- Comment #3 from Don <clugdbug at yahoo.com.au> 2010-06-09 00:31:56 PDT ---
PATCH: Currently, after processing every field, sc->offset gets changed, and
StructDeclaration::semantic() sets the offset back to zero if it was a union.
This patch moves the processing to AggregateDeclaration::addField() instead. If
it's a union, don't change the offset in the first place.
Index: struct.c
===================================================================
--- struct.c (revision 527)
+++ struct.c (working copy)
@@ -194,20 +194,23 @@
sizeok = 2; // cannot finish; flag as forward referenced
return;
}
+ size_t ofs = sc->offset;
memsize = t->size(loc);
memalignsize = t->alignsize();
xalign = t->memalign(sc->structalign);
- alignmember(xalign, memalignsize, &sc->offset);
- v->offset = sc->offset;
- sc->offset += memsize;
- if (sc->offset > structsize)
- structsize = sc->offset;
+ alignmember(xalign, memalignsize, &ofs);
+ v->offset = ofs;
+ ofs += memsize;
+ if (ofs > structsize)
+ structsize = ofs;
if (sc->structalign < memalignsize)
memalignsize = sc->structalign;
if (alignsize < memalignsize)
alignsize = memalignsize;
//printf("\talignsize = %d\n", alignsize);
+ if (!isUnionDeclaration())
+ sc->offset = ofs;
v->storage_class |= STCfield;
//printf(" addField '%s' to '%s' at offset %d, size = %d\n", v->toChars(),
toChars(), v->offset, memsize);
@@ -386,8 +389,6 @@
{
Dsymbol *s = (Dsymbol *)members->data[i];
s->semantic(sc2);
- if (isUnionDeclaration())
- sc2->offset = 0;
#if 0
if (sizeok == 2)
{ //printf("forward reference\n");
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list