]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/uninit-pr59970.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / uninit-pr59970.c
1 /* PR tree-optimization/59970 - Bogus -Wmaybe-uninitialized at low optimization
2 levels
3 { dg-do compile }
4 { dg-options "-Wall" } */
5
6 #pragma GCC push_options
7 #pragma GCC optimize ("1")
8
9 __attribute__ ((noipa)) int
10 d_demangle_callback_O1 (const char *mangled)
11 {
12 enum { DCT_TYPE, DCT_GLOBAL_DTORS } type;
13 int dc;
14
15 /* Fails for -Og and -O1. */
16 if (mangled)
17 type = DCT_GLOBAL_DTORS;
18 else
19 type = DCT_TYPE;
20
21 /* If both cases assign the same value, all is fine. */
22 switch (type)
23 {
24 case DCT_TYPE:
25 dc = 0 /* 1 */;
26 break;
27 case DCT_GLOBAL_DTORS:
28 dc = /* 0 */ 1;
29 break;
30
31 /* If this is added, all is fine. */
32 #ifdef ABORT
33 default:
34 __builtin_unreachable ();
35 #endif
36 }
37
38 return dc; // { dg-bogus "uninitialized" }
39 }
40
41 #pragma GCC pop_options
42
43
44 #pragma GCC optimize ("Og")
45
46 __attribute__ ((noipa)) int
47 d_demangle_callback_Og (const char *mangled)
48 {
49 enum { DCT_TYPE, DCT_GLOBAL_DTORS } type;
50 int dc;
51
52 /* Fails for -Og. */
53 /* Removing either the function call or the array dereference, it'll be like
54 the TOGGLE1 case. */
55 extern int cmp (void);
56 if (cmp () && mangled[0])
57 type = DCT_GLOBAL_DTORS;
58 else
59 type = DCT_TYPE;
60
61 /* If both cases assign the same value, all is fine. */
62 switch (type)
63 {
64 case DCT_TYPE:
65 dc = 0 /* 1 */;
66 break;
67 case DCT_GLOBAL_DTORS:
68 dc = /* 0 */ 1;
69 break;
70
71 /* If this is added, all is fine. */
72 #ifdef ABORT
73 default:
74 __builtin_unreachable ();
75 #endif
76 }
77
78 return dc; // { dg-bogus "uninitialized" }
79 }