-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Silence spurious -Wnontrivial-memcall warnings in C mode #137429
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
clang/test/Sema/warn-nontrivial-struct-memaccess-ptrauth.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics -fsyntax-only -verify=c,expected %s | ||
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -fsyntax-only -verify=c,expected %s | ||
// RUN: %clang_cc1 -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics -fsyntax-only -x c++ -verify=cxx,expected %s | ||
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -fsyntax-only -x c++ -verify=cxx,expected %s | ||
|
||
#if defined __cplusplus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahahah, I was literally thinking "add a -D argument to say it's C++" because I'm a muppet and forgot the builtin macro :D |
||
extern "C" { | ||
#endif | ||
|
||
ahatanak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void *memset(void *, int, __SIZE_TYPE__); | ||
void bzero(void *, __SIZE_TYPE__); | ||
void *memcpy(void *, const void *, __SIZE_TYPE__); | ||
void *memmove(void *, const void *, __SIZE_TYPE__); | ||
|
||
#if defined __cplusplus | ||
} | ||
#endif | ||
|
||
#define AQ __ptrauth(1,1,50) | ||
#define IQ __ptrauth(1,0,50) | ||
|
||
struct PtrAuthTrivial { | ||
int f0; | ||
int * IQ f1; | ||
}; | ||
|
||
struct PtrAuthNonTrivial0 { | ||
int f0; | ||
int * AQ f1; // c-note 2 {{non-trivial to copy}} | ||
int f2; | ||
}; | ||
|
||
struct PtrAuthNonTrivial1 { | ||
int * AQ f0; // c-note 2 {{non-trivial to copy}} | ||
int f1; | ||
struct PtrAuthNonTrivial0 f2; | ||
}; | ||
|
||
void testPtrAuthTrivial(struct PtrAuthTrivial *d, struct PtrAuthTrivial *s) { | ||
memset(d, 0, sizeof(struct PtrAuthTrivial)); | ||
ahatanak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
memset(d, 1, sizeof(struct PtrAuthTrivial)); | ||
bzero(d, sizeof(struct PtrAuthTrivial)); | ||
memcpy(d, s, sizeof(struct PtrAuthTrivial)); | ||
memmove(d, s, sizeof(struct PtrAuthTrivial)); | ||
} | ||
|
||
void testPtrAuthNonTrivial1(struct PtrAuthNonTrivial1 *d, | ||
struct PtrAuthNonTrivial1 *s) { | ||
memset(d, 0, sizeof(struct PtrAuthNonTrivial1)); // cxx-warning {{is a pointer to non-trivially copyable type 'struct PtrAuthNonTrivial1'}} // cxx-note {{explicitly cast the pointer to silence}} | ||
memset(d, 1, sizeof(struct PtrAuthNonTrivial1)); // cxx-warning {{is a pointer to non-trivially copyable type 'struct PtrAuthNonTrivial1'}} // cxx-note {{explicitly cast the pointer to silence}} | ||
bzero(d, sizeof(struct PtrAuthNonTrivial1)); // cxx-warning {{is a pointer to non-trivially copyable type 'struct PtrAuthNonTrivial1'}} // cxx-note {{explicitly cast the pointer to silence}} | ||
memcpy(d, s, sizeof(struct PtrAuthNonTrivial1)); | ||
// c-warning@-1 {{that is not trivial to primitive-copy}} | ||
// cxx-warning@-2 {{is a pointer to non-trivially copyable type 'struct PtrAuthNonTrivial1'}} | ||
// expected-note@-3 {{explicitly cast the pointer to silence}} | ||
memmove(d, s, sizeof(struct PtrAuthNonTrivial1)); | ||
// c-warning@-1 {{that is not trivial to primitive-copy}} | ||
// cxx-warning@-2 {{is a pointer to non-trivially copyable type 'struct PtrAuthNonTrivial1'}} | ||
// expected-note@-3 {{explicitly cast the pointer to silence}} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I would like to have
isTriviallyCopyableType
do any required desugaring or canonicalization rather than requiring every call site do this work, it's a constant hazard.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.
Do we have to desugar the type before calling
isTriviallyCopyableType
? It doesn't look like other call sites are doing so.Why is the call to desugar` needed here?