1 /* PR39565: Static variable leaves undefined symbol in object file.
2    Variables codestrs_4 and codestrs_8 should not be undefined,
3    when this program is compiled at -O2. As a basic sanity test,
4    verify that this program compiles into an executable and runs. */
5 
6 /* { dg-do run } */
7 /* { dg-options "-O2" } */
8 
9 extern void abort (void);
10 extern void exit (int);
11 extern int strcmp (const char *, const char *);
12 
13 static const union codestrs_t_4 {
14   struct {
15     char str_2[sizeof ("Illegal opcode")];
16   };
17   char str[0];
18 } codestrs_4 = { {"Illegal opcode"} };
19 
20 static const union codestrs_t_8 {
21   struct {
22     char str_12[sizeof ("Integer divide by zero")];
23   };
24   char str[0];
25 } codestrs_8 = { {"Integer divide by zero"} };
26 
27 const char *
psiginfo(int pinfo)28 psiginfo (int pinfo)
29 {
30   const char *base = ((void *)0);
31 
32   switch (pinfo)
33     {
34     case 4: base = codestrs_4.str; break;
35     case 8: base = codestrs_8.str; break;
36     }
37   return base;
38 }
39 
40 int
main(void)41 main (void)
42 {
43   if (strcmp (psiginfo (4), codestrs_4.str))
44     abort ();
45   if (strcmp (psiginfo (8), codestrs_8.str))
46     abort ();
47   exit (0);
48 }
49