blob: e573129994497c8278c181279268dfc962fdd0de [file] [log] [blame]
Ryan Govostesb141b282012-02-11 16:32:09 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core.BoolAssignment -analyzer-store=region -verify %s
2
3// Test C++'s bool
4
5void test_cppbool_initialization(int y) {
6 if (y < 0) {
7 bool x = y; // expected-warning {{Assignment of a non-Boolean value}}
8 return;
9 }
10 if (y > 1) {
11 bool x = y; // expected-warning {{Assignment of a non-Boolean value}}
12 return;
13 }
14 bool x = y; // no-warning
15}
16
17void test_cppbool_assignment(int y) {
18 bool x = 0; // no-warning
19 if (y < 0) {
20 x = y; // expected-warning {{Assignment of a non-Boolean value}}
21 return;
22 }
23 if (y > 1) {
24 x = y; // expected-warning {{Assignment of a non-Boolean value}}
25 return;
26 }
27 x = y; // no-warning
28}
29
30// Test Objective-C's BOOL
31
32typedef signed char BOOL;
33
34void test_BOOL_initialization(int y) {
35 if (y < 0) {
36 BOOL x = y; // expected-warning {{Assignment of a non-Boolean value}}
37 return;
38 }
39 if (y > 1) {
40 BOOL x = y; // expected-warning {{Assignment of a non-Boolean value}}
41 return;
42 }
43 BOOL x = y; // no-warning
44}
45
46void test_BOOL_assignment(int y) {
47 BOOL x = 0; // no-warning
48 if (y < 0) {
49 x = y; // expected-warning {{Assignment of a non-Boolean value}}
50 return;
51 }
52 if (y > 1) {
53 x = y; // expected-warning {{Assignment of a non-Boolean value}}
54 return;
55 }
56 x = y; // no-warning
57}
58
59
60// Test MacTypes.h's Boolean
61
62typedef unsigned char Boolean;
63
64void test_Boolean_initialization(int y) {
65 if (y < 0) {
66 Boolean x = y; // expected-warning {{Assignment of a non-Boolean value}}
67 return;
68 }
69 if (y > 1) {
70 Boolean x = y; // expected-warning {{Assignment of a non-Boolean value}}
71 return;
72 }
73 Boolean x = y; // no-warning
74}
75
76void test_Boolean_assignment(int y) {
77 Boolean x = 0; // no-warning
78 if (y < 0) {
79 x = y; // expected-warning {{Assignment of a non-Boolean value}}
80 return;
81 }
82 if (y > 1) {
83 x = y; // expected-warning {{Assignment of a non-Boolean value}}
84 return;
85 }
86 x = y; // no-warning
87}