| 1 |
// RUN: %clang_analyze_cc1 -verify -Wno-objc-root-class %s \ |
| 2 |
// RUN: -Wno-tautological-pointer-compare \ |
| 3 |
// RUN: -analyzer-checker=core \ |
| 4 |
// RUN: -analyzer-checker=nullability \ |
| 5 |
// RUN: -analyzer-checker=debug.ExprInspection |
| 6 |
|
| 7 |
void clang_analyzer_eval(int); |
| 8 |
|
| 9 |
@interface TestFunctionLevelAnnotations |
| 10 |
- (void)method1:(int *_Nonnull)x; |
| 11 |
- (void)method2:(int *)x __attribute__((nonnull)); |
| 12 |
@end |
| 13 |
|
| 14 |
@implementation TestFunctionLevelAnnotations |
| 15 |
- (void)method1:(int *_Nonnull)x { |
| 16 |
clang_analyzer_eval(x != 0); // expected-warning{{TRUE}} |
| 17 |
} |
| 18 |
|
| 19 |
- (void)method2:(int *)x { |
| 20 |
clang_analyzer_eval(x != 0); // expected-warning{{TRUE}} |
| 21 |
} |
| 22 |
@end |
| 23 |
|
| 24 |
typedef struct NestedNonnullMember { |
| 25 |
struct NestedNonnullMember *Child; |
| 26 |
int *_Nonnull Value; |
| 27 |
} NestedNonnullMember; |
| 28 |
|
| 29 |
NestedNonnullMember *foo(void); |
| 30 |
|
| 31 |
void f1(NestedNonnullMember *Root) { |
| 32 |
NestedNonnullMember *Grandson = Root->Child->Child; |
| 33 |
|
| 34 |
clang_analyzer_eval(Root->Value != 0); // expected-warning{{TRUE}} |
| 35 |
clang_analyzer_eval(Grandson->Value != 0); // expected-warning{{TRUE}} |
| 36 |
clang_analyzer_eval(foo()->Child->Value != 0); // expected-warning{{TRUE}} |
| 37 |
} |
| 38 |
|
| 39 |
// Check that we correctly process situations when non-pointer parameters |
| 40 |
// get nonnul attributes. |
| 41 |
typedef struct { |
| 42 |
long a; |
| 43 |
} B; |
| 44 |
__attribute__((nonnull)) void c(B x, int *y); |
| 45 |
|
| 46 |
void c(B x, int *y) { |
| 47 |
clang_analyzer_eval(y != 0); // expected-warning{{TRUE}} |
| 48 |
} |