llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

-Wnullable-to-nonnull-conversion not recognizing 'nil' as nullable

Open llvmbot opened this issue 10 years ago • 3 comments

Bugzilla Link 26664
Version unspecified
OS MacOS X
Reporter LLVM Bugzilla Contributor
CC @devincoughlin,@AnnaZaks

Extended Description

CLANG_ANALYZER_NONNULL with Xcode 7.3 Beta 3 is giving incomplete warnings.

Steps to Reproduce:

NSString * _Nonnull foo = nil;

Actual result: no warning Expected result: warning for converting from Nullable to Nonnull.

Workaround: one can define this macro...

#define __DARWIN_NULL ((void * _Nullable)0)

llvmbot avatar Feb 18 '16 19:02 llvmbot

This is tracked internally as rdar://problem/24724255/

devincoughlin avatar Feb 18 '16 21:02 devincoughlin

There are two separate warnings mentioned here. One is a compiler warning (-Wnullable-to-nonnull-conversion). The other is a static analyzer warning (the nullability checker).

The analyzer does warn here:

$ cat local-nonnull.m #include <Foundation/Foundation.h> void foo() { NSString * _Nonnull foo = nil; (void)foo; }

$ clang --analyze local-nonnull.m local-nonnull.m:4:3: warning: Null is assigned to a pointer which is expected to have non-null value NSString * _Nonnull foo = nil; ^~~~~~~~~~~~~~~~~~~~~~~ ~~~ 1 warning generated.

But the compiler does not:

$ clang -fsyntax-only -Wnullable-to-nonnull-conversion local-nonnull.m

(No warnings).

devincoughlin avatar Feb 18 '16 20:02 devincoughlin

assigned to @adrian-prantl

llvmbot avatar Feb 18 '16 19:02 llvmbot