aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/pr93249.c
blob: 2c9a6b4dee0f9f0b49770e5ccbc453bbcafa4ecd (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
/* PR tree-optimization/93249 */

char a[2], b[4], c[6];

void
foo (void)
{
  char d[2] = { 0x00, 0x11 };
  __builtin_strncpy (&b[2], d, 2);
  __builtin_strncpy (&b[1], a, 2);
  if (b[0] || b[1] || b[2] || b[3])
    __builtin_abort ();
}

void
bar (void)
{
  __builtin_strncpy (&b[2], "\0\x11", 2);
  __builtin_strncpy (&b[1], a, 2);
  if (b[0] || b[1] || b[2] || b[3])
    __builtin_abort ();
}

void
baz (void)
{
  __builtin_strncpy (&c[2], "\x11\x11\0\x11", 4);
  __builtin_strncpy (&c[1], a, 2);
  if (c[0] || c[1] || c[2] || c[3] != 0x11 || c[4] || c[5])
    __builtin_abort ();
}

int
main ()
{
  foo ();
  bar ();
  baz ();
  return 0;
}