Skip to content

Commit

Permalink
Merge pull request #3648 from yebblies/issue10071
Browse files Browse the repository at this point in the history
Issue 10071 - 'real' alignment wrong on OS X 32 bit
  • Loading branch information
WalterBright committed Jun 12, 2014
2 parents 083271a + d9e9991 commit 647917b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/declaration.c
Expand Up @@ -1853,6 +1853,8 @@ void VarDeclaration::setFieldOffset(AggregateDeclaration *ad, unsigned *poffset,
ad->sizeok = SIZEOKfwd; // cannot finish; flag as forward referenced
return;
}
if (t->ty == Terror)
return;


unsigned memsize = (unsigned)t->size(loc); // size of member
Expand Down
12 changes: 4 additions & 8 deletions src/struct.c
Expand Up @@ -431,15 +431,11 @@ void AggregateDeclaration::alignmember(
break;

case (structalign_t) STRUCTALIGN_DEFAULT:
{
/* Must match what the corresponding C compiler's default
* alignment behavior is.
*/
assert(size != 3);
unsigned sa = (size == 0 || 8 < size) ? 8 : size;
*poffset = (*poffset + sa - 1) & ~(sa - 1);
// Alignment in Target::fieldalignsize must match what the
// corresponding C compiler's default alignment behavior is.
assert(size > 0 && !(size & (size - 1)));
*poffset = (*poffset + size - 1) & ~(size - 1);
break;
}

default:
// Align on alignment boundary, which must be a positive power of 2
Expand Down
15 changes: 15 additions & 0 deletions test/runnable/cppa.d
Expand Up @@ -279,6 +279,20 @@ void test11()
}
/****************************************/

struct Struct10071
{
void *p;
real r;
}

extern(C++) size_t offset10071();
void test10071()
{
assert(offset10071() == Struct10071.r.offsetof);
}

/****************************************/

char[100] valistbuffer;

extern(C++) void myvprintfx(const(char)* format, va_list va)
Expand Down Expand Up @@ -331,6 +345,7 @@ void main()
test4();
test5();
test6();
test10071();
test7();
test8();
test11802();
Expand Down
14 changes: 14 additions & 0 deletions test/runnable/extra-files/cppb.cpp
Expand Up @@ -182,6 +182,20 @@ extern "C" { int foo7()

/**************************************/

struct Struct10071
{
void *p;
long double r;
};

size_t offset10071()
{
Struct10071 s;
return (char *)&s.r - (char *)&s;
}

/**************************************/

void foo8(const char *p)
{
}
Expand Down

0 comments on commit 647917b

Please sign in to comment.