1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config suppress-inlined-defensive-checks=true -verify %s
3 typedef signed char BOOL;
4 typedef struct objc_class *Class;
5 typedef struct objc_object {
8 @protocol NSObject - (BOOL)isEqual:(id)object; @end
9 @interface NSObject <NSObject> {}
19 // Check that inline defensive checks is triggered for null expressions
20 // within CompoundLiteralExpr.
22 struct dispatch_object_s *_do;
23 struct dispatch_source_s *_ds;
24 } dispatch_object_t __attribute__((__transparent_union__));
25 typedef struct dispatch_source_s *dispatch_source_t;
27 extern __attribute__((visibility("default"))) __attribute__((__nonnull__)) __attribute__((__nothrow__))
29 dispatch_resume(dispatch_object_t object);
31 @interface AppDelegate : NSObject {
36 @implementation AppDelegate
37 - (void)updateDeleteTimer {
41 - (void)createAndStartDeleteTimer {
42 [self updateDeleteTimer];
43 dispatch_resume(p); // no warning
47 // Test nil receiver suppression.
48 // We only suppress on nil receiver if the nil value is directly causing the bug.
60 Foo *retInputOrNil(Foo *p) {
71 int testNilReceiver(Foo* fPtr) {
74 // On a path where fPtr is nil, mem should be nil.
75 Foo *mem = [fPtr getFooPtr];
76 return mem->x; // expected-warning {{Access to instance variable 'x' results in a dereference of a null pointer}}
79 int suppressNilReceiverRetNullCond(Foo* fPtr) {
81 fPtr = retInputOrNil(fPtr);
82 // On a path where fPtr is nzil, mem should be nil.
83 Foo *mem = [fPtr getFooPtr];
87 int suppressNilReceiverRetNullCondCast(id fPtr) {
89 fPtr = retInputOrNil(fPtr);
90 // On a path where fPtr is nzil, mem should be nil.
91 Foo *mem = ((id)([(Foo*)(fPtr) getFooPtr]));
95 int dontSuppressNilReceiverRetNullCond(Foo* fPtr) {
97 fPtr = retInputOrNil(fPtr);
98 // On a path where fPtr is nil, mem should be nil.
99 // The warning is not suppressed because the receiver being nil is not
100 // directly related to the value that triggers the warning.
101 Foo *mem = [fPtr getFooPtr];
103 return 5/zero; // expected-warning {{Division by zero}}
107 int dontSuppressNilReceiverRetNull(Foo* fPtr) {
110 // On a path where fPtr is nil, mem should be nil.
111 // The warning is not suppressed because the receiver being nil is not
112 // directly related to the value that triggers the warning.
113 Foo *mem = [fPtr getFooPtr];
115 return 5/zero; // expected-warning {{Division by zero}}
119 int dontSuppressNilReceiverIDC(Foo* fPtr) {
122 // On a path where fPtr is nil, mem should be nil.
123 // The warning is not suppressed because the receiver being nil is not
124 // directly related to the value that triggers the warning.
125 Foo *mem = [fPtr getFooPtr];
127 return 5/zero; // expected-warning {{Division by zero}}