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.
Since you updated ClangAttrEmitter.cpp, you shouldn't need this last argument since it can now be inferred.