annotate clang/test/Analysis/objc-message.m @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify -Wno-objc-root-class %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 extern void clang_analyzer_warnIfReached();
anatofuz
parents:
diff changeset
4 void clang_analyzer_eval(int);
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 @interface SomeClass
anatofuz
parents:
diff changeset
7 -(id)someMethodWithReturn;
anatofuz
parents:
diff changeset
8 -(void)someMethod;
anatofuz
parents:
diff changeset
9 @end
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 void consistencyOfReturnWithNilReceiver(SomeClass *o) {
anatofuz
parents:
diff changeset
12 id result = [o someMethodWithReturn];
anatofuz
parents:
diff changeset
13 if (result) {
anatofuz
parents:
diff changeset
14 if (!o) {
anatofuz
parents:
diff changeset
15 // It is impossible for both o to be nil and result to be non-nil,
anatofuz
parents:
diff changeset
16 // so this should not be reached.
anatofuz
parents:
diff changeset
17 clang_analyzer_warnIfReached(); // no-warning
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19 }
anatofuz
parents:
diff changeset
20 }
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 void maybeNilReceiverIsNotNilAfterMessage(SomeClass *o) {
anatofuz
parents:
diff changeset
23 [o someMethod];
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 // We intentionally drop the nil flow (losing coverage) after a method
anatofuz
parents:
diff changeset
26 // call when the receiver may be nil in order to avoid inconsistencies of
anatofuz
parents:
diff changeset
27 // the kind tested for in consistencyOfReturnWithNilReceiver().
anatofuz
parents:
diff changeset
28 clang_analyzer_eval(o != 0); // expected-warning{{TRUE}}
anatofuz
parents:
diff changeset
29 }
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 void nilReceiverIsStillNilAfterMessage(SomeClass *o) {
anatofuz
parents:
diff changeset
32 if (o == 0) {
anatofuz
parents:
diff changeset
33 id result = [o someMethodWithReturn];
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 // Both the receiver and the result should be nil after a message
anatofuz
parents:
diff changeset
36 // sent to a nil receiver returning a value of type id.
anatofuz
parents:
diff changeset
37 clang_analyzer_eval(o == 0); // expected-warning{{TRUE}}
anatofuz
parents:
diff changeset
38 clang_analyzer_eval(result == 0); // expected-warning{{TRUE}}
anatofuz
parents:
diff changeset
39 }
anatofuz
parents:
diff changeset
40 }