From b316dc517d9721ac9047819e4eeaa0eb59c4020a Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 31 Jul 2013 17:12:26 +0000 Subject: [PATCH] ObjectiveC arc: Move check for type conversions in arc out of ImpCastExprToType and to the caller site as appropriate. This is in prep. to do more work for // rdar://14569171 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187503 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/Sema.cpp | 3 --- lib/Sema/SemaExpr.cpp | 26 +++++++++++++++++++------- lib/Sema/SemaExprCXX.cpp | 3 ++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 8faa919773..b75ef9a5f8 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -284,9 +284,6 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty, if (ExprTy == TypeTy) return Owned(E); - if (getLangOpts().ObjCAutoRefCount) - CheckObjCARCConversion(SourceRange(), Ty, E, CCK); - // If this is a derived-to-base cast to a through a virtual base, we // need a vtable. if (Kind == CK_DerivedToBase && diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 65654b67cf..4397fb71ff 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -6443,9 +6443,13 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &RHS, // so that we can use references in built-in functions even in C. // The getNonReferenceType() call makes sure that the resulting expression // does not have reference type. - if (result != Incompatible && RHS.get()->getType() != LHSType) - RHS = ImpCastExprToType(RHS.take(), - LHSType.getNonLValueExprType(Context), Kind); + if (result != Incompatible && RHS.get()->getType() != LHSType) { + QualType Ty = LHSType.getNonLValueExprType(Context); + Expr *E = RHS.take(); + if (getLangOpts().ObjCAutoRefCount) + CheckObjCARCConversion(SourceRange(), Ty, E, CCK_ImplicitConversion); + RHS = ImpCastExprToType(E, Ty, Kind); + } return result; } @@ -7698,12 +7702,20 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS, diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, /*isError*/false); } - if (LHSIsNull && !RHSIsNull) - LHS = ImpCastExprToType(LHS.take(), RHSType, + if (LHSIsNull && !RHSIsNull) { + Expr *E = LHS.take(); + if (getLangOpts().ObjCAutoRefCount) + CheckObjCARCConversion(SourceRange(), RHSType, E, CCK_ImplicitConversion); + LHS = ImpCastExprToType(E, RHSType, RPT ? CK_BitCast :CK_CPointerToObjCPointerCast); - else - RHS = ImpCastExprToType(RHS.take(), LHSType, + } + else { + Expr *E = RHS.take(); + if (getLangOpts().ObjCAutoRefCount) + CheckObjCARCConversion(SourceRange(), LHSType, E, CCK_ImplicitConversion); + RHS = ImpCastExprToType(E, LHSType, LPT ? CK_BitCast :CK_CPointerToObjCPointerCast); + } return ResultTy; } if (LHSType->isObjCObjectPointerType() && diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 4fe613e792..90841d8745 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -2765,7 +2765,8 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, (void) PrepareCastToObjCObjectPointer(E); From = E.take(); } - + if (getLangOpts().ObjCAutoRefCount) + CheckObjCARCConversion(SourceRange(), ToType, From, CCK); From = ImpCastExprToType(From, ToType, Kind, VK_RValue, &BasePath, CCK) .take(); break; -- 2.40.0