diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-21 18:48:51 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-21 18:48:51 +0000 |
commit | e898f8a94947c6074d76ff83943b47d5bbdf210d (patch) | |
tree | 1f78161a32336d99f5d0daedfcf751241a64c474 /lib/Sema | |
parent | 12d0c307369e4a523e2e40025bf124c310f98dff (diff) |
Check on null arguments in the presense of nonnull attribute.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72219 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 14 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 9c294e0b10..25284318a3 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -2741,6 +2741,8 @@ private: void CheckPrintfString(const StringLiteral *FExpr, const Expr *OrigFormatExpr, const CallExpr *TheCall, bool HasVAListArg, unsigned format_idx, unsigned firstDataArg); + void CheckNonNullArguments(const NonNullAttr *NonNull, + const CallExpr *TheCall); void CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg, unsigned format_idx, unsigned firstDataArg); void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index e9ddce33ce..5a6babb321 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -178,6 +178,10 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { HasVAListArg ? 0 : Format->getFirstArg() - 1); } } + for (const Attr *attr = FDecl->getAttrs(); attr; attr = attr->getNext()) { + if (const NonNullAttr *NonNull = dyn_cast<NonNullAttr>(attr)) + CheckNonNullArguments(NonNull, TheCall); + } return move(TheCallResult); } @@ -784,6 +788,16 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall, } } +void +Sema::CheckNonNullArguments(const NonNullAttr *NonNull, const CallExpr *TheCall) +{ + for (NonNullAttr::iterator i = NonNull->begin(), e = NonNull->end(); + i != e; ++i) { + const Expr *ArgExpr = TheCall->getArg(*i)->IgnoreParenCasts(); + if (ArgExpr->isNullPointerConstant(Context)) + Diag(ArgExpr->getLocStart(), diag::warn_null_arg); + } +} /// CheckPrintfArguments - Check calls to printf (and similar functions) for /// correct use of format strings. |