summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/strlenopt-31.c
blob: bdd46ba0000fde537c09df45a505b23358fd60bd (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
/* { dg-do run } */
/* { dg-options "-O2" } */

#include "strlenopt.h"

__attribute__((noinline, noclone)) int
bar (char *p1, const char *q)
{
  strcpy (p1, "abcde");
  char *p2 = strchr (p1, '\0');
  strcpy (p2, q);
  char *p3 = strchr (p2, '\0');
  memcpy (p3, "x", 2);
  return strlen (p1);
}

int
main (void)
{
  char buffer[10];
  int res = bar (buffer, "foo");
  if (strcmp (buffer, "abcdefoox") != 0 || res != 9)
    abort ();
  return 0;
}