1 /* { dg-do compile { target *-*-darwin* } } */
2 /* { dg-options "-O0 -gdwarf-2 -dA" } */
3 /* { dg-skip-if "Unmatchable assembly" { mmix-*-* } { "*" } { "" } } */
4 /* { dg-final { scan-assembler "__debug_pubtypes" } } */
5 /* { dg-final { scan-assembler "long+\[ \t\]+0x172+\[ \t\]+\[#;]+\[ \t\]+Pub Info Length" } } */
6 /* { dg-final { scan-assembler "used_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */
7 /* { dg-final { scan-assembler-not "unused_struct\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */
8 /* { dg-final { scan-assembler "\"list_name_type\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */
9 /* { dg-final { scan-assembler "\"enum_list_array\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */
10 /* { dg-final { scan-assembler "\"field_union\\\\0\"+\[ \t\]+\[#;]+\[ \t\]+external name" } } */
11 
12 #include <stdlib.h>
13 #include <stdio.h>
14 
15 struct used_struct
16 {
17   int key;
18   char *name;
19   union field_union
20   {
21     char  u_c;
22     int   u_i;
23     long  u_l;
24     double u_d;
25   } u;
26 };
27 
28 struct unused_struct
29 {
30   int key1;
31   int f2;
32   double f3;
33   char *f4;
34   struct unused_struct *next;
35 };
36 
37 enum list_name_type {
38   boy_name,
39   girl_name,
40   unknown
41 };
42 
43 
44 typedef enum list_name_type *enum_list_array;
45 
46 enum_list_array enum_list;
47 
48 void
foo(struct used_struct * list)49 foo (struct used_struct *list)
50 {
51   int b_count = 0;
52   int g_count = 0;
53   int i;
54 
55   enum_list = (enum_list_array) malloc (10 * sizeof (enum list_name_type));
56 
57   for (i = 0; i < 10; i++)
58     {
59       if (strncmp (list[i].name, "Alice", 5) == 0)
60 	{
61 	  enum_list[i] = girl_name;
62 	  g_count++;
63 	}
64       else if (strncmp (list[i].name, "David", 5) == 0)
65 	{
66 	  enum_list[i] = boy_name;
67 	  b_count++;
68 	}
69       else
70 	enum_list[i] = unknown;
71     }
72 
73 }
74 
75 int
main(int argc,char ** argv)76 main (int argc, char **argv)
77 {
78   int i;
79   struct used_struct *my_list;
80 
81   my_list = (struct used_struct *) malloc (10 * sizeof (struct used_struct));
82 
83   for (i = 0; i < 10; i++)
84     {
85       my_list[i].key = i;
86       my_list[i].name = (char *) malloc (11);
87       sprintf (my_list[i].name, "Alice_%d", i);
88     }
89 
90   foo (my_list);
91 
92   for (i = 0; i < 10; i++)
93     fprintf (stdout, "Key: %d, Name: %s\n", my_list[i].key, my_list[i].name);
94 
95   return 0;
96 }
97