summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-01-17 06:24:47 +0000
committerTed Kremenek <kremenek@apple.com>2014-01-17 06:24:47 +0000
commita146db39871c93121251bb33a33a6ef6d305ed9e (patch)
treedacd4e6c8ef238d44c9d442ce98e71b362af8083 /clang/lib/Sema/SemaChecking.cpp
parent2bc7333a06eb65e0ca151c7d4f8ba9a61c952e29 (diff)
downloadbcm5719-llvm-a146db39871c93121251bb33a33a6ef6d305ed9e.tar.gz
bcm5719-llvm-a146db39871c93121251bb33a33a6ef6d305ed9e.zip
Push NonNullAttr inspection loop into CheckNonNullArguments.
No functionality change. llvm-svn: 199465
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1ea862ab188..714e975e42f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -713,29 +713,39 @@ bool Sema::getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember,
return true;
}
+static void CheckNonNullArgument(Sema &S,
+ const Expr *ArgExpr,
+ SourceLocation CallSiteLoc) {
+ // As a special case, transparent unions initialized with zero are
+ // considered null for the purposes of the nonnull attribute.
+ if (const RecordType *UT = ArgExpr->getType()->getAsUnionType()) {
+ if (UT->getDecl()->hasAttr<TransparentUnionAttr>())
+ if (const CompoundLiteralExpr *CLE =
+ dyn_cast<CompoundLiteralExpr>(ArgExpr))
+ if (const InitListExpr *ILE =
+ dyn_cast<InitListExpr>(CLE->getInitializer()))
+ ArgExpr = ILE->getInit(0);
+ }
+
+ bool Result;
+ if (ArgExpr->EvaluateAsBooleanCondition(Result, S.Context) && !Result)
+ S.Diag(CallSiteLoc, diag::warn_null_arg) << ArgExpr->getSourceRange();
+}
+
static void CheckNonNullArguments(Sema &S,
- const NonNullAttr *NonNull,
+ const NamedDecl *FDecl,
const Expr * const *ExprArgs,
SourceLocation CallSiteLoc) {
- for (NonNullAttr::args_iterator i = NonNull->args_begin(),
- e = NonNull->args_end();
- i != e; ++i) {
- const Expr *ArgExpr = ExprArgs[*i];
-
- // As a special case, transparent unions initialized with zero are
- // considered null for the purposes of the nonnull attribute.
- if (const RecordType *UT = ArgExpr->getType()->getAsUnionType()) {
- if (UT->getDecl()->hasAttr<TransparentUnionAttr>())
- if (const CompoundLiteralExpr *CLE =
- dyn_cast<CompoundLiteralExpr>(ArgExpr))
- if (const InitListExpr *ILE =
- dyn_cast<InitListExpr>(CLE->getInitializer()))
- ArgExpr = ILE->getInit(0);
- }
+ for (specific_attr_iterator<NonNullAttr>
+ I = FDecl->specific_attr_begin<NonNullAttr>(),
+ E = FDecl->specific_attr_end<NonNullAttr>(); I != E; ++I) {
- bool Result;
- if (ArgExpr->EvaluateAsBooleanCondition(Result, S.Context) && !Result)
- S.Diag(CallSiteLoc, diag::warn_null_arg) << ArgExpr->getSourceRange();
+ const NonNullAttr *NonNull = *I;
+ for (NonNullAttr::args_iterator i = NonNull->args_begin(),
+ e = NonNull->args_end();
+ i != e; ++i) {
+ CheckNonNullArgument(S, ExprArgs[*i], CallSiteLoc);
+ }
}
}
@@ -780,10 +790,7 @@ void Sema::checkCall(NamedDecl *FDecl,
}
if (FDecl) {
- for (specific_attr_iterator<NonNullAttr>
- I = FDecl->specific_attr_begin<NonNullAttr>(),
- E = FDecl->specific_attr_end<NonNullAttr>(); I != E; ++I)
- CheckNonNullArguments(*this, *I, Args.data(), Loc);
+ CheckNonNullArguments(*this, FDecl, Args.data(), Loc);
// Type safety checking.
for (specific_attr_iterator<ArgumentWithTypeTagAttr>
OpenPOWER on IntegriCloud