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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/* PR tree-optimization/83456 - -Wrestrict false positive on a non-overlapping
memcpy in an inline function
Verify that calls to built-in functions are diagnosed when the pointer
arguments to their restrict-qualified parameters are the same (the absence
of the false positives reported in PR 83456 is tested in Wrestrict-12.c.
{ dg-do compile }
{ dg-options "-O2 -Wall -Wrestrict -Wno-stringop-truncation" } */
typedef __SIZE_TYPE__ size_t;
extern void* memcpy (void* restrict, const void* restrict, size_t);
extern void* mempcpy (void* restrict, const void* restrict, size_t);
extern char* stpncpy (char* restrict, const char* restrict, size_t);
extern char* stpcpy (char* restrict, const char* restrict);
extern char* strncat (char* restrict, const char* restrict, size_t);
extern char* strcat (char* restrict, const char* restrict);
extern char* strncpy (char* restrict, const char* restrict, size_t);
extern char* strcpy (char* restrict, const char* restrict);
struct S
{
char a[4];
char *p;
} s;
void sink (void*);
void test_memcpy (char *p, struct S *q, size_t n)
{
/* The behavior of memcpy() is undefined only when when copying takes
place between overlapping objects. Since a call with a size of zero
does nothing, it should not be diagnosed. */
memcpy (p, p, 0);
sink (p);
memcpy (p, p, 1); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
memcpy (p, p, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
memcpy (q->a, q->a, 0);
sink (q);
memcpy (q->p, q->p, 1); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
memcpy (&q->a[0], q->a, n); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
sink (q);
memcpy (q, q->a, n); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
sink (q);
}
void test_mempcpy (char *p, struct S *q, size_t n)
{
mempcpy (p, p, 0);
sink (p);
mempcpy (p, p, 1); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
mempcpy (p, p, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
mempcpy (q->a, q->a, 0);
sink (q);
mempcpy (q->p, q->p, 1); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
mempcpy (&q->a[0], q->a, n); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
sink (q);
mempcpy (q, q->a, n); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
sink (q);
}
void test_strncat (char *p, struct S *q, size_t n)
{
strncat (p, p, 0);
sink (p);
strncat (p, p, 1); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strncat (p, p, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strncat (q->a, q->a, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strncat (&q->a[0], &q->a[0], n);/* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strncat (q->a, &q->a[0], n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strncat (q->p, &q->p[0], n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
}
void test_strcat (char *p, struct S *q, size_t n)
{
strcat (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strcat (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strcat (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strcat (q->a, q->a); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strcat (&q->a[0], &q->a[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strcat (q->a, &q->a[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strcat (q->p, &q->p[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
}
void test_stpncpy (char *p, struct S *q, size_t n)
{
stpncpy (p, p, 0); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
stpncpy (p, p, 1); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
stpncpy (p, p, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
stpncpy (q->a, q->a, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
stpncpy (&q->a[0], &q->a[0], n);/* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
stpncpy (q->a, &q->a[0], n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
stpncpy (q->p, &q->p[0], n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
}
void test_stpcpy (char *p, struct S *q, size_t n)
{
stpcpy (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
stpcpy (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
stpcpy (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
stpcpy (q->a, q->a); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
stpcpy (&q->a[0], &q->a[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
stpcpy (q->a, &q->a[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
stpcpy (q->p, &q->p[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
}
void test_strncpy (char *p, struct S *q, size_t n)
{
strncpy (p, p, 0);
sink (p);
strncpy (p, p, 1); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strncpy (p, p, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strncpy (q->a, q->a, n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strncpy (&q->a[0], &q->a[0], n);/* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strncpy (q->a, &q->a[0], n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strncpy (q->p, &q->p[0], n); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
}
void test_strcpy (char *p, struct S *q, size_t n)
{
strcpy (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strcpy (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strcpy (p, p); /* { dg-warning "\\\[-Wrestrict]" } */
sink (p);
strcpy (q->a, q->a); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strcpy (&q->a[0], &q->a[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strcpy (q->a, &q->a[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
strcpy (q->p, &q->p[0]); /* { dg-warning "\\\[-Wrestrict]" } */
sink (q);
}
|