aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/torture/pr109609.c
blob: 0e191cd1ee812719ad4d4f2604ff17bdced2f41b (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
/* { dg-do run } */

#define N 23
#define MAX_LEN 13
char dst[N + 1];

void __attribute__((noipa))
invert(const char *id)
{
  char buf[MAX_LEN];
  char *ptr = buf + sizeof(buf);  // start from the end of buf
  *(--ptr) = '\0';                // terminate string
  while (*id && ptr > buf) {
    *(--ptr) = *(id++);           // copy id backwards
  }
  __builtin_strncpy(dst, ptr, N);           // copy ptr/buf to dst
}


int main()
{
  invert("abcde");
  if (__builtin_strcmp(dst, "edcba"))
    __builtin_abort();
  return 0;
}