2018-05-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / memcpy-6.c
blob7ff735e94d11022f7435298845d617786f198fdc
1 /* Test to verify that overlapping memcpy with const sizes that are powers
2 of two are folded into into the same code as memmove, but that they
3 are diagnosed nonetheless. Whether a call is folded depends on
4 the size of the copy, the alignment, and wheteber else the target
5 might decide to consider. The test is only run on a small subset
6 of targets where it's known to pass (see PR testsuite/83483).
7 { dg-do compile }
8 { dg-options "-O0 -Wrestrict -fdump-tree-optimized" }
9 { dg-skip-if "skip non-x86 targets" { ! { i?86-*-* x86_64-*-* } } } */
11 char a[32];
13 void fold_copy_2 (void)
15 __builtin_memcpy (a + 1, a, 2); /* { dg-warning "\\\[-Wrestrict]" } */
18 void fold_copy_4 (void)
20 __builtin_memcpy (a + 2, a, 4); /* { dg-warning "\\\[-Wrestrict]" } */
23 void fold_copy_8 (void)
25 __builtin_memcpy (a + 3, a, 8); /* { dg-warning "\\\[-Wrestrict]" } */
28 void fold_move_2 (void)
30 __builtin_memmove (a + 1, a, 2);
33 void fold_move_4 (void)
35 __builtin_memmove (a + 2, a, 4);
38 void fold_move_8 (void)
40 __builtin_memmove (a + 3, a, 8);
43 /* { dg-final { scan-tree-dump-not "memcpy" "optimized" } }
44 { dg-final { scan-tree-dump-not "memmove" "optimized" } } */