When moving ivars to increase their alignment, make sure later ivars are

also moved.

Fixes #27
main
David Chisnall 9 years ago
parent 695282e5d7
commit 4fd27a066f

@ -26,6 +26,7 @@ set(TESTS
WeakBlock_arc.m
WeakReferences_arc.m
ivar_arc.m
IVarOverlap.m
objc_msgSend.m
msgInterpose.m
NilException.m

@ -0,0 +1,30 @@
#import <stdio.h>
#import "../objc/objc.h"
#import "../objc/runtime.h"
#import "../objc/Object.h"
#include "Test.h"
#import <sys/types.h>
#import <sys/stat.h>
@interface Dummy : Test
{
id objOne;
struct stat statBuf;
BOOL flagOne;
}
@end
@implementation Dummy
- (void)test
{
assert((char*)&statBuf+sizeof(struct stat) <= (char*)&flagOne);
}
@end
int main(int argc, char *argv[])
{
[[Dummy new] test];
return 0;
}

@ -47,6 +47,7 @@ PRIVATE void objc_compute_ivar_offsets(Class class)
*/
if (class->ivars)
{
long cumulative_fudge = 0;
for (i = 0 ; i < class->ivars->count ; i++)
{
struct objc_ivar *ivar = &class->ivars->ivar_list[i];
@ -58,6 +59,7 @@ PRIVATE void objc_compute_ivar_offsets(Class class)
? (class_size - ivar->offset)
: class->ivars->ivar_list[i+1].offset - ivar->offset ;
assert(ivar_size > 0);
ivar->offset += cumulative_fudge;
// We only need to do the realignment for things that are
// bigger than a pointer, and we don't need to do it in GC mode
// where we don't add any extra padding.
@ -71,6 +73,7 @@ PRIVATE void objc_compute_ivar_offsets(Class class)
long fudge = 16 - (offset % 16);
ivar->offset += fudge;
class->instance_size += fudge;
cumulative_fudge += fudge;
assert((ivar_start + ivar->offset + sizeof(intptr_t)) % 16 == 0);
}
ivar->offset += ivar_start;

Loading…
Cancel
Save