aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-06-16 09:09:40 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-06-16 09:09:40 +0000
commit8b9e5a72cb1219d40ef12e319ac2d835a8b19ee9 (patch)
tree0ab643f93482420064866db73d74f22580fe1270 /clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
parentc026370858e31e99a8190e4c945676fb2f3e941f (diff)
downloadllvm-8b9e5a72cb1219d40ef12e319ac2d835a8b19ee9.zip
llvm-8b9e5a72cb1219d40ef12e319ac2d835a8b19ee9.tar.gz
llvm-8b9e5a72cb1219d40ef12e319ac2d835a8b19ee9.tar.bz2
Rework the warning for 'memset(p, 0, sizeof(p))' where 'p' is a pointer
and the programmer intended to write 'sizeof(*p)'. There are several elements to the new version: 1) The actual expressions are compared in order to more accurately flag the case where the pattern that works for an array has been used, or a '*' has been omitted. 2) Only do a loose type-based check for record types. This prevents us from warning when we happen to be copying around chunks of data the size of a pointer and the pointer types for the sizeof and source/dest match. 3) Move all the diagnostics behind the runtime diagnostic filter. Not sure this is really important for this particular diagnostic, but almost everything else in SemaChecking.cpp does so. 4) Make the wording of the diagnostic more precise and informative. At least to my eyes. 5) Provide highlighting for the two expressions which had the unexpected similarity. 6) Place this diagnostic under a flag: -Wsizeof-pointer-memaccess This uses the Stmt::Profile system for computing #1. Because of the potential cost, this is guarded by the warning flag. I'd be interested in feedback on how bad this is in practice; I would expect it to be quite cheap in practice. Ideas for a cheaper / better way to do this are also welcome. The diagnostic wording could likely use some further wordsmithing. Suggestions welcome here. The goals I had were to: clarify that its the interaction of 'memset' and 'sizeof' and give more reasonable suggestions for a resolution. An open question is whether these diagnostics should have the note attached for silencing by casting the dest/source pointer to void*. llvm-svn: 133155
Diffstat (limited to 'clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions