diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2017-09-20 06:32:45 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2017-09-20 06:32:45 +0000 |
commit | a4e2a1bb79ad3a93151ebd059a0d2cf0f88ff4aa (patch) | |
tree | 96c3afc54ecd82000558a3017b242d752d34439c /include/clang/Basic/AttrDocs.td | |
parent | b87abe7024808ca31ff5bb25aecef7f92b694cfa (diff) |
Add support for attribute 'noescape'.
The attribute informs the compiler that the annotated pointer parameter
of a function cannot escape and enables IRGen to attach attribute
'nocapture' to parameters that are annotated with the attribute. That is
the only optimization that currently takes advantage of 'noescape', but
there are other optimizations that will be added later that improves
IRGen for ObjC blocks.
rdar://problem/19886775
Differential Revision: https://reviews.llvm.org/D32210
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313722 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/AttrDocs.td')
-rw-r--r-- | include/clang/Basic/AttrDocs.td | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/clang/Basic/AttrDocs.td b/include/clang/Basic/AttrDocs.td index 6a7bbbcffd..0500c28386 100644 --- a/include/clang/Basic/AttrDocs.td +++ b/include/clang/Basic/AttrDocs.td @@ -130,6 +130,47 @@ members, and static locals. }]; } +def NoEscapeDocs : Documentation { + let Category = DocCatVariable; + let Content = [{ +``noescape`` placed on a function parameter of a pointer type is used to inform +the compiler that the pointer cannot escape: that is, no reference to the object +the pointer points to that is derived from the parameter value will survive +after the function returns. Users are responsible for making sure parameters +annotated with ``noescape`` do not actuallly escape. + +For example: + +.. code-block:: c + int *gp; + + void nonescapingFunc(__attribute__((noescape)) int *p) { + *p += 100; // OK. + } + + void escapingFunc(__attribute__((noescape)) int *p) { + gp = p; // Not OK. + } + +Additionally, when the parameter is a `block pointer +<https://clang.llvm.org/docs/BlockLanguageSpec.html>`, the same restriction +applies to copies of the block. For example: + + typedef void (^BlockTy)(); + BlockTy g0, g1; + + void nonescapingFunc(__attribute__((noescape)) BlockTy block) { + block(); // OK. + } + + void escapingFunc(__attribute__((noescape)) BlockTy block) { + g0 = block; // Not OK. + g1 = Block_copy(block); // Not OK either. + } + + }]; +} + def CarriesDependencyDocs : Documentation { let Category = DocCatFunction; let Content = [{ |