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

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 17:26:19 PDT 2018


erik.pilkington created this revision.
erik.pilkington added reviewers: rsmith, aaron.ballman, arphaman.
Herald added a subscriber: dexonsmith.

This warning tries to catch programs that incorrectly call memset with the second and third arguments transposed, ie `memset(ary, sizeof(ary), 0)` instead of `memset(ary, 0, sizeof(ary))`. This is done by looking at two factors: 1) if the last argument is `0`, then this is likely a bug (looks this is what GCC's implementation does) and 2) if the last argument isn't `0`, but the second argument is a `sizeof`expression. This catches cases like `memset(ary, sizeof(ary), 0xff)`. I also grouped a couple of related diagnostics that deal with these c functions into a new group, -Wsuspicious-memaccess.

llvm.org/PR36242

Thanks for taking a look!
Erik


Repository:
  rC Clang

https://reviews.llvm.org/D49112

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/transpose-memset.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49112.154727.patch
Type: text/x-patch
Size: 8472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180710/eea17108/attachment.bin>


More information about the cfe-commits mailing list