-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang] Move warning about memset/memcpy to NonTriviallyCopyable type… #117387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
fda70bc
a9b2bbb
08613f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -683,11 +683,13 @@ def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">; | |
| def SizeofPointerMemaccess : DiagGroup<"sizeof-pointer-memaccess">; | ||
| def MemsetTransposedArgs : DiagGroup<"memset-transposed-args">; | ||
| def DynamicClassMemaccess : DiagGroup<"dynamic-class-memaccess">; | ||
| def NonTrivialMemaccess : DiagGroup<"nontrivial-memaccess">; | ||
| def NonTrivialMemcall : DiagGroup<"nontrivial-memcall">; | ||
| def NonTrivialMemaccess : DiagGroup<"nontrivial-memaccess", [NonTrivialMemcall]>; | ||
| def SuspiciousBzero : DiagGroup<"suspicious-bzero">; | ||
| def SuspiciousMemaccess : DiagGroup<"suspicious-memaccess", | ||
| [SizeofPointerMemaccess, DynamicClassMemaccess, | ||
| NonTrivialMemaccess, MemsetTransposedArgs, SuspiciousBzero]>; | ||
| NonTrivialMemaccess, NonTrivialMemcall, MemsetTransposedArgs, | ||
|
||
| SuspiciousBzero]>; | ||
| def StaticInInline : DiagGroup<"static-in-inline">; | ||
| def StaticLocalInInline : DiagGroup<"static-local-in-inline">; | ||
| def GNUStaticFloatInit : DiagGroup<"gnu-static-float-init">; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wnontrivial-memcall %s | ||
|
|
||
| extern "C" void *memcpy(void *s1, const void *s2, unsigned n); | ||
|
|
||
| class TriviallyCopyable {}; | ||
| class NonTriviallyCopyable { NonTriviallyCopyable(const NonTriviallyCopyable&);}; | ||
| struct Incomplete; | ||
|
|
||
| void test_memcpy(TriviallyCopyable* tc0, TriviallyCopyable* tc1, | ||
| NonTriviallyCopyable *ntc0, NonTriviallyCopyable *ntc1, | ||
| Incomplete *i0, Incomplete *i1) { | ||
| // OK | ||
| memcpy(tc0, tc1, sizeof(*tc0)); | ||
|
|
||
| // OK | ||
| memcpy(i0, i1, 10); | ||
|
|
||
| // expected-warning@+2{{first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'NonTriviallyCopyable'}} | ||
| // expected-note@+1{{explicitly cast the pointer to silence this warning}} | ||
| memcpy(ntc0, ntc1, sizeof(*ntc0)); | ||
|
|
||
| // ~ OK | ||
| memcpy((void*)ntc0, ntc1, sizeof(*ntc0)); | ||
|
|
||
| // OK | ||
| memcpy((void*)ntc0, (void*)ntc1, sizeof(*ntc0)); | ||
| } | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention here that it's part of -Wnontrivial-memaccess?