Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Storing nullable values to local variables defeats -Wnullable-to-nonnull-conversion #29777

Open Quuxplusone opened 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR30804
Status NEW
Importance P normal
Reported by Timothy J. Wood (tjw@me.com)
Reported on 2016-10-26 18:42:10 -0700
Last modified on 2016-10-26 18:42:10 -0700
Version trunk
Hardware Macintosh MacOS X
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments nonnull-conversion.m (1132 bytes, application/octet-stream)
Blocks
Blocked by
See also
Created attachment 17499
sample case

Adding nullability annotations to ObjC source for correct interoperability with
Swift is made more difficult by the inability of clang to detect if a method
might return nil even if it says it doesn't.

clang apparently has a -Wnullable-to-nonnull-conversion flag to detect cases
like this. While it works for code like:

- (nonnull NSString *)ok:(nullable NSString *)arg;
{
    return arg;
}

it is trivially confused by:

- (nonnull NSString *)bad:(nullable NSString *)arg;
{
    // BAD: nullable value returned to a non-nullable result
    NSString *result = arg;
    return result;
}

Example file attached with a couple variants.
Quuxplusone commented 8 years ago

Attached nonnull-conversion.m (1132 bytes, application/octet-stream): sample case