analyzer: add heuristics for switch on enum type [PR105273]
[platform/upstream/gcc.git] / gcc / testsuite / gcc.dg / analyzer / torture / switch-enum-pr105273-git-vreportf-1.c
1 typedef __SIZE_TYPE__ size_t;
2 int snprintf(char *str, size_t size, const char *format, ...);
3
4 enum usage_kind {
5         USAGE_ERROR,
6         USAGE_BUG,
7 };
8
9 static void __analyzer_vreportf(enum usage_kind kind)
10 {
11         char buf[256];
12         const char *pfx;
13
14         switch (kind) {
15         case USAGE_ERROR:
16                 pfx = "error: ";
17                 break;
18         case USAGE_BUG:
19                 pfx = "BUG: ";
20                 break;
21         }
22
23         if (kind == USAGE_BUG)
24                 snprintf(buf, sizeof(buf), "%s%s:%d: ", pfx, "file", 123);
25         else
26                 snprintf(buf, sizeof(buf), "%s", pfx);
27 }
28
29 int main(void)
30 {
31         __analyzer_vreportf(USAGE_ERROR);
32         __analyzer_vreportf(USAGE_BUG);
33
34         return 0;
35 }