Dot notation runs intermediate parts multiple times

Originator:joachimb
Number:rdar://6816055 Date Originated:22-Apr-2009 04:00 PM
Status:Duplicate/6220490 Resolved:
Product:Developer Tools Product Version:gcc 4.0, Xcode 3.1.2
Classification:Serious Bug Reproducible:Always
 
Summary:
Parts before the dot in dot notation accessor calls runs twice

Reduced case:
#import <Foundation/Foundation.h>

@interface Foo : NSObject
{
@public;
	int callNo;
}
@property (readonly) int blah;
-(Foo*)mustNotRunTwice;
@end
@implementation Foo
-(Foo*)mustNotRunTwice;
{
	callNo++;
	NSLog(@"mustNotRunTwice called %d time%s.", callNo, (callNo==1)?"":"s");
	return self;
}
-(int)blah; { return 0; }
@end


int main (int argc, const char * argv[]) {
	Foo *foo = [Foo new];
	
	NSLog(@"Method accessor:");
	foo->callNo = 0;
	[[foo mustNotRunTwice] blah];
	
	NSLog(@"Dot accessor:");
	foo->callNo = 0;
	[foo mustNotRunTwice].blah;
	
    return 0;
}


Steps to Reproduce:
1. Compile the above as a Foundation tool

Expected Results:
2009-04-22 15:50:56.246 DotNotationBug[75608:10b] Method accessor:
2009-04-22 15:50:56.249 DotNotationBug[75608:10b] mustNotRunTwice called 1 time.
2009-04-22 15:50:56.250 DotNotationBug[75608:10b] Dot accessor:
2009-04-22 15:50:56.250 DotNotationBug[75608:10b] mustNotRunTwice called 1 time.

Actual Results:
2009-04-22 15:50:56.246 DotNotationBug[75608:10b] Method accessor:
2009-04-22 15:50:56.249 DotNotationBug[75608:10b] mustNotRunTwice called 1 time.
2009-04-22 15:50:56.250 DotNotationBug[75608:10b] Dot accessor:
2009-04-22 15:50:56.250 DotNotationBug[75608:10b] mustNotRunTwice called 1 time.
2009-04-22 15:50:56.251 DotNotationBug[75608:10b] mustNotRunTwice called 2 times.


Regression:
The bug appears fixed in GCC 4.2. 4.0 is however default in MacOS and a lot of developers are affected by this bug without knowing (imagine for example [foo autorelease].bar or [foo retain].bar). Also, 4.2 doesn't work on the iPhone as far as I know (and I use dot notation *a lot* in my iPhone apps, probably enough that this would affect performance if immediate steps are expensive).

Notes:
See also rdar://6671614

Comments


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!