aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/pr94015.c
blob: 2c91b23583417323b74b609bed941ff97c9983d6 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* PR tree-optimization/94015 */
/* { dg-do run } */
/* { dg-options "-O2" } */

char buf[10] = "AAAAAAAAA";

__attribute__((noipa)) char *
alloc (void)
{
  return buf;
}

__attribute__((noipa)) void
f1 (void)
{
  char *s = alloc ();
  *(char **)s = "1234567";
  s[7] = '\0';
}

__attribute__((noipa)) void
f2 (void)
{
  char *s = alloc ();
  *(char **)s = "123456";
  s[6] = '\0';
}

__attribute__((noipa)) void
f3 (void)
{
  char *s = alloc ();
  *(char **)s = "12345";
  s[5] = '\0';
}

__attribute__((noipa)) void
f4 (void)
{
  char *s = alloc ();
  *(char **)s = "1234";
  s[4] = '\0';
}

__attribute__((noipa)) void
f5 (void)
{
  char *s = alloc ();
  *(char **)s = "123";
  s[3] = '\0';
}

__attribute__((noipa)) void
f6 (void)
{
  char *s = alloc ();
  *(char **)s = "12";
  s[2] = '\0';
}

__attribute__((noipa)) void
f7 (void)
{
  char *s = alloc ();
  *(char **)s = "1";
  s[1] = '\0';
}

__attribute__((noipa)) void
f8 (void)
{
  char *s = alloc ();
  *(char **)s = "";
  s[0] = '\0';
}

int
main ()
{
  if (sizeof (char *) > 8)
    return 0;
  f1 ();
  if (buf[7] != 0)
    __builtin_abort ();
  f2 ();
  if (buf[6] != 0)
    __builtin_abort ();
  f3 ();
  if (buf[5] != 0)
    __builtin_abort ();
  f4 ();
  if (buf[4] != 0)
    __builtin_abort ();
  f5 ();
  if (buf[3] != 0)
    __builtin_abort ();
  f6 ();
  if (buf[2] != 0)
    __builtin_abort ();
  f7 ();
  if (buf[1] != 0)
    __builtin_abort ();
  f8 ();
  if (buf[0] != 0)
    __builtin_abort ();
  return 0;
}