1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.BoolAssignment,alpha.security.taint -verify -std=c99 -Dbool=_Bool %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.BoolAssignment,alpha.security.taint -verify -x c++ %s
4 // Test C++'s bool and C's _Bool.
5 // FIXME: We stopped warning on these when SValBuilder got smarter about
6 // casts to bool. Arguably, however, these conversions are okay; the result
7 // is always 'true' or 'false'.
9 void test_stdbool_initialization(int y
) {
10 bool constant
= 2; // no-warning
12 bool x
= y
; // no-warning
16 bool x
= y
; // no-warning
19 bool x
= y
; // no-warning
22 void test_stdbool_assignment(int y
) {
23 bool x
= 0; // no-warning
35 // Test Objective-C's BOOL
37 typedef signed char BOOL
;
39 void test_BOOL_initialization(int y
) {
40 BOOL constant
= 2; // expected-warning {{Assignment of a non-Boolean value}}
42 BOOL x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
45 if (y
> 200 && y
< 250) {
47 BOOL x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
49 BOOL x
= y
; // no-warning
53 if (y
>= 127 && y
< 150) {
54 BOOL x
= y
; // expected-warning{{Assignment of a non-Boolean value}}
58 BOOL x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
61 BOOL x
= y
; // no-warning
64 void test_BOOL_assignment(int y
) {
65 BOOL x
= 0; // no-warning
67 x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
71 x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
78 // Test MacTypes.h's Boolean
80 typedef unsigned char Boolean
;
82 void test_Boolean_initialization(int y
) {
83 Boolean constant
= 2; // expected-warning {{Assignment of a non-Boolean value}}
85 Boolean x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
89 Boolean x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
92 Boolean x
= y
; // no-warning
95 void test_Boolean_assignment(int y
) {
96 Boolean x
= 0; // no-warning
98 x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
102 x
= y
; // expected-warning {{Assignment of a non-Boolean value}}
108 int scanf(const char *format
, ...);
109 void test_tainted_Boolean() {
112 Boolean copy
= n
; // expected-warning {{Might assign a tainted non-Boolean value}}