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-*-* } } } */
10
11 char a[32];
12
fold_copy_2(void)13 void fold_copy_2 (void)
14 {
15 __builtin_memcpy (a + 1, a, 2); /* { dg-warning "\\\[-Wrestrict]" } */
16 }
17
fold_copy_4(void)18 void fold_copy_4 (void)
19 {
20 __builtin_memcpy (a + 2, a, 4); /* { dg-warning "\\\[-Wrestrict]" } */
21 }
22
fold_copy_8(void)23 void fold_copy_8 (void)
24 {
25 __builtin_memcpy (a + 3, a, 8); /* { dg-warning "\\\[-Wrestrict]" } */
26 }
27
fold_move_2(void)28 void fold_move_2 (void)
29 {
30 __builtin_memmove (a + 1, a, 2);
31 }
32
fold_move_4(void)33 void fold_move_4 (void)
34 {
35 __builtin_memmove (a + 2, a, 4);
36 }
37
fold_move_8(void)38 void fold_move_8 (void)
39 {
40 __builtin_memmove (a + 3, a, 8);
41 }
42
43 /* { dg-final { scan-tree-dump-not "memcpy" "optimized" } }
44 { dg-final { scan-tree-dump-not "memmove" "optimized" } } */
45