1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify -Wno-objc-root-class %s
3 extern void clang_analyzer_warnIfReached(void);
4 void clang_analyzer_eval(int);
7 -(id)someMethodWithReturn;
11 void consistencyOfReturnWithNilReceiver(SomeClass *o) {
12 id result = [o someMethodWithReturn];
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
22 void maybeNilReceiverIsNotNilAfterMessage(SomeClass *o) {
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}}
31 void nilReceiverIsStillNilAfterMessage(SomeClass *o) {
33 id result = [o someMethodWithReturn];
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}}