[cfe-commits] r68875 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaObjC/blocks.m

Chris Lattner sabre at nondot.org
Sat Apr 11 12:27:54 PDT 2009


Author: lattner
Date: Sat Apr 11 14:27:54 2009
New Revision: 68875

URL: http://llvm.org/viewvc/llvm-project?rev=68875&view=rev
Log:
fix blocks to reject objc interfaces returned by value.  Also,
a block without a prototype should still coerce a return in it to
use the declared return type.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/blocks.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=68875&r1=68874&r2=68875&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Apr 11 14:27:54 2009
@@ -4655,11 +4655,18 @@
 
     CurBlock->hasPrototype = true;
     CurBlock->isVariadic = false;
-    Type *RetTy = T.getTypePtr()->getAsFunctionType()->getResultType()
-      .getTypePtr();
+    
+    QualType RetTy = T.getTypePtr()->getAsFunctionType()->getResultType();
+    
+    // Do not allow returning a objc interface by-value.
+    if (RetTy->isObjCInterfaceType()) {
+      Diag(ParamInfo.getSourceRange().getBegin(),
+           diag::err_object_cannot_be_passed_returned_by_value) << 0 << RetTy;
+      return;
+    }
 
     if (!RetTy->isDependentType())
-      CurBlock->ReturnType = RetTy;
+      CurBlock->ReturnType = RetTy.getTypePtr();
     return;
   }
 
@@ -4683,22 +4690,26 @@
     for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
       CurBlock->Params.push_back(FTI.ArgInfo[i].Param.getAs<ParmVarDecl>());
     CurBlock->isVariadic = FTI.isVariadic;
-    QualType T = GetTypeForDeclarator (ParamInfo, CurScope);
-
-    Type* RetTy = T.getTypePtr()->getAsFunctionType()->getResultType()
-      .getTypePtr();
-
-    if (!RetTy->isDependentType())
-      CurBlock->ReturnType = RetTy;
   }
   CurBlock->TheDecl->setParams(Context, &CurBlock->Params[0], 
-                                        CurBlock->Params.size());
+                               CurBlock->Params.size());
 
   for (BlockDecl::param_iterator AI = CurBlock->TheDecl->param_begin(),
        E = CurBlock->TheDecl->param_end(); AI != E; ++AI)
     // If this has an identifier, add it to the scope stack.
     if ((*AI)->getIdentifier())
       PushOnScopeChains(*AI, CurBlock->TheScope);
+
+  // Analyze the return type.
+  QualType T = GetTypeForDeclarator(ParamInfo, CurScope);
+  QualType RetTy = T->getAsFunctionType()->getResultType();
+  
+  // Do not allow returning a objc interface by-value.
+  if (RetTy->isObjCInterfaceType()) {
+    Diag(ParamInfo.getSourceRange().getBegin(),
+         diag::err_object_cannot_be_passed_returned_by_value) << 0 << RetTy;
+  } else if (!RetTy->isDependentType())
+    CurBlock->ReturnType = RetTy.getTypePtr();
 }
 
 /// ActOnBlockError - If there is an error parsing a block, this callback

Modified: cfe/trunk/test/SemaObjC/blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/blocks.m?rev=68875&r1=68874&r2=68875&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/blocks.m (original)
+++ cfe/trunk/test/SemaObjC/blocks.m Sat Apr 11 14:27:54 2009
@@ -40,4 +40,7 @@
 
 void foo8() {
   void *P = ^(itf x) {};  // expected-error {{Objective-C interface type 'itf' cannot be passed by value}}
+  P = ^itf(int x) {};     // expected-error {{Objective-C interface type 'itf' cannot be returned by value}}
+  P = ^itf() {};          // expected-error {{Objective-C interface type 'itf' cannot be returned by value}}
+  P = ^itf{};             // expected-error {{Objective-C interface type 'itf' cannot be returned by value}}
 }





More information about the cfe-commits mailing list