| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wnontrivial-memcall %s |
| 2 |
|
| 3 |
extern "C" void *bzero(void *, unsigned); |
| 4 |
extern "C" void *memset(void *, int, unsigned); |
| 5 |
extern "C" void *memmove(void *s1, const void *s2, unsigned n); |
| 6 |
extern "C" void *memcpy(void *s1, const void *s2, unsigned n); |
| 7 |
|
| 8 |
class TriviallyCopyable {}; |
| 9 |
class NonTriviallyCopyable { NonTriviallyCopyable(const NonTriviallyCopyable&);}; |
| 10 |
struct Incomplete; |
| 11 |
|
| 12 |
void test_bzero(TriviallyCopyable* tc, |
| 13 |
NonTriviallyCopyable *ntc, |
| 14 |
Incomplete* i) { |
| 15 |
// OK |
| 16 |
bzero(tc, sizeof(*tc)); |
| 17 |
|
| 18 |
// OK |
| 19 |
bzero(i, 10); |
| 20 |
|
| 21 |
// expected-warning@+2{{first argument in call to 'bzero' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 22 |
// expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 23 |
bzero(ntc, sizeof(*ntc)); |
| 24 |
|
| 25 |
// OK |
| 26 |
bzero((void*)ntc, sizeof(*ntc)); |
| 27 |
} |
| 28 |
|
| 29 |
void test_memset(TriviallyCopyable* tc, |
| 30 |
NonTriviallyCopyable *ntc, |
| 31 |
Incomplete* i) { |
| 32 |
// OK |
| 33 |
memset(tc, 0, sizeof(*tc)); |
| 34 |
|
| 35 |
// OK |
| 36 |
memset(i, 0, 10); |
| 37 |
|
| 38 |
// expected-warning@+2{{first argument in call to 'memset' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 39 |
// expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 40 |
memset(ntc, 0, sizeof(*ntc)); |
| 41 |
|
| 42 |
// OK |
| 43 |
memset((void*)ntc, 0, sizeof(*ntc)); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
void test_memcpy(TriviallyCopyable* tc0, TriviallyCopyable* tc1, |
| 48 |
NonTriviallyCopyable *ntc0, NonTriviallyCopyable *ntc1, |
| 49 |
Incomplete *i0, Incomplete *i1) { |
| 50 |
// OK |
| 51 |
memcpy(tc0, tc1, sizeof(*tc0)); |
| 52 |
|
| 53 |
// OK |
| 54 |
memcpy(i0, i1, 10); |
| 55 |
|
| 56 |
// expected-warning@+2{{first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 57 |
// expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 58 |
memcpy(ntc0, ntc1, sizeof(*ntc0)); |
| 59 |
|
| 60 |
// ~ OK |
| 61 |
memcpy((void*)ntc0, ntc1, sizeof(*ntc0)); |
| 62 |
|
| 63 |
// OK |
| 64 |
memcpy((void*)ntc0, (void*)ntc1, sizeof(*ntc0)); |
| 65 |
} |
| 66 |
|
| 67 |
void test_memmove(TriviallyCopyable* tc0, TriviallyCopyable* tc1, |
| 68 |
NonTriviallyCopyable *ntc0, NonTriviallyCopyable *ntc1, |
| 69 |
Incomplete *i0, Incomplete *i1) { |
| 70 |
// OK |
| 71 |
memmove(tc0, tc1, sizeof(*tc0)); |
| 72 |
|
| 73 |
// OK |
| 74 |
memmove(i0, i1, 10); |
| 75 |
|
| 76 |
// expected-warning@+2{{first argument in call to 'memmove' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} |
| 77 |
// expected-note@+1{{explicitly cast the pointer to silence this warning}} |
| 78 |
memmove(ntc0, ntc1, sizeof(*ntc0)); |
| 79 |
|
| 80 |
// ~ OK |
| 81 |
memmove((void*)ntc0, ntc1, sizeof(*ntc0)); |
| 82 |
|
| 83 |
// OK |
| 84 |
memmove((void*)ntc0, (void*)ntc1, sizeof(*ntc0)); |
| 85 |
} |