annotate clang/test/Analysis/default-analyze.m @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
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 %s -o %t
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 // Tests that some specific checkers are enabled by default.
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 id foo(int x) {
anatofuz
parents:
diff changeset
6 id title;
anatofuz
parents:
diff changeset
7 switch (x) {
anatofuz
parents:
diff changeset
8 case 1:
anatofuz
parents:
diff changeset
9 title = @"foo"; // expected-warning {{never read}}
anatofuz
parents:
diff changeset
10 case 2:
anatofuz
parents:
diff changeset
11 title = @"bar";
anatofuz
parents:
diff changeset
12 break;
anatofuz
parents:
diff changeset
13 default:
anatofuz
parents:
diff changeset
14 title = @"baz";
anatofuz
parents:
diff changeset
15 break;
anatofuz
parents:
diff changeset
16 }
anatofuz
parents:
diff changeset
17 return title;
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 // <rdar://problem/8808566> Static analyzer is wrong: NSWidth(imgRect) not understood as unconditional assignment
anatofuz
parents:
diff changeset
21 //
anatofuz
parents:
diff changeset
22 // Note: this requires inlining support. This previously issued a false positive use of
anatofuz
parents:
diff changeset
23 // uninitialized value when calling NSWidth.
anatofuz
parents:
diff changeset
24 typedef double CGFloat;
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 struct CGPoint {
anatofuz
parents:
diff changeset
27 CGFloat x;
anatofuz
parents:
diff changeset
28 CGFloat y;
anatofuz
parents:
diff changeset
29 };
anatofuz
parents:
diff changeset
30 typedef struct CGPoint CGPoint;
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 struct CGSize {
anatofuz
parents:
diff changeset
33 CGFloat width;
anatofuz
parents:
diff changeset
34 CGFloat height;
anatofuz
parents:
diff changeset
35 };
anatofuz
parents:
diff changeset
36 typedef struct CGSize CGSize;
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 struct CGRect {
anatofuz
parents:
diff changeset
39 CGPoint origin;
anatofuz
parents:
diff changeset
40 CGSize size;
anatofuz
parents:
diff changeset
41 };
anatofuz
parents:
diff changeset
42 typedef struct CGRect CGRect;
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 typedef CGRect NSRect;
anatofuz
parents:
diff changeset
45 typedef CGSize NSSize;
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 static __inline__ __attribute__((always_inline)) CGFloat NSWidth(NSRect aRect) {
anatofuz
parents:
diff changeset
48 return (aRect.size.width);
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 static __inline__ __attribute__((always_inline)) CGFloat NSHeight(NSRect aRect) {
anatofuz
parents:
diff changeset
52 return (aRect.size.height);
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 NSSize rdar880566_size();
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 double rdar8808566() {
anatofuz
parents:
diff changeset
58 NSRect myRect;
anatofuz
parents:
diff changeset
59 myRect.size = rdar880566_size();
anatofuz
parents:
diff changeset
60 double x = NSWidth(myRect) + NSHeight(myRect); // no-warning
anatofuz
parents:
diff changeset
61 return x;
anatofuz
parents:
diff changeset
62 }
anatofuz
parents:
diff changeset
63