libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / uninit-pr59970.c
blob145af657a76c2dfaa16453cc8a45c7c5f713eb74
1 /* PR tree-optimization/59970 - Bogus -Wmaybe-uninitialized at low optimization
2 levels
3 { dg-do compile }
4 { dg-options "-Wall" } */
6 #pragma GCC push_options
7 #pragma GCC optimize ("1")
9 __attribute__ ((noipa)) int
10 d_demangle_callback_O1 (const char *mangled)
12 enum { DCT_TYPE, DCT_GLOBAL_DTORS } type;
13 int dc;
15 /* Fails for -Og and -O1. */
16 if (mangled)
17 type = DCT_GLOBAL_DTORS;
18 else
19 type = DCT_TYPE;
21 /* If both cases assign the same value, all is fine. */
22 switch (type)
24 case DCT_TYPE:
25 dc = 0 /* 1 */;
26 break;
27 case DCT_GLOBAL_DTORS:
28 dc = /* 0 */ 1;
29 break;
31 /* If this is added, all is fine. */
32 #ifdef ABORT
33 default:
34 __builtin_unreachable ();
35 #endif
38 return dc; // { dg-bogus "uninitialized" }
41 #pragma GCC pop_options
44 #pragma GCC optimize ("Og")
46 __attribute__ ((noipa)) int
47 d_demangle_callback_Og (const char *mangled)
49 enum { DCT_TYPE, DCT_GLOBAL_DTORS } type;
50 int dc;
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;
61 /* If both cases assign the same value, all is fine. */
62 switch (type)
64 case DCT_TYPE:
65 dc = 0 /* 1 */;
66 break;
67 case DCT_GLOBAL_DTORS:
68 dc = /* 0 */ 1;
69 break;
71 /* If this is added, all is fine. */
72 #ifdef ABORT
73 default:
74 __builtin_unreachable ();
75 #endif
78 return dc; // { dg-bogus "uninitialized" }