Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/switch-enum-2.c

raw
1 #include "analyzer-decls.h"
2
3 /* Verify the handling of "switch (enum_value)". */
4
5 enum e
6 {
7 E_VAL0,
8 E_VAL1,
9 E_VAL2,
10
11 E_VAL10 = 10,
12 E_VAL11 = 11,
13 E_VAL12 = 12,
14
15 E_VAL20 = 20,
16 E_VAL21 = 21,
17 E_VAL22 = 22
18 };
19
20 /* Verify that we assume that "switch (enum)" doesn't follow implicit
21 "default" if all enum values have cases */
22
23 int test_all_values_covered_implicit_default_1 (enum e x)
24 {
25 switch (x)
26 {
27 case E_VAL0...E_VAL2:
28 return 1066;
29 case E_VAL10...E_VAL12:
30 return 1776;
31 case E_VAL20...E_VAL22:
32 return 1945;
33 }
34 __analyzer_dump_path (); /* { dg-bogus "path" } */
35 }
36
37 int test_all_values_covered_implicit_default_2 (enum e x)
38 {
39 int result;
40 switch (x)
41 {
42 case E_VAL0...E_VAL2:
43 result = 1066;
44 break;
45 case E_VAL10...E_VAL12:
46 result = 1776;
47 break;
48 case E_VAL20...E_VAL22:
49 result = 1945;
50 break;
51 }
52 return result; /* { dg-bogus "uninitialized" } */
53 }
54
55 /* Verify that we consider paths that use the implicit default when not
56 all enum values are covered by cases. */
57
58 int test_missing_values_implicit_default_1 (enum e x)
59 {
60 switch (x) /* { dg-message "following 'default:' branch" } */
61 {
62 case E_VAL0...E_VAL2:
63 return 1066;
64 case E_VAL10...E_VAL12:
65 return 1776;
66 }
67 __analyzer_dump_path (); /* { dg-message "path" } */
68 return 0;
69 }
70
71 int test_missing_values_implicit_default_2 (enum e x)
72 {
73 int result;
74 switch (x) /* { dg-message "following 'default:' branch" } */
75 {
76 case E_VAL0...E_VAL2:
77 result = 1066;
78 break;
79 case E_VAL10...E_VAL12:
80 result = 1776;
81 break;
82 }
83 return result; /* { dg-warning "uninitialized" } */
84 }
85
86 /* Verify that explicit "default" isn't rejected. */
87
88 int test_all_values_covered_explicit_default_1 (enum e x)
89 {
90 switch (x)
91 {
92 case E_VAL0...E_VAL2:
93 return 1066;
94 case E_VAL10...E_VAL12:
95 return 1776;
96 case E_VAL20...E_VAL22:
97 return 1945;
98 default:
99 __analyzer_dump_path (); /* { dg-message "path" } */
100 return 0;
101 }
102 }
103
104 int test_missing_values_explicit_default_1 (enum e x)
105 {
106 switch (x)
107 {
108 default:
109 case E_VAL0...E_VAL2:
110 return 1066;
111 case E_VAL10...E_VAL12:
112 return 1776;
113 }
114 __analyzer_dump_path (); /* { dg-bogus "path" } */
115 return 0;
116 }
117
118 int test_missing_values_explicit_default_2 (enum e x)
119 {
120 switch (x)
121 {
122 case E_VAL0...E_VAL2:
123 return 1066;
124 case E_VAL10...E_VAL12:
125 return 1776;
126 default:
127 __analyzer_dump_path (); /* { dg-message "path" } */
128 return 1945;
129 }
130 __analyzer_dump_path (); /* { dg-bogus "path" } */
131 return 0;
132 }