[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args
Arthur O'Dwyer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 9 17:49:49 PDT 2018
Quuxplusone added inline comments.
================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:662
+def note_suspicious_sizeof_memset_silence : Note<
+ "%select{parenthesize the third argument|cast the second argument to 'int'}0 to silence">;
+
----------------
If it were my codebase, I'd rather see a cast to `(unsigned char)` than a cast to `(int)`. (The second argument to memset is supposed to be a single byte.) Why did you pick `(int)` specifically?
================
Comment at: clang/lib/Sema/SemaChecking.cpp:7962
+ if (auto *BO = dyn_cast<BinaryOperator>(SizeofExpr)) {
+ if (BO->getOpcode() != BO_Mul)
+ return false;
----------------
Honestly, if the second argument to `memset` involves `sizeof` *at all*, it's probably a bug, isn't it?
memset(&buf, sizeof foo + 10, 0xff);
memset(&buf, sizeof foo * sizeof bar, 0xff);
Should Clang really go out of its way to silence the warning in these cases?
Repository:
rC Clang
https://reviews.llvm.org/D49112
More information about the cfe-commits
mailing list