1 // RUN: %clang_cc1 -std=c99 -analyze -analyzer-checker=core,alpha.core.BoolAssignment -analyzer-store=region -verify %s
2
3 // Test stdbool.h's _Bool
4
5 // Prior to C99, stdbool.h uses this typedef, but even in ANSI C mode, _Bool
6 // appears to be defined.
7
8 // #if __STDC_VERSION__ < 199901L
9 // typedef int _Bool;
10 // #endif
11
test_stdbool_initialization(int y)12 void test_stdbool_initialization(int y) {
13 if (y < 0) {
14 _Bool x = y; // expected-warning {{Assignment of a non-Boolean value}}
15 return;
16 }
17 if (y > 1) {
18 _Bool x = y; // expected-warning {{Assignment of a non-Boolean value}}
19 return;
20 }
21 _Bool x = y; // no-warning
22 }
23
test_stdbool_assignment(int y)24 void test_stdbool_assignment(int y) {
25 _Bool x = 0; // no-warning
26 if (y < 0) {
27 x = y; // expected-warning {{Assignment of a non-Boolean value}}
28 return;
29 }
30 if (y > 1) {
31 x = y; // expected-warning {{Assignment of a non-Boolean value}}
32 return;
33 }
34 x = y; // no-warning
35 }
36