diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2016-08-10 18:34:47 +0000 |
---|---|---|
committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2016-08-10 18:34:47 +0000 |
commit | 7ea9fd233bdccb45f0a43879d5f7d49d972c9a7d (patch) | |
tree | 241ab3ecc4b8f16c19d1a592232edeebdd1dba18 /clang/lib | |
parent | 12b0acc7274d2c39ba593be2adbb8c2a42e8809d (diff) | |
download | bcm5719-llvm-7ea9fd233bdccb45f0a43879d5f7d49d972c9a7d.tar.gz bcm5719-llvm-7ea9fd233bdccb45f0a43879d5f7d49d972c9a7d.zip |
Reapply [Sema] Add sizeof diagnostics for bzero
Reapply r277787. For memset (and others) we can get diagnostics like:
struct stat { int x; };
void foo(struct stat *stamps) {
bzero(stamps, sizeof(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 implements the same class of warnings for bzero.
Differential Revision: https://reviews.llvm.org/D22525
rdar://problem/18963514
llvm-svn: 278264
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index d1e8d25ea04..813a20a9f52 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3408,6 +3408,10 @@ unsigned FunctionDecl::getMemoryFunctionKind() const { case Builtin::BIstrlen: return Builtin::BIstrlen; + case Builtin::BI__builtin_bzero: + case Builtin::BIbzero: + return Builtin::BIbzero; + default: if (isExternC()) { if (FnInfo->isStr("memset")) @@ -3430,6 +3434,8 @@ unsigned FunctionDecl::getMemoryFunctionKind() const { return Builtin::BIstrndup; else if (FnInfo->isStr("strlen")) return Builtin::BIstrlen; + else if (FnInfo->isStr("bzero")) + return Builtin::BIbzero; } break; } diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index fd90121bfe3..f76ab083586 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -6179,13 +6179,15 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call, // It is possible to have a non-standard definition of memset. Validate // we have enough arguments, and if not, abort further checking. - unsigned ExpectedNumArgs = (BId == Builtin::BIstrndup ? 2 : 3); + unsigned ExpectedNumArgs = + (BId == Builtin::BIstrndup || BId == Builtin::BIbzero ? 2 : 3); if (Call->getNumArgs() < ExpectedNumArgs) return; - unsigned LastArg = (BId == Builtin::BImemset || + unsigned LastArg = (BId == Builtin::BImemset || BId == Builtin::BIbzero || BId == Builtin::BIstrndup ? 1 : 2); - unsigned LenArg = (BId == Builtin::BIstrndup ? 1 : 2); + unsigned LenArg = + (BId == Builtin::BIbzero || BId == Builtin::BIstrndup ? 1 : 2); const Expr *LenExpr = Call->getArg(LenArg)->IgnoreParenImpCasts(); if (CheckMemorySizeofForComparison(*this, LenExpr, FnName, |