blob: f525ce7968ddc6a64596621ca889429b82bb6659 [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify -Wno-objc-root-class %s
Devin Coughlinca5ab2b2015-09-15 01:13:53 +00002
3extern void clang_analyzer_warnIfReached();
4void clang_analyzer_eval(int);
5
6@interface SomeClass
7-(id)someMethodWithReturn;
8-(void)someMethod;
9@end
10
11void consistencyOfReturnWithNilReceiver(SomeClass *o) {
12 id result = [o someMethodWithReturn];
13 if (result) {
14 if (!o) {
15 // It is impossible for both o to be nil and result to be non-nil,
16 // so this should not be reached.
17 clang_analyzer_warnIfReached(); // no-warning
18 }
19 }
20}
21
22void maybeNilReceiverIsNotNilAfterMessage(SomeClass *o) {
23 [o someMethod];
24
25 // We intentionally drop the nil flow (losing coverage) after a method
26 // call when the receiver may be nil in order to avoid inconsistencies of
27 // the kind tested for in consistencyOfReturnWithNilReceiver().
28 clang_analyzer_eval(o != 0); // expected-warning{{TRUE}}
29}
30
31void nilReceiverIsStillNilAfterMessage(SomeClass *o) {
32 if (o == 0) {
33 id result = [o someMethodWithReturn];
34
35 // Both the receiver and the result should be nil after a message
36 // sent to a nil receiver returning a value of type id.
37 clang_analyzer_eval(o == 0); // expected-warning{{TRUE}}
38 clang_analyzer_eval(result == 0); // expected-warning{{TRUE}}
39 }
40}