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
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index e9ddce3..5a6babb 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -178,6 +178,10 @@
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 @@
}
}
+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.