1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config suppress-null-return-paths=false -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify -DSUPPRESSED=1 %s
3 // RUN: %clang_analyze_cc1 -analyzer-checker=core -fobjc-arc -verify -DSUPPRESSED=1 %s
4 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config avoid-suppressing-null-argument-paths=true -DSUPPRESSED=1 -DNULL_ARGS=1 -verify %s
6 #define ARC __has_feature(objc_arc)
9 // expected-no-diagnostics
12 @interface PointerWrapper
21 void testNilReceiverHelperA(int *x) {
24 // expected-warning@-2 {{Dereference of null pointer}}
28 void testNilReceiverHelperB(int *x) {
30 #if !defined(SUPPRESSED)
31 // expected-warning@-2 {{Dereference of null pointer}}
35 void testNilReceiver(int coin) {
38 testNilReceiverHelperA([x getPtr]);
40 testNilReceiverHelperB([[x getObject] getPtr]);
43 // FALSE NEGATIVES (over-suppression)
45 __attribute__((objc_root_class))
46 @interface SomeClass {
49 -(int *)methodReturningNull;
51 @property(readonly) int *propertyReturningNull;
53 @property(readonly) int *synthesizedProperty;
55 @property(readonly) SomeClass *propertyReturningNil;
59 @interface SubOfSomeClass : SomeClass
62 @implementation SubOfSomeClass
65 @implementation SomeClass
66 -(int *)methodReturningNull {
70 -(int *)propertyReturningNull {
74 -(SomeClass *)propertyReturningNil {
78 +(int *)classPropertyReturningNull {
83 void testMethodReturningNull(SomeClass *sc) {
84 int *result = [sc methodReturningNull];
87 // expected-warning@-2 {{Dereference of null pointer}}
91 void testPropertyReturningNull(SomeClass *sc) {
92 int *result = sc.propertyReturningNull;
95 // expected-warning@-2 {{Dereference of null pointer}}
99 @implementation SubOfSomeClass (ForTestOfSuperProperty)
100 -(void)testSuperPropertyReturningNull {
101 int *result = super.propertyReturningNull;
104 // expected-warning@-2 {{Dereference of null pointer}}
109 void testClassPropertyReturningNull(void) {
110 int *result = SomeClass.classPropertyReturningNull;
113 // expected-warning@-2 {{Dereference of null pointer}}
117 @implementation SomeClass (ForTestOfPropertyReturningNil)
118 void testPropertyReturningNil(SomeClass *sc) {
119 SomeClass *result = sc.propertyReturningNil;
122 // expected-warning@-2 {{Access to instance variable 'ivar' results in a dereference of a null pointer (loaded from variable 'result')}}
127 void testSynthesizedPropertyReturningNull(SomeClass *sc) {
128 if (sc.synthesizedProperty)
131 int *result = sc.synthesizedProperty;
134 // expected-warning@-2 {{Dereference of null pointer}}