Clang note: explicitly cast the pointer to silence this warning (note_bad_memaccess_silence)
Jump to navigation
Jump to search
Text | error: explicitly cast the pointer to silence this warning |
---|---|
Type | Note |
Category | Semantic Issue |
Internal Id | note_bad_memaccess_silence |
Internal Message | explicitly cast the pointer to silence this warning
|
Regular Expression | note\: explicitly cast the pointer to silence this warning
|
First Commit | 2011-06-03 ac6872655bc6 Clean up the "non-POD memaccess" stuff some. This adds a properly named |
Description
Example
Flags | -xc++
|
|
---|---|---|
Source |
#include <string.h>
struct S { int x; virtual void f() {} };
int main() {
S s;
// Virtual function introduces vtable
memset(&s, 0, sizeof(s));
return 0;
}
| |
Compiler Output |
<source>:7:10: warning: destination for this 'memset' call is a pointer to dynamic class 'S'; vtable pointer will be overwritten [-Wdynamic-class-memaccess] <source>:7:10: note: explicitly cast the pointer to silence this warning |
Clang Internals (17.0.6)
Git Commit Message
Clean up the "non-POD memaccess" stuff some. This adds a properly named diagnostic group to cover the cases where we have definitively bad behavior: dynamic classes. It also rips out the existing support for POD-based checking. This didn't work well, and triggered too many false positives. I'm looking into a possibly more principled way to warn on the fundamental buggy construct here. POD-ness isn't the critical aspect anyways, so a clean slate is better. This also removes some silliness from the code until the new checks arrive. llvm-svn: 132534
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaChecking.cpp (line 12603)
/// Check for dangerous or invalid arguments to memset().
///
/// This issues warnings on known problematic, dangerous or unspecified
/// arguments to the standard 'memset', 'memcpy', 'memmove', and 'memcmp'
/// function calls.
///
/// \param Call The call expression to diagnose.
void Sema::CheckMemaccessArguments(const CallExpr *Call, unsigned BId, IdentifierInfo *FnName) {
// ...
for (unsigned ArgIdx = 0; ArgIdx != LastArg; ++ArgIdx) {
// ...
DiagRuntimeBehavior(Dest->getExprLoc(), Dest, PDiag(diag::note_bad_memaccess_silence) << FixItHint::CreateInsertion(ArgRange.getBegin(), "(void*)"));
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaObjC/warn-nontrivial-struct-memaccess.m
- clang/test/SemaObjC/warn-nontrivial-struct-memaccess.m:34:10: note: explicitly cast the pointer to silence this warning
- clang/test/SemaObjC/warn-nontrivial-struct-memaccess.m:36:9: note: explicitly cast the pointer to silence this warning
- clang/test/SemaObjC/warn-nontrivial-struct-memaccess.m:37:10: note: explicitly cast the pointer to silence this warning
- clang/test/SemaObjC/warn-nontrivial-struct-memaccess.m:38:11: note: explicitly cast the pointer to silence this warning