summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/string-opt-1.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gcc.dg/string-opt-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/string-opt-1.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/string-opt-1.c b/gcc/testsuite/gcc.dg/string-opt-1.c
index bc0f30098fa..2f060732bf0 100644
--- a/gcc/testsuite/gcc.dg/string-opt-1.c
+++ b/gcc/testsuite/gcc.dg/string-opt-1.c
@@ -1,11 +1,52 @@
-/* Ensure mempcpy is not "optimized" into memcpy followed by addition. */
+/* Ensure mempcpy is "optimized" into memcpy followed by addition. */
/* { dg-do compile } */
/* { dg-options "-O2" } */
-void *
-fn (char *x, char *y, int z)
+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)
{
- return __builtin_mempcpy (x, y, z);
+ 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 "memcpy" } } */
+/* { dg-final { scan-assembler-not "\<mempcpy\>" } } */
+/* { dg-final { scan-assembler "memcpy" } } */