iosiphonexcodereleaseiphone-64bit

EXC_BAD_ACCESS in simple code in release


This simple code below works in debug, but fails in release on iPhone 6.

XCode 6.2 (6C131e)

Calling runTest causes the EXC_BAD_ACCESS on the latest 64bit iPhones. And it only happens when build Optimization Levels set 'Faster' and higher: -O2, -O3, -Os or -Ofast. So usually in Release configuration. BTW, the code works well when Optimization Levels set 'None' or 'Fast': -O0 or -O1.

#import <objc/NSObject.h>

@interface Foo : NSObject
@end

@interface Test : NSObject {
    Foo *field;
}
@end

@implementation Foo

- (Foo *)bar {
    return self;
}

@end

@implementation Test

- (void)runTest {
    Foo *foo = [[Foo alloc] init];
    field = foo;
    field = nil;
    [foo bar];
}

@end

Please explain me why this happens.


Solution

  • I posted problem to Apple Bug Reporter, but Apple once requested some more details and then never responded. Now the problem report has completely disappeared.

    By the way this appears to work with clang, version 7.3.