[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 13 05:02:20 PDT 2018
aaron.ballman 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">;
+
----------------
erik.pilkington wrote:
> Quuxplusone wrote:
> > 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?
> I chose `int` because that's the actual type of the second parameter to `memset`, it just gets casted down to `unsigned char` internally. FWIW, either type will suppress the warning. I'm fine with recommending `unsigned char` if you have a strong preference for it.
My preference is for `int` as well.
================
Comment at: clang/lib/Sema/SemaChecking.cpp:7975-7976
+static void CheckMemsetSizeof(Sema &S, unsigned BId, const CallExpr *Call) {
+ if (BId != Builtin::BImemset)
+ return;
+
----------------
This functionality should apply equally to `wmemset()` as well, should it not? The only difference I can think of would be that the type should be cast to `wchar_t` instead of `int` to silence the warning.
================
Comment at: clang/lib/Sema/SemaChecking.cpp:7997
+
+
+ // If the function is defined as a builtin macro, do not show macro expansion.
----------------
Spurious whitespace.
https://reviews.llvm.org/D49112
More information about the cfe-commits
mailing list