aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-05-21 18:48:51 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-05-21 18:48:51 +0000
commite898f8a94947c6074d76ff83943b47d5bbdf210d (patch)
tree1f78161a32336d99f5d0daedfcf751241a64c474 /lib/Sema/SemaChecking.cpp
parent12d0c307369e4a523e2e40025bf124c310f98dff (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/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp14
1 files changed, 14 insertions, 0 deletions
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.