summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/array-init-2.c
blob: 9c425818fe540a0aabc1062b799dac22dff36182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Test array initializion by store_by_pieces.  */
/* { dg-do run } */
/* { dg-options "-O2" } */

struct A { char c[10]; };
extern void abort (void);

void
__attribute__((noinline))
check (struct A * a, int b)
{
  const char *p;
  switch (b)
    {
    case 0:
      p = "abcdefghi";
      break;
    case 1:
      p = "j\0\0\0\0\0\0\0\0";
      break;
    case 2:
      p = "kl\0\0\0\0\0\0\0";
      break;
    case 3:
      p = "mnop\0\0\0\0\0";
      break;
    case 4:
      p = "qrstuvwx\0";
      break;
    default:
      abort ();
    }
  if (__builtin_memcmp (a->c, p, 10) != 0)
    abort ();
}

int
main (void)
{
  struct A a = { "abcdefghi" };
  check (&a, 0);
  struct A b = { "j" };
  check (&b, 1);
  struct A c = { "kl" };
  check (&c, 2);
  struct A d = { "mnop" };
  check (&d, 3);
  struct A e = { "qrstuvwx" };
  check (&e, 4);
  return 0;
}