Calling a C-function that takes a __nonnull argument and passing a weak variable does not yield compiler warning

Originator:nobrien
Number:rdar://40129673 Date Originated:05/10/2018
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 9.3
Classification:Bug/Serious Reproducible:Always
 
Summary:
When a C-function is passed a weak variable for a nonnull argument the compiler should elicit a warning that the provided variable could be `nil` and therefore is not save to pass to a nonnull argument.

Example:


// Function
static void _Foo(MyObject * __nonnull bar)
{
    bar->_fooCount++;
}

// MyObject
@implementation MyObject
{
    NSInteger _fooCount;
}

- (void)asyncFoo
{
    __weak typeof(self) weakSelf = self;
    dispatch_async(SomeQueue(), ^{
        _Foo(weakSelf); // <-- should warn against nil being passed!  Will crash!
    });
}

@end


Steps to Reproduce:
Implement code like the example above

Expected Results:
Compiler elicits a warning (which we'd elect to treat as an error)

Actual Results:
No compiler warning.  In fact, the static analyzer does not yield a warning either!

Notes:
We consider this critical to safety and stability

Version/Build:
Xcode 9.3

Configuration:
macOS High Sierra

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!