[PATCH] D49112: [Sema] Implement -Wmemset-transposed-args

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 17 10:16:59 PDT 2018


erik.pilkington planned changes to this revision.
erik.pilkington added a comment.

In https://reviews.llvm.org/D49112#1158793, @thakis wrote:

> lgtm assuming you ran this on some large code base to make sure it doesn't have false positives.


Sorry for the delay here, I was running this on some very large internal code bases. This is overwhelmingly true-positive, but there are 2 improvements I want to make here before landing this:

- Suppress the diagnostic in cases like `memset(ptr, 0xff, PADDING)`, when PADDING is a macro defined to be 0.
- Some platforms #define bzero to `__builtin_memset`, so we should recognize when we're in a macro expansion to bzero and emit a more accurate diagnostic for `bzero(ary, 0);`. We might as well add support for `__builtin_bzero` too.



================
Comment at: clang/lib/Sema/SemaChecking.cpp:7975-7976
+static void CheckMemsetSizeof(Sema &S, unsigned BId, const CallExpr *Call) {
+  if (BId != Builtin::BImemset)
+    return;
+
----------------
aaron.ballman wrote:
> 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.
Looks like clang doesn't have a builtin for wmemset, its just defined as a normal function. I suppose that we could still try to diagnose calls to top-level functions named wmemset, but thats unprecedented and doesn't really seem worth the trouble.


https://reviews.llvm.org/D49112





More information about the cfe-commits mailing list