]> granicus.if.org Git - clang/commitdiff
Don't assume that a block always has a FunctionProtoType. Fixes rdar://6768379.
authorAnders Carlsson <andersca@mac.com>
Wed, 8 Apr 2009 02:55:55 +0000 (02:55 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 8 Apr 2009 02:55:55 +0000 (02:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68583 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGCall.cpp
lib/CodeGen/CodeGenTypes.h
test/CodeGen/blocks.c

index c8d9655951d6aec4009d22d7baa756e47c712799..74b6af1425e471c3b739747dce216d713c1096c9 100644 (file)
@@ -444,13 +444,15 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
   // Load the function.
   llvm::Value *Func = Builder.CreateLoad(FuncPtr, false, "tmp");
 
-  const CGFunctionInfo &FnInfo = CGM.getTypes().getFunctionInfo(BPT);
-  bool IsVariadic = 
-    BPT->getPointeeType()->getAsFunctionProtoType()->isVariadic();
+  QualType FnType = BPT->getPointeeType();
+  QualType ResultType = FnType->getAsFunctionType()->getResultType();
+
+  const CGFunctionInfo &FnInfo = 
+    CGM.getTypes().getFunctionInfo(ResultType, Args);
   
   // Cast the function pointer to the right type.
   const llvm::Type *BlockFTy = 
-    CGM.getTypes().GetFunctionType(FnInfo, IsVariadic);
+    CGM.getTypes().GetFunctionType(FnInfo, false);
   
   const llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
   Func = Builder.CreateBitCast(Func, BlockFTyPtr);
index 43db767158eccd803787850fc875f34176f968d7..e3f824fc7428cddfb78d905b7011a32f3d1922e5 100644 (file)
@@ -53,19 +53,6 @@ CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionProtoType *FTP) {
   return getFunctionInfo(FTP->getResultType(), ArgTys);
 }
 
-const 
-CGFunctionInfo &CodeGenTypes::getFunctionInfo(const BlockPointerType *BPT) {
-  llvm::SmallVector<QualType, 16> ArgTys;
-  const FunctionProtoType *FTP = 
-    BPT->getPointeeType()->getAsFunctionProtoType();
-  
-  // Add the block pointer.
-  ArgTys.push_back(Context.getPointerType(Context.VoidTy));
-  for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
-    ArgTys.push_back(FTP->getArgType(i));
-  return getFunctionInfo(FTP->getResultType(), ArgTys);
-}
-
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXMethodDecl *MD) {
   llvm::SmallVector<QualType, 16> ArgTys;
   // Add the 'this' pointer.
index b09531f5ca3683644d0d826816fcfb8f5ec9de66..a23b8f651a8c25e0a36328a08dd6acc5d669fbfd 100644 (file)
@@ -172,11 +172,9 @@ public:
 
   const CGFunctionInfo &getFunctionInfo(const FunctionNoProtoType *FTNP);
   const CGFunctionInfo &getFunctionInfo(const FunctionProtoType *FTP);
-  const CGFunctionInfo &getFunctionInfo(const BlockPointerType *BPT);
   const CGFunctionInfo &getFunctionInfo(const FunctionDecl *FD);
   const CGFunctionInfo &getFunctionInfo(const CXXMethodDecl *MD);
   const CGFunctionInfo &getFunctionInfo(const ObjCMethodDecl *MD);
-//private:
   const CGFunctionInfo &getFunctionInfo(QualType ResTy, 
                                         const CallArgList &Args);
 public:
index 4dfe553aecb4560c73486be71def8aa15c22de52..3eb4c43505a5831801040cc79c4787409d5dd80a 100644 (file)
@@ -1,2 +1,7 @@
 // RUN: clang-cc %s -emit-llvm -o %t -fblocks
 void (^f)(void) = ^{};
+
+// rdar://6768379
+int f0(int (^a0)()) {
+  return a0(1, 2, 3);
+}