Mercurial > hg > CbC > CbC_gcc
view gcc/testsuite/gcc.dg/string-opt-1.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | |
children | 84e7813d76e9 |
line wrap: on
line source
/* 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" } } */