smdb.py: print the return_implies value
[smatch.git] / validation / enum-common.c
blobf940fefacc5852dbbc4fb95ce5023193e18198ab
1 static enum ENUM_TYPE_A { VALUE_A } var_a;
2 static enum ENUM_TYPE_B { VALUE_B } var_b;
3 static enum /* anon. */ { VALUE_C } anon_enum_var;
4 static int i;
6 static void take_enum_of_type_a(enum ENUM_TYPE_A arg_enum)
8 (void) arg_enum;
11 static void take_int(int arg_int)
13 (void) arg_int;
16 static void always_ok(void)
18 var_a ++;
19 var_a = VALUE_A;
20 var_a = (enum ENUM_TYPE_A) VALUE_B;
21 var_b = (enum ENUM_TYPE_B) i;
22 i = (int) VALUE_A;
23 anon_enum_var = VALUE_C;
24 i = VALUE_C;
25 i = anon_enum_var;
26 i = 7;
27 var_a = (enum ENUM_TYPE_A) 0;
28 anon_enum_var = (__typeof__(anon_enum_var)) 0;
29 anon_enum_var = (__typeof__(anon_enum_var)) VALUE_A;
31 switch (var_a) {
32 case VALUE_A:
33 default:
34 take_enum_of_type_a(var_a);
35 take_enum_of_type_a(VALUE_A);
38 switch (anon_enum_var) {
39 case VALUE_C:
40 default:
41 take_int(anon_enum_var);
44 switch (i) {
45 case VALUE_C:
46 default:
47 take_int(VALUE_C);
51 static void trigger_enum_mismatch(void)
53 switch (var_a) {
54 case VALUE_B:
55 case VALUE_C:
56 default:
57 take_enum_of_type_a(var_b);
58 take_enum_of_type_a(VALUE_B);
61 switch (anon_enum_var) {
62 case VALUE_A:
63 default:
64 take_enum_of_type_a(anon_enum_var);
65 take_enum_of_type_a(VALUE_C);
68 // this has been already working in sparse 0.4.1
69 var_a = var_b;
70 var_b = anon_enum_var;
71 anon_enum_var = var_a;
73 // implemented after sparse 0.4.1
74 var_a = VALUE_B;
75 var_b = VALUE_C;
76 anon_enum_var = VALUE_A;
79 static void trigger_int_to_enum_conversion(void)
81 switch (var_a) {
82 case 0:
83 default:
84 take_enum_of_type_a(i);
85 take_enum_of_type_a(7);
87 var_a = 0;
88 var_b = i;
89 anon_enum_var = 0;
90 anon_enum_var = i;
91 var_a = (int) VALUE_A;
92 var_a = (int) VALUE_B;
95 static void trigger_enum_to_int_conversion(void)
97 i = var_a;
98 i = VALUE_B;
99 switch (i) {
100 case VALUE_A:
101 case VALUE_B:
102 default:
103 take_int(var_a);
104 take_int(VALUE_B);
109 * check-name: enum-common
110 * check-description: common part of the test for -Wenum-mismatch, -Wenum-to-int and -Wint-to-enum
111 * check-command: sparse -Wno-enum-mismatch -Wno-int-to-enum $file