diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-08-02 18:03:58 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-08-02 18:03:58 +0000 |
commit | dc48305e319c56f6f305c12b9faecdc378dfebdc (patch) | |
tree | b96f5eef2fb3221c2392ae53277a21eac13bebc9 /lib/Sema/SemaPseudoObject.cpp | |
parent | 1abee64ad71519ea9d91f1fe76441b9cdb75b6c0 (diff) |
objective-c arc: Patch to suggest bridge casting of CF
objects used as dictionary subscript objects.
// rdar://11913153
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161187 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaPseudoObject.cpp')
-rw-r--r-- | lib/Sema/SemaPseudoObject.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index 4921ec9bfe..722ac19be5 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -955,6 +955,27 @@ Sema::ObjCSubscriptKind return OS_Error; } +/// CheckKeyForObjCARCConversion - This routine suggests bridge casting of CF +/// objects used as dictionary subscript key objects. +static void CheckKeyForObjCARCConversion(Sema &S, QualType ContainerT, + Expr *Key) { + if (ContainerT.isNull()) + return; + // dictionary subscripting. + // - (id)objectForKeyedSubscript:(id)key; + IdentifierInfo *KeyIdents[] = { + &S.Context.Idents.get("objectForKeyedSubscript") + }; + Selector GetterSelector = S.Context.Selectors.getSelector(1, KeyIdents); + ObjCMethodDecl *Getter = S.LookupMethodInObjectType(GetterSelector, ContainerT, + true /*instance*/); + if (!Getter) + return; + QualType T = Getter->param_begin()[0]->getType(); + S.CheckObjCARCConversion(Key->getSourceRange(), + T, Key, Sema::CCK_ImplicitConversion); +} + bool ObjCSubscriptOpBuilder::findAtIndexGetter() { if (AtIndexGetter) return true; @@ -972,8 +993,12 @@ bool ObjCSubscriptOpBuilder::findAtIndexGetter() { } Sema::ObjCSubscriptKind Res = S.CheckSubscriptingKind(RefExpr->getKeyExpr()); - if (Res == Sema::OS_Error) + if (Res == Sema::OS_Error) { + if (S.getLangOpts().ObjCAutoRefCount) + CheckKeyForObjCARCConversion(S, ResultType, + RefExpr->getKeyExpr()); return false; + } bool arrayRef = (Res == Sema::OS_Array); if (ResultType.isNull()) { @@ -1080,8 +1105,12 @@ bool ObjCSubscriptOpBuilder::findAtIndexSetter() { Sema::ObjCSubscriptKind Res = S.CheckSubscriptingKind(RefExpr->getKeyExpr()); - if (Res == Sema::OS_Error) + if (Res == Sema::OS_Error) { + if (S.getLangOpts().ObjCAutoRefCount) + CheckKeyForObjCARCConversion(S, ResultType, + RefExpr->getKeyExpr()); return false; + } bool arrayRef = (Res == Sema::OS_Array); if (ResultType.isNull()) { |