Index: include/clang/Basic/DiagnosticGroups.td =================================================================== --- include/clang/Basic/DiagnosticGroups.td +++ include/clang/Basic/DiagnosticGroups.td @@ -498,6 +498,7 @@ def ARCRepeatedUseOfWeakMaybe : DiagGroup<"arc-maybe-repeated-use-of-weak">; def ARCRepeatedUseOfWeak : DiagGroup<"arc-repeated-use-of-weak", [ARCRepeatedUseOfWeakMaybe]>; +def BlockCaptureAutoReleasing : DiagGroup<"block-capture-autoreleasing">; def ObjCBridge : DiagGroup<"bridge-cast">; def DeallocInCategory:DiagGroup<"dealloc-in-category">; Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -5073,6 +5073,12 @@ } // end "ARC and @properties" category +def warn_block_capture_autoreleasing : Warning< + "block captures indirect parameter implicitly qualified with __autoreleasing">, + InGroup, DefaultIgnore; +def note_explicit_ownership_qualification : Note< + "explicitly specify ownership qualification">; + def err_arc_atomic_ownership : Error< "cannot perform atomic operation on a pointer to type %0: type has " "non-trivial ownership">; Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -13473,6 +13473,20 @@ } return false; } + + // Warn about implicitly autoreleasing indirect parameters captured by blocks. + if (auto *PT = dyn_cast(CaptureType)) { + QualType PointeeTy = PT->getPointeeType(); + if (isa(PointeeTy.getCanonicalType()) && + PointeeTy.getObjCLifetime() == Qualifiers::OCL_Autoreleasing && + !isa(PointeeTy)) { + if (BuildAndDiagnose) { + S.Diag(Loc, diag::warn_block_capture_autoreleasing); + S.Diag(Var->getLocation(), diag::note_explicit_ownership_qualification); + } + } + } + const bool HasBlocksAttr = Var->hasAttr(); if (HasBlocksAttr || CaptureType->isReferenceType() || (S.getLangOpts().OpenMP && S.IsOpenMPCapturedDecl(Var))) { Index: test/SemaObjC/arc.m =================================================================== --- test/SemaObjC/arc.m +++ test/SemaObjC/arc.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class -Wblock-capture-autoreleasing %s typedef unsigned long NSUInteger; typedef const void * CFTypeRef; @@ -808,3 +808,10 @@ TKAssertEqual(object, nil); TKAssertEqual(object, (id)nil); } + +void block_capture_autoreleasing(A * __autoreleasing *a, A **b) { // expected-note {{explicitly specify ownership qualification}} + ^{ + (void)*a; + (void)*b; // expected-warning {{block captures indirect parameter implicitly qualified with __autoreleasing}} + }(); +}