This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Add sizeof diagnostics for bzero
ClosedPublic

Authored by bruno on Jul 19 2016, 11:56 AM.

Details

Summary

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.

Diff Detail

Event Timeline

bruno updated this revision to Diff 64536.Jul 19 2016, 11:56 AM
bruno retitled this revision from to [Sema] Add sizeof diagnostics for bzero.
bruno updated this object.
bruno added a reviewer: zaks.anna.
bruno added a subscriber: cfe-commits.
zaks.anna accepted this revision.Jul 22 2016, 10:43 AM
zaks.anna edited edge metadata.
This revision is now accepted and ready to land.Jul 22 2016, 10:43 AM
bruno closed this revision.Aug 4 2016, 5:08 PM

Thanks! Committed in r277787