Author: arphaman
Date: Wed Nov  8 14:44:34 2017
New Revision: 317736

URL: http://llvm.org/viewvc/llvm-project?rev=317736&view=rev
Log:
[ObjC] Fix function signature handling for blocks literals with attributes

Block literals can have a type with attributes in its signature, e.g.
ns_returns_retained. The code that inspected the type loc of the block when
declaring its parameters didn't account for this fact, and only looked through
paren type loc. This commit ensures that getAsAdjusted is used instead of
IgnoreParens to find the block's FunctionProtoTypeLoc. This ensures that
block parameters are declared correctly in the block and avoids the
'undeclared identifier' error.

rdar://35416160

Added:
    cfe/trunk/test/SemaObjC/block-literal-with-attribute.m
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=317736&r1=317735&r2=317736&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Nov  8 14:44:34 2017
@@ -12859,8 +12859,8 @@ void Sema::ActOnBlockArguments(SourceLoc
   // Look for an explicit signature in that function type.
   FunctionProtoTypeLoc ExplicitSignature;
 
-  TypeLoc tmp = Sig->getTypeLoc().IgnoreParens();
-  if ((ExplicitSignature = tmp.getAs<FunctionProtoTypeLoc>())) {
+  if ((ExplicitSignature =
+           Sig->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>())) {
 
     // Check whether that explicit signature was synthesized by
     // GetTypeForDeclarator.  If so, don't save that as part of the

Added: cfe/trunk/test/SemaObjC/block-literal-with-attribute.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/block-literal-with-attribute.m?rev=317736&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/block-literal-with-attribute.m (added)
+++ cfe/trunk/test/SemaObjC/block-literal-with-attribute.m Wed Nov  8 14:44:34 
2017
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks -fobjc-arc
+// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
+// FIXME: should compile
+
+__auto_type block = ^ id __attribute__((ns_returns_retained)) (id filter) {
+  return filter; // ok
+};
+__auto_type block2 = ^  __attribute__((ns_returns_retained)) id (id filter) {
+  return filter; // ok
+};
+__auto_type block3 = ^ id (id filter)  __attribute__((ns_returns_retained))  {
+  return filter; // ok
+};
+
+// expected-no-diagnostics


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

Reply via email to