summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/string-opt-1.c
blob: 2f060732bf042e7083dfef0824ffc3c84b6e65a4 (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
/* Ensure mempcpy is "optimized" into memcpy followed by addition.  */
/* { dg-do compile } */
/* { dg-options "-O2" } */

char *buffer;
char *test;

#define SIZE 100

char *
__attribute__((noinline))
my_memcpy (char *d, char *s, unsigned l)
{
  return __builtin_memcpy (d, s, l);
}

char *
__attribute__((noinline))
my_mempcpy (char *d, char *s, unsigned l)
{
  return __builtin_mempcpy (d, s, l);
}

void
run_test (char *d, char *s, unsigned l)
{
  char *r = my_mempcpy (d, s, l);
  if (r != d + l)
    __builtin_abort ();

  r = my_memcpy (d, s, l);
  if (r != d)
    __builtin_abort ();
}

int
main (void)
{
  const char* const foo = "hello world";
  unsigned l = __builtin_strlen (foo) + 1;

  buffer = __builtin_malloc (SIZE);
  __builtin_memcpy (buffer, foo, l);
  test = __builtin_malloc (SIZE);

  run_test (test, buffer, l);

  return 0;
}

/* { dg-final { scan-assembler-not "\<mempcpy\>" } } */
/* { dg-final { scan-assembler "memcpy" } } */