Function/Method parameters declared with NSError** handles do not get flagged by compiler if they are assigned within a block.

Originator:SelfTransformingElfMachine
Number:rdar://29046901 Date Originated:11/01/2016
Status:Closed Resolved:Duplicate of 15377548 (Open)
Product:Developer Tools Product Version:Xcode 8/8.1
Classification: Reproducible:Always
 
This crash is only reproducible on iOS 10 when building with Xcode 8 or 8.1.

Summary:
Given a function or method with an NSError** handle as a parameter:
void __VIPErrorHandleBrokenTestFunction(NSError **error)
{
	NSBlockOperation *operation  = [NSBlockOperation blockOperationWithBlock:^{
		if (error) {
			*error = [[NSError alloc] initWithDomain:@"VIPTesting" code:-123 userInfo:@{}];
		}
	}];
	NSOperationQueue *queue = [[NSOperationQueue alloc] init];
	[queue addOperations:@[operation] waitUntilFinished:YES];
}

If I de-reference that error and assign it within a block the compiler will produce crashing code and not flag this as an error or warning.

Steps to Reproduce:
1. Set xcodebuild to use the Xcode 8 toolchain.
2. Compile the attached file in terminal with: `clang -fobjc-arc -framework Foundation NSErrorCrash.m -o NSErrorCrash`
3. Run the compiled executable in terminal with: `./NSErrorCrash `


Expected Results:
Compiler should emit an error or warning indicating that the syntax is wrong and that the inner *error de-reference is going to cause a crash because it is assigning a pointer that is nor marked as __block.

Actual Results:
No warnings/errors are emitted by the compiler. Executable crashes at runtime.

Version:
Xcode 8 and 8.1 all GM versions. Have not tested on Xcode 8 betas.

Notes:


Configuration:


Attachments:
'NSErrorCrash.m' was successfully uploaded.

```
#import <Foundation/Foundation.h>

void __VIPErrorHandleBrokenTestFunction(NSError * __autoreleasing *error)
{
	NSBlockOperation *operation  = [NSBlockOperation blockOperationWithBlock:^{
		if (error) {
			*error = [[NSError alloc] initWithDomain:@"VIPTesting" code:-123 userInfo:@{}];
		}
	}];
	NSOperationQueue *queue = [[NSOperationQueue alloc] init];
	[queue addOperations:@[operation] waitUntilFinished:YES];
}

void __VIPTestBlockCrashOnIOS10BuiltWithXcode8(void)
{
	for (int i = 0; i < 10; i++) {
		NSError *error;
		__VIPErrorHandleBrokenTestFunction(&error);
		//NSLog(@"Error: %@", error);
	}
}


int main(int argc, char *argv[]) {
	@autoreleasepool {
		__VIPTestBlockCrashOnIOS10BuiltWithXcode8();
		
		[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];
		NSLog(@"iOS X autorelease crash bug is fixed!");
	}
}
```

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!