diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2014-08-08 17:31:14 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2014-08-08 17:31:14 +0000 |
commit | 495bc3f5f6a1924dddfeb3c090520175e637af4d (patch) | |
tree | 691b5a3a8bccc2e4c587ee19079b7098067a08e0 /clang/lib | |
parent | 241fd486eb4134361de5f571ed6b929d1603241a (diff) | |
download | bcm5719-llvm-495bc3f5f6a1924dddfeb3c090520175e637af4d.tar.gz bcm5719-llvm-495bc3f5f6a1924dddfeb3c090520175e637af4d.zip |
Objective-C ARC. Use of non-retain/autorelease API
for building Objective-C array literals in ARC
mode. rdar://17554063
llvm-svn: 215232
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 41 |
2 files changed, 36 insertions, 6 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 4ed5aa8a287..205081b656a 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -98,6 +98,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, InitArrayWithObjectsMethod(nullptr), NSDictionaryDecl(nullptr), DictionaryWithObjectsMethod(nullptr), InitDictionaryWithObjectsMethod(nullptr), + ArrayAllocObjectsMethod(nullptr), DictAllocObjectsMethod(nullptr), GlobalNewDeleteDeclared(false), TUKind(TUKind), diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index e4625bc98c2..786637c205e 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -630,6 +630,7 @@ ExprResult Sema::BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, } ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) { + bool Arc = getLangOpts().ObjCAutoRefCount; // Look up the NSArray class, if we haven't done so already. if (!NSArrayDecl) { NamedDecl *IF = LookupSingleName(TUScope, @@ -649,18 +650,45 @@ ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) { return ExprError(); } } - - // Find the arrayWithObjects:count: method, if we haven't done so already. QualType IdT = Context.getObjCIdType(); + if (Arc && !ArrayAllocObjectsMethod) { + // Find +[NSArray alloc] method. + IdentifierInfo *II = &Context.Idents.get("alloc"); + Selector AllocSel = Context.Selectors.getSelector(0, &II); + ArrayAllocObjectsMethod = NSArrayDecl->lookupClassMethod(AllocSel); + if (!ArrayAllocObjectsMethod && getLangOpts().DebuggerObjCLiteral) { + ArrayAllocObjectsMethod = ObjCMethodDecl::Create(Context, + SourceLocation(), SourceLocation(), AllocSel, + IdT, + nullptr /*TypeSourceInfo */, + Context.getTranslationUnitDecl(), + false /*Instance*/, false/*isVariadic*/, + /*isPropertyAccessor=*/false, + /*isImplicitlyDeclared=*/true, /*isDefined=*/false, + ObjCMethodDecl::Required, + false); + SmallVector<ParmVarDecl *, 1> Params; + ArrayAllocObjectsMethod->setMethodParams(Context, Params, None); + } + if (!ArrayAllocObjectsMethod) { + Diag(SR.getBegin(), diag::err_undeclared_alloc); + return ExprError(); + } + } + // Find the arrayWithObjects:count: method, if we haven't done so already. if (!ArrayWithObjectsMethod) { Selector - Sel = NSAPIObj->getNSArraySelector(NSAPI::NSArr_arrayWithObjectsCount); - ObjCMethodDecl *Method = NSArrayDecl->lookupClassMethod(Sel); + Sel = NSAPIObj->getNSArraySelector( + Arc? NSAPI::NSArr_initWithObjectsCount : NSAPI::NSArr_arrayWithObjectsCount); + ObjCMethodDecl *Method = + Arc? NSArrayDecl->lookupInstanceMethod(Sel) + : NSArrayDecl->lookupClassMethod(Sel); if (!Method && getLangOpts().DebuggerObjCLiteral) { TypeSourceInfo *ReturnTInfo = nullptr; Method = ObjCMethodDecl::Create( Context, SourceLocation(), SourceLocation(), Sel, IdT, ReturnTInfo, - Context.getTranslationUnitDecl(), false /*Instance*/, + Context.getTranslationUnitDecl(), + Arc /*Instance for Arc, Class for MRR*/, false /*isVariadic*/, /*isPropertyAccessor=*/false, /*isImplicitlyDeclared=*/true, /*isDefined=*/false, @@ -740,7 +768,8 @@ ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) { return MaybeBindToTemporary( ObjCArrayLiteral::Create(Context, Elements, Ty, - ArrayWithObjectsMethod, nullptr, SR)); + ArrayWithObjectsMethod, + ArrayAllocObjectsMethod, SR)); } ExprResult Sema::BuildObjCDictionaryLiteral(SourceRange SR, |