Over-release under ARC with -Os, but not with -O0

Number:rdar://12311693 Date Originated:17-Sep-2012 12:57 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 4.5 (4G182)
Classification:Crash/Hang/Data Loss Reproducible:Always

The attached project crashes due to an over-release when built with compiler optimization turned on (-Os), but does not crash when compiler optimization is turned off (-O0). The project is being built against the iOS 6.0 SDK that was shipped with Xcode 4.5 (4G182) with the Apple LLVM compiler 4.1.

Steps to Reproduce:

1) Inspect the problem-causing code in AppDelegate.m in the attached sample project.
2) Run the attached Xcode project with optimization turned off. Note that the no crashes occur.
3) Run the attached project with optimization set to -Os

Expected Results:

I would expect that no crashes would occur.

Actual Results:

The app crashes when num2 is over-released. Enable Zombie Objects to confirm that this is the case.


Based on my understanding of ARC, this code should not lead to any objects being over-released.

Excerpted sample code:

	// This crashes under -Os, but not under -O0
	NSNumber *num1 = @((float)arc4random() / (float)UINT32_MAX);
	NSNumber *num2 = @((float)arc4random() / (float)UINT32_MAX);

	NSNumber *foo1 = num1;
	NSNumber *foo2 = num2;

	for (NSUInteger i=0; i<2; i++) {

		NSLog(@"foo1: %p %@", foo1, foo1);
		NSLog(@"foo2: %p %@", foo2, foo2);

		// swap foo1 and foo2
		foo1 = num2;
		foo2 = num1;


Cross reference to related Stack Overflow discussion: http://stackoverflow.com/questions/12464074/over-release-under-objc-arc-with-os-but-not-with-o0

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!