[PATCH] D22525: [Sema] Add sizeof diagnostics for bzero

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 19 11:56:37 PDT 2016


bruno created this revision.
bruno added a reviewer: zaks.anna.
bruno added a subscriber: cfe-commits.

For memset (and others) we can get diagnostics like:

  struct stat { int x; };
  void foo(struct stat *stamps) {
    memset(stamps, 0, sizeof(stamps));
  }

  t.c:7:28: warning: 'memset' call operates on objects of type 'struct stat' while the size is based on a different type 'struct stat *' [-Wsizeof-pointer-memaccess]
    memset(stamps, 0, sizeof(stamps));
           ~~~~~~            ^~~~~~
  t.c:7:28: note: did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?
    memset(stamps, 0, sizeof(stamps));
                             ^~~~~~

This patch adds support for the same class of warnings for bzero.

https://reviews.llvm.org/D22525

Files:
  lib/AST/Decl.cpp
  lib/Sema/SemaChecking.cpp
  test/SemaCXX/warn-memset-bad-sizeof.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22525.64536.patch
Type: text/x-patch
Size: 5537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160719/42837344/attachment.bin>


More information about the cfe-commits mailing list