diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2019-01-11 18:02:08 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2019-01-11 18:02:08 +0000 |
commit | bc7927d208280def86be0f33a509024b46d77f42 (patch) | |
tree | be85e7f3a404d82e17dba7bc44b61a973276943d /include/clang/Basic | |
parent | fb2ad0413c5c2c71e9e96bb7004acd4f4de32bf2 (diff) |
[attributes] Extend os_returns_(not_?)_retained attributes to parameters
When applied to out-parameters, the attributes specify the expected lifetime of the written-into object.
Additionally, introduce OSReturnsRetainedOn(Non)Zero attributes, which
specify that an ownership transfer happens depending on a return code.
Differential Revision: https://reviews.llvm.org/D56292
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350942 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic')
-rw-r--r-- | include/clang/Basic/Attr.td | 16 | ||||
-rw-r--r-- | include/clang/Basic/AttrDocs.td | 15 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 |
3 files changed, 30 insertions, 3 deletions
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 311cf943df..1fe1dd3994 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -841,13 +841,25 @@ def OSConsumed : InheritableParamAttr { def OSReturnsRetained : InheritableAttr { let Spellings = [Clang<"os_returns_retained">]; - let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>; + let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>; let Documentation = [RetainBehaviorDocs]; } def OSReturnsNotRetained : InheritableAttr { let Spellings = [Clang<"os_returns_not_retained">]; - let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>; + let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty, ParmVar]>; + let Documentation = [RetainBehaviorDocs]; +} + +def OSReturnsRetainedOnZero : InheritableAttr { + let Spellings = [Clang<"os_returns_retained_on_zero">]; + let Subjects = SubjectList<[ParmVar]>; + let Documentation = [RetainBehaviorDocs]; +} + +def OSReturnsRetainedOnNonZero : InheritableAttr { + let Spellings = [Clang<"os_returns_retained_on_non_zero">]; + let Subjects = SubjectList<[ParmVar]>; let Documentation = [RetainBehaviorDocs]; } diff --git a/include/clang/Basic/AttrDocs.td b/include/clang/Basic/AttrDocs.td index aae2d1ddfc..5773a92c9c 100644 --- a/include/clang/Basic/AttrDocs.td +++ b/include/clang/Basic/AttrDocs.td @@ -888,6 +888,21 @@ Similar to ``__attribute__((ns_consumes_self))``, ``__attribute__((os_consumes_this))`` specifies that the method call consumes the reference to "this" (e.g., when attaching it to a different object supplied as a parameter). +Out parameters (parameters the function is meant to write into, +either via pointers-to-pointers or references-to-pointers) +may be annotated with ``__attribute__((os_returns_retained))`` +or ``__attribute__((os_returns_not_retained))`` which specifies that the object +written into the out parameter should (or respectively should not) be released +after use. +Since often out parameters may or may not be written depending on the exit +code of the function, +annotations ``__attribute__((os_returns_retained_on_zero))`` +and ``__attribute__((os_returns_retained_on_non_zero))`` specify that +an out parameter at ``+1`` is written if and only if the function returns a zero +(respectively non-zero) error code. +Observe that return-code-dependent out parameter annotations are only +available for retained out parameters, as non-retained object do not have to be +released by the callee. These attributes are only used by the Clang Static Analyzer. The family of attributes ``X_returns_X_retained`` can be added to functions, diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 2f77773ac8..57c3abd048 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3425,7 +3425,7 @@ def err_ns_attribute_wrong_parameter_type : Error< "%select{Objective-C object|pointer|pointer-to-CF-pointer}1 parameters">; def warn_ns_attribute_wrong_parameter_type : Warning< "%0 attribute only applies to " - "%select{Objective-C object|pointer|pointer-to-CF-pointer}1 parameters">, + "%select{Objective-C object|pointer|pointer-to-CF-pointer|pointer/reference-to-OSObject-pointer}1 parameters">, InGroup<IgnoredAttributes>; def warn_objc_requires_super_protocol : Warning< "%0 attribute cannot be applied to %select{methods in protocols|dealloc}1">, |