[Sema] Add a new warning, -Wmemset-transposed-args
authorErik Pilkington <erik.pilkington@gmail.com>
Thu, 19 Jul 2018 16:46:15 +0000 (16:46 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Thu, 19 Jul 2018 16:46:15 +0000 (16:46 +0000)
commitd1cf276621a7382a0f8e1d6f70d317e3944ffbeb
tree4f021b8e007dd568e0374a085293f9387a0cbbef
parentb6022aa8d900d175da00a5ca7b948a27ec61f4bf
[Sema] Add a new warning, -Wmemset-transposed-args

This diagnoses calls to memset that have the second and third arguments
transposed, for example:

  memset(buf, sizeof(buf), 0);

This is done by checking if the third argument is a literal 0, or if the second
is a sizeof expression (and the third isn't). The first check is also done for
calls to bzero.

Differential revision: https://reviews.llvm.org/D49112

llvm-svn: 337470
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/transpose-memset.c [new file with mode: 0644]