| 1 |
/* PR middle-end/80936 - bcmp, bcopy, and bzero not declared nonnull |
| 2 |
Verify that -Wnonnull is issued for calls with constant null pointers |
| 3 |
with no optimization. |
| 4 |
{ dg-do compile } |
| 5 |
{ dg-options "-O0 -Wall" } */ |
| 6 |
|
| 7 |
void |
| 8 |
zero0 (void *p, unsigned n) |
| 9 |
{ |
| 10 |
__builtin_memset (0, 0, 0); |
| 11 |
__builtin_memset (0, 0, n); |
| 12 |
__builtin_memset (0, 0, 1); // { dg-warning "\\\[-Wnonnull]" } |
| 13 |
} |
| 14 |
|
| 15 |
void |
| 16 |
zero1 (void *p, unsigned n) |
| 17 |
{ |
| 18 |
__builtin_bzero (0, 0); |
| 19 |
__builtin_bzero (0, n); |
| 20 |
__builtin_bzero (0, 2); // { dg-warning "\\\[-Wnonnull]" } |
| 21 |
} |
| 22 |
|
| 23 |
void |
| 24 |
copy0 (void *p, const void *q, unsigned n) |
| 25 |
{ |
| 26 |
__builtin_memcpy (0, q, 0); |
| 27 |
__builtin_memcpy (0, q, n); |
| 28 |
__builtin_memcpy (0, q, 3); // { dg-warning "\\\[-Wnonnull]" } |
| 29 |
} |
| 30 |
|
| 31 |
void |
| 32 |
copy1 (void *p, const void *q, unsigned n) |
| 33 |
{ |
| 34 |
__builtin_memcpy (p, 0, 0); |
| 35 |
__builtin_memcpy (p, 0, n); |
| 36 |
__builtin_memcpy (p, 0, 4); // { dg-warning "\\\[-Wnonnull]" } |
| 37 |
} |
| 38 |
|
| 39 |
void |
| 40 |
copy2 (void *p, const void *q, unsigned n) |
| 41 |
{ |
| 42 |
__builtin_bcopy (0, p, 0); |
| 43 |
__builtin_bcopy (0, p, n); |
| 44 |
__builtin_bcopy (0, p, 5); // { dg-warning "\\\[-Wnonnull]" } |
| 45 |
} |
| 46 |
|
| 47 |
void |
| 48 |
copy3 (void *p, const void *q, unsigned n) |
| 49 |
{ |
| 50 |
__builtin_bcopy (q, 0, 0); |
| 51 |
__builtin_bcopy (q, 0, n); |
| 52 |
__builtin_bcopy (q, 0, 6); // { dg-warning "\\\[-Wnonnull]" } |
| 53 |
} |
| 54 |
|
| 55 |
int |
| 56 |
cmp0 (const void *p, const void *q, unsigned n) |
| 57 |
{ |
| 58 |
return __builtin_memcmp (0, q, 0); |
| 59 |
} |
| 60 |
|
| 61 |
int |
| 62 |
cmp1 (const void *p, const void *q, unsigned n) |
| 63 |
{ |
| 64 |
return __builtin_memcmp (0, q, 0); |
| 65 |
} |
| 66 |
|
| 67 |
int |
| 68 |
cmp2 (const void *p, const void *q, unsigned n) |
| 69 |
{ |
| 70 |
return __builtin_bcmp (0, q, 0); |
| 71 |
} |
| 72 |
|
| 73 |
int |
| 74 |
cmp3 (const void *p, const void *q, unsigned n) |
| 75 |
{ |
| 76 |
return __builtin_bcmp (p, 0, 0); |
| 77 |
} |
| 78 |
|
| 79 |
int |
| 80 |
cmp4 (const void *p, const void *q, unsigned n) |
| 81 |
{ |
| 82 |
return __builtin_memcmp (0, q, n); |
| 83 |
} |
| 84 |
|
| 85 |
int |
| 86 |
cmp5 (const void *p, const void *q, unsigned n) |
| 87 |
{ |
| 88 |
return __builtin_memcmp (0, q, n); |
| 89 |
} |
| 90 |
|
| 91 |
int |
| 92 |
cmp6 (const void *p, const void *q, unsigned n) |
| 93 |
{ |
| 94 |
return __builtin_bcmp (0, q, n); |
| 95 |
} |
| 96 |
|
| 97 |
int |
| 98 |
cmp7 (const void *p, const void *q, unsigned n) |
| 99 |
{ |
| 100 |
return __builtin_bcmp (p, 0, n); |
| 101 |
} |
| 102 |
|
| 103 |
int |
| 104 |
cmp8 (const void *p, const void *q, unsigned n) |
| 105 |
{ |
| 106 |
return __builtin_memcmp (0, q, 41); // { dg-warning "\\\[-Wnonnull]" } |
| 107 |
} |
| 108 |
|
| 109 |
int |
| 110 |
cmp9 (const void *p, const void *q, unsigned n) |
| 111 |
{ |
| 112 |
return __builtin_memcmp (0, q, 42); // { dg-warning "\\\[-Wnonnull]" } |
| 113 |
} |
| 114 |
|
| 115 |
int |
| 116 |
cmp10 (const void *p, const void *q, unsigned n) |
| 117 |
{ |
| 118 |
return __builtin_bcmp (0, q, 43); // { dg-warning "\\\[-Wnonnull]" } |
| 119 |
} |
| 120 |
|
| 121 |
int |
| 122 |
cmp11 (const void *p, const void *q, unsigned n) |
| 123 |
{ |
| 124 |
return __builtin_bcmp (p, 0, 44); // { dg-warning "\\\[-Wnonnull]" } |
| 125 |
} |