llvm-project/clang/test/Analysis/nullability-arc.mm
songruiwang b22a5d4617 [analyzer] Fix false negative when pass implicit cast nil to nonnull
We should look through implicit casts before determining the type of the arguments, and only allow explicit cast to _Nonnull to suppress warning

```
void foo(NSString *_Nonnull);

foo((NSString * _Nonnull)nil); // no-warning
id obj = nil;
foo(obj); // should warning here (implicit cast id to NSString *_Nonnull)

```

Reviewed By: xazax.hun, steakhal

Differential Revision: https://reviews.llvm.org/D154221
2023-07-06 22:36:51 +08:00

31 lines
741 B
Plaintext

// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,nullability\
// RUN: -analyzer-output=text -verify %s
// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,nullability\
// RUN: -analyzer-output=text -verify %s -fobjc-arc
#define nil ((id)0)
@interface Param
@end
@interface Base
- (void)foo:(Param *_Nonnull)param;
@end
@interface Derived : Base
@end
@implementation Derived
- (void)foo:(Param *)param {
// FIXME: Why do we not emit the warning under ARC?
[super foo:param];
[self foo:nil];
// expected-warning@-1{{nil passed to a callee that requires a non-null 1st parameter}}
// expected-note@-2 {{nil passed to a callee that requires a non-null 1st parameter}}
}
@end