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