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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* { dg-do compile { target { ! x32 } } }
{ dg-require-effective-target mempcpy }
{ dg-options "-O2 -Wrestrict -fcheck-pointer-bounds -mmpx" } */
#define USE_GNU
#include "../../gcc.dg/strlenopt.h"
/* There is no BUILT_IN_ST{P,R}NCPY_CHKP or BUILT_IN_STRNCAT_CHKP
so the test for them below are XFAIL. */
char *stpncpy (char *__restrict, const char *__restrict, size_t);
char *strncpy (char *__restrict, const char *__restrict, size_t);
char *strncat (char *__restrict, const char *__restrict, size_t);
char a[8];
void test_memcpy (void)
{
memcpy (a, a + 1, 3); /* { dg-warning ".memcpy\.chkp. accessing 3 bytes at offsets 0 and 1 overlaps 2 bytes at offset 1" } */
}
void test_memmove (void)
{
memmove (a, a + 1, 3);
}
void* test_mempcpy (void)
{
return mempcpy (a, a + 1, 3); /* { dg-warning ".mempcpy\.chkp. accessing 3 bytes at offsets 0 and 1 overlaps 2 bytes at offset 1" } */
}
char* test_stpcpy (void)
{
strcpy (a, "0123456");
return stpcpy (a, a + 2); /* { dg-warning ".stpcpy\.chkp. accessing 6 bytes at offsets 0 and 2 overlaps 4 bytes at offset 2" } */
}
char* test_stpncpy (void)
{
strcpy (a, "0123456");
/* There is no BUILT_IN_STPNCPY_CHKP so this isn't handled. */
return stpncpy (a, a + 2, sizeof a); /* { dg-warning ".stpcpy\.chkp. accessing 7 bytes at offsets 0 and 2 overlaps 4 bytes at offset 2" "bug 82652" { xfail *-*-* } } */
}
void test_strcpy (void)
{
strcpy (a, "0123456");
strcpy (a, a + 1); /* { dg-warning ".strcpy\.chkp. accessing 7 bytes at offsets 0 and 1 overlaps 6 bytes at offset 1" } */
}
void test_strcat (int n)
{
strcat (a, a + 3); /* { dg-warning ".strcat\.chkp. accessing 4 or more bytes at offsets 0 and 3 may overlap 1 byte at offset 3" } */
}
void test_strncat (int n)
{
strncat (a, a + 3, sizeof a); /* { dg-warning ".strncat\.chkp. accessing 0 or more bytes at offsets 0 and 3 may overlap 1 byte" "bug 82652" { xfail *-*-* } } */
}
void test_strncpy (int n)
{
strcpy (a, "0123456");
/* There is no BUILT_IN_STRNCPY_CHKP so this isn't handled. */
strncpy (a, a + 2, sizeof a); /* { dg-warning ".strncpy\.chkp. accessing 7 bytes at offsets 0 and 2 overlaps 5 bytes at offset 2" "bug 82652" { xfail *-*-* } } */
}
|