From b2d83f8c8c536ba1263ea7f4897ddbe7b60677c9 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 17 Jan 2014 06:24:47 +0000 Subject: [PATCH] Push NonNullAttr inspection loop into CheckNonNullArguments. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199465 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 53 ++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 1ea862ab18..714e975e42 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/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()) + if (const CompoundLiteralExpr *CLE = + dyn_cast(ArgExpr)) + if (const InitListExpr *ILE = + dyn_cast(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()) - if (const CompoundLiteralExpr *CLE = - dyn_cast(ArgExpr)) - if (const InitListExpr *ILE = - dyn_cast(CLE->getInitializer())) - ArgExpr = ILE->getInit(0); - } + for (specific_attr_iterator + I = FDecl->specific_attr_begin(), + E = FDecl->specific_attr_end(); 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 - I = FDecl->specific_attr_begin(), - E = FDecl->specific_attr_end(); I != E; ++I) - CheckNonNullArguments(*this, *I, Args.data(), Loc); + CheckNonNullArguments(*this, FDecl, Args.data(), Loc); // Type safety checking. for (specific_attr_iterator -- 2.49.0