brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · f0daaad Raw
41 lines · plain
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -Wno-objc-root-class %s2 3extern void clang_analyzer_warnIfReached(void);4void clang_analyzer_eval(int);5 6@interface SomeClass7-(id)someMethodWithReturn;8-(void)someMethod;9@end10 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-warning18    }19  }20}21 22void maybeNilReceiverIsNotNilAfterMessage(SomeClass *o) {23  [o someMethod];24 25  // We intentionally drop the nil flow (losing coverage) after a method26  // call when the receiver may be nil in order to avoid inconsistencies of27  // 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 message36    // 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}41