Add new checker-specific attribute 'objc_ownership_cfretain'. This is the same
as 'objc_ownership_cfretain' except that the method acts like a CFRetain instead
of a [... retain] (important in GC modes). Checker support is wired up, but
currently only for Objective-C message expressions (not function calls).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70218 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp
index c2369ab..6223e7c 100644
--- a/lib/Analysis/CFRefCount.cpp
+++ b/lib/Analysis/CFRefCount.cpp
@@ -1104,7 +1104,11 @@
ScratchArgs.push_back(std::make_pair(i, IncRefMsg));
hasArgEffect = true;
}
-}
+ else if ((*I)->getAttr<ObjCOwnershipCFRetainAttr>()) {
+ ScratchArgs.push_back(std::make_pair(i, IncRef));
+ hasArgEffect = true;
+ }
+ }
if (!hasRetEffect && !hasArgEffect)
return 0;
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 508d2ef..50cc031 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -475,6 +475,7 @@
SIMPLE_ATTR(ObjCException);
SIMPLE_ATTR(ObjCNSObject);
+ SIMPLE_ATTR(ObjCOwnershipCFRetain);
SIMPLE_ATTR(ObjCOwnershipRetain);
SIMPLE_ATTR(ObjCOwnershipReturns);
SIMPLE_ATTR(Overloadable);
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 82eb5df..391a1f9 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -1420,6 +1420,7 @@
case Attr::ObjCException:
case Attr::ObjCNSObject:
+ case Attr::ObjCOwnershipCFRetain:
case Attr::ObjCOwnershipRetain:
case Attr::ObjCOwnershipReturns:
case Attr::Overloadable:
diff --git a/lib/Parse/AttributeList.cpp b/lib/Parse/AttributeList.cpp
index a9c552b..9e46159 100644
--- a/lib/Parse/AttributeList.cpp
+++ b/lib/Parse/AttributeList.cpp
@@ -136,12 +136,17 @@
case 21:
if (!memcmp(Str, "objc_ownership_retain", 21))
return AT_objc_ownership_retain;
+ break;
case 22:
if (!memcmp(Str, "objc_ownership_returns", 22))
return AT_objc_ownership_returns;
if (!memcmp(Str, "no_instrument_function", 22))
return AT_no_instrument_function;
break;
+ case 23:
+ if (!memcmp(Str, "objc_ownership_cfretain", 23))
+ return AT_objc_ownership_cfretain;
+ break;
}
return UnknownAttribute;
}
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index c0a3b44..7bbfb26 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -1545,6 +1545,18 @@
d->addAttr(::new (S.Context) ObjCOwnershipRetainAttr());
}
+static void HandleObjCOwnershipCFRetainAttr(Decl *d, const AttributeList &Attr,
+ Sema &S) {
+
+ if (!isa<ParmVarDecl>(d)) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) <<
+ "objc_ownership_cfretain" << 4 /* parameter */;
+ return;
+ }
+
+ d->addAttr(::new (S.Context) ObjCOwnershipCFRetainAttr());
+}
+
//===----------------------------------------------------------------------===//
// Top Level Sema Entry Points
//===----------------------------------------------------------------------===//
@@ -1587,6 +1599,8 @@
HandleObjCOwnershipRetainAttr(D, Attr, S); break;
case AttributeList::AT_objc_ownership_returns:
HandleObjCOwnershipReturnsAttr(D, Attr, S); break;
+ case AttributeList::AT_objc_ownership_cfretain:
+ HandleObjCOwnershipCFRetainAttr(D, Attr, S); break;
case AttributeList::AT_packed: HandlePackedAttr (D, Attr, S); break;
case AttributeList::AT_section: HandleSectionAttr (D, Attr, S); break;