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

2016-01-14 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

At a high level, is there a reason why these should be supported on block, but 
not on ObjC method declarations? It smells like these may be useful there as 
well, which could also simplify the patch slightly.



Comment at: include/clang/Basic/Attr.td:992
@@ -993,1 +991,3 @@
+  let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar],
+ WarnDiag, 
"ExpectedFunctionMethodParameterOrBlock">;
   let Args = [VariadicUnsignedArgument<"Args">];

Since you updated ClangAttrEmitter.cpp, you shouldn't need this last argument 
since it can now be inferred.


Comment at: lib/Parse/ParseExpr.cpp:2679
@@ -2678,3 +2678,1 @@
 
-/// ParseBlockId - Parse a block-id, which roughly looks like int (int x).
-///

This (and its related changes) look good to me, but should be in a separate 
patch since they are orthogonal to the rest of the changes in this patch.


Comment at: lib/Sema/SemaDeclAttr.cpp:1282
@@ -1279,1 +1281,3 @@
+ const AttributeList ,
+ QualType ResultType) {
   SourceRange SR = getFunctionOrMethodResultSourceRange(D);

Please do not add any parameters to these function signatures. We try to keep 
them uniform in the hopes that maybe someday we can refactor this code to do 
dispatch more easily. (It's fine to add an extra level of indirection through a 
helper function that then has the additional parameter.)


Comment at: lib/Sema/SemaDeclAttr.cpp:5654
@@ -5644,1 +5653,3 @@
+void Sema::ProcessDeclAttributes(Scope *S, Decl *D, const Declarator ,
+ QualType *OverrideRetType) {
   // Apply decl attributes from the DeclSpec if present.

This doesn't seem like the correct way to solve the problem -- everyone who 
calls ProcessDeclAttributes should not have to understand what an overridden 
return type is for objective-c blocks. I'm not certain of a better way to solve 
it right now, but I would rather see the changes for this one split out into 
its own patch so we can make progress on the other improvements.


http://reviews.llvm.org/D15907



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-01-13 Thread Nicholas Allegra via cfe-commits
comex added reviewers: aaron.ballman, rsmith.
comex added a comment.

Ping, and adding potential reviewers like I was supposed to do in the first 
place.


http://reviews.llvm.org/D15907



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-01-05 Thread Nicholas Allegra via cfe-commits
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

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -2363,10 +2363,12 @@
 case GenericRecord:
   return "(S.getLangOpts().CPlusPlus ? ExpectedStructOrUnionOrClass : "
"ExpectedStructOrUnion)";
+case Func | Block: return "ExpectedFunctionOrBlock";
 case Func | ObjCMethod | Block: return "ExpectedFunctionMethodOrBlock";
 case Func | ObjCMethod | Class: return "ExpectedFunctionMethodOrClass";
 case Func | Param:
 case Func | ObjCMethod | Param: return "ExpectedFunctionMethodOrParameter";
+case Func | ObjCMethod | Block | Param: return "ExpectedFunctionMethodBlockOrParameter";
 case Func | ObjCMethod: return "ExpectedFunctionOrMethod";
 case Func | Var: return "ExpectedVariableOrFunction";
 
Index: test/SemaObjC/objcbridge-attribute.m
===
--- test/SemaObjC/objcbridge-attribute.m
+++ test/SemaObjC/objcbridge-attribute.m
@@ -38,7 +38,7 @@
 
 @interface I
 {
-   __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to structs, unions, and typedefs}};
+   __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to structs, unions and typedefs}};
 }
 @end
 
Index: test/SemaObjC/objcbridge-attribute-arc.m
===
--- test/SemaObjC/objcbridge-attribute-arc.m
+++ test/SemaObjC/objcbridge-attribute-arc.m
@@ -32,7 +32,7 @@
 
 @interface I
 {
-   __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to structs, unions, and typedefs}};
+   __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to structs, unions and typedefs}};
 }
 @end
 
Index: test/SemaObjC/attr-cf_returns.m
===
--- test/SemaObjC/attr-cf_returns.m
+++ test/SemaObjC/attr-cf_returns.m
@@ -10,8 +10,8 @@
 #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
 #define CF_RETURNS_NOT_RETAINED