diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-12-21 08:04:20 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-12-21 08:04:20 +0000 |
commit | b1ea510de0ef4ebfbbe8fa7668ab1635410fc080 (patch) | |
tree | 73b20094c98818538ef99c531c4d66ec70eec9a8 /lib/Sema/SemaChecking.cpp | |
parent | 0dbe2fb7758fe64568206b5bc0f1c5b106b9c806 (diff) |
Refactor checkUnsafeAssigns() to avoid code duplication with while loop.
This is just a minor bit of refactoring, but it is nice cleanup for
the subsequent patch that adds warning support for assigning literals
to weak variables.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170863 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 095d25aa02..eafe595687 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -5749,16 +5749,15 @@ void Sema::checkRetainCycles(VarDecl *Var, Expr *Init) { diagnoseRetainCycle(*this, Capturer, Owner); } -bool Sema::checkUnsafeAssigns(SourceLocation Loc, - QualType LHS, Expr *RHS) { - Qualifiers::ObjCLifetime LT = LHS.getObjCLifetime(); - if (LT != Qualifiers::OCL_Weak && LT != Qualifiers::OCL_ExplicitNone) - return false; - // strip off any implicit cast added to get to the one arc-specific +static bool checkUnsafeAssignObject(Sema &S, SourceLocation Loc, + Qualifiers::ObjCLifetime LT, + Expr *RHS, bool isProperty) { + // Strip off any implicit cast added to get to the one ARC-specific. while (ImplicitCastExpr *cast = dyn_cast<ImplicitCastExpr>(RHS)) { if (cast->getCastKind() == CK_ARCConsumeObject) { - Diag(Loc, diag::warn_arc_retained_assign) - << (LT == Qualifiers::OCL_ExplicitNone) << 1 + S.Diag(Loc, diag::warn_arc_retained_assign) + << (LT == Qualifiers::OCL_ExplicitNone) + << (isProperty ? 0 : 1) << RHS->getSourceRange(); return true; } @@ -5767,6 +5766,19 @@ bool Sema::checkUnsafeAssigns(SourceLocation Loc, return false; } +bool Sema::checkUnsafeAssigns(SourceLocation Loc, + QualType LHS, Expr *RHS) { + Qualifiers::ObjCLifetime LT = LHS.getObjCLifetime(); + + if (LT != Qualifiers::OCL_Weak && LT != Qualifiers::OCL_ExplicitNone) + return false; + + if (checkUnsafeAssignObject(*this, Loc, LT, RHS, false)) + return true; + + return false; +} + void Sema::checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS) { QualType LHSType; @@ -5826,14 +5838,8 @@ void Sema::checkUnsafeExprAssigns(SourceLocation Loc, } } else if (Attributes & ObjCPropertyDecl::OBJC_PR_weak) { - while (ImplicitCastExpr *cast = dyn_cast<ImplicitCastExpr>(RHS)) { - if (cast->getCastKind() == CK_ARCConsumeObject) { - Diag(Loc, diag::warn_arc_retained_assign) - << 0 << 0<< RHS->getSourceRange(); - return; - } - RHS = cast->getSubExpr(); - } + if (checkUnsafeAssignObject(*this, Loc, Qualifiers::OCL_Weak, RHS, true)) + return; } } } |