Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / SemaCXX / warn-memaccess.cpp
blob070b44891a91aa4e4aca48c851cfb68f8e96eb08
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wnontrivial-memaccess %s
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);
8 class TriviallyCopyable {};
9 class NonTriviallyCopyable { NonTriviallyCopyable(const NonTriviallyCopyable&);};
10 struct Incomplete;
12 void test_bzero(TriviallyCopyable* tc,
13 NonTriviallyCopyable *ntc,
14 Incomplete* i) {
15 // OK
16 bzero(tc, sizeof(*tc));
18 // OK
19 bzero(i, 10);
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));
25 // OK
26 bzero((void*)ntc, sizeof(*ntc));
29 void test_memset(TriviallyCopyable* tc,
30 NonTriviallyCopyable *ntc,
31 Incomplete* i) {
32 // OK
33 memset(tc, 0, sizeof(*tc));
35 // OK
36 memset(i, 0, 10);
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));
42 // OK
43 memset((void*)ntc, 0, sizeof(*ntc));
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));
53 // OK
54 memcpy(i0, i1, 10);
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));
60 // ~ OK
61 memcpy((void*)ntc0, ntc1, sizeof(*ntc0));
63 // OK
64 memcpy((void*)ntc0, (void*)ntc1, sizeof(*ntc0));
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));
73 // OK
74 memmove(i0, i1, 10);
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));
80 // ~ OK
81 memmove((void*)ntc0, ntc1, sizeof(*ntc0));
83 // OK
84 memmove((void*)ntc0, (void*)ntc1, sizeof(*ntc0));