[PATCH] D15907: Allow various function attributes to be specified on Objective-C blocks too.

Nicholas Allegra via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 5 15:08:19 PST 2016


comex created this revision.
comex added a subscriber: cfe-commits.
Herald added a subscriber: aemerson.

This mostly "just works" by adding Block to the subject list, but there is an
issue with warnings in attribute handlers tied to the return type, which for
blocks can be inferred.  My solution to this is a bit ugly but seems to do the
right thing.

The list: always_inline, noinline, cold, hot, minsize, malloc,
disable_tail_calls, noalias, noduplicate, nonnull, returns_nonnull, optnone.

nonnull already partially worked on blocks, but fix applying it to parameters
on them; also, improve the error message and add additional tests.

Most of these attributes only make sense when the target of a function call is
known; since blocks are always called indirectly via pointers, these will only
work if the optimizer is able to replace the indirect calls with direct calls
(ergo not at all at -O0).  However, this can still be useful in practice.

For now, all of them only apply to the block implementation function itself, as
opposed to the copy and dispose helpers.  For those it might make sense to
propagate always_inline in particular, or perhaps to just add some explicit
syntax for putting attributes on them, but it's not essential.

Incidentally, for some of these attributes and some not included, such as
returns_nonnull, printf, warn_unused_result, etc., it would be somewhat useful
and more principled to allow them as part of function types rather than just
functions themselves, for the sake of both standard function pointer calls and
blocks.  Currently only a handful of attributes can be used on types: noreturn,
ns_returns_retained, regparm, and calling convention.  However, that would be a
larger change and orthogonal to this patch.


http://reviews.llvm.org/D15907

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Parse/Parser.h
  include/clang/Sema/AttributeList.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  test/CXX/dcl.dcl/dcl.attr/dcl.attr.depend/p1.cpp
  test/CodeGen/always-inline.c
  test/CodeGen/attr-disable-tail-calls.c
  test/CodeGen/attr-noinline.c
  test/CodeGen/attr-optnone.c
  test/CodeGen/nonnull.c
  test/Parser/cxx0x-attributes.cpp
  test/Sema/attr-capabilities.c
  test/Sema/attr-coldhot.c
  test/Sema/attr-disable-tail-calls.c
  test/Sema/attr-malloc.c
  test/Sema/attr-minsize.c
  test/Sema/attr-noinline.c
  test/Sema/nonnull.c
  test/SemaObjC/attr-cf_returns.m
  test/SemaObjC/objcbridge-attribute-arc.m
  test/SemaObjC/objcbridge-attribute.m
  utils/TableGen/ClangAttrEmitter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15907.44065.patch
Type: text/x-patch
Size: 37749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160105/63109954/attachment-0001.bin>


More information about the cfe-commits mailing list