[cfe-commits] r68865 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGen/kr-style-block.c

Fariborz Jahanian fjahanian at apple.com
Sat Apr 11 10:55:16 PDT 2009


Author: fjahanian
Date: Sat Apr 11 12:55:15 2009
New Revision: 68865

URL: http://llvm.org/viewvc/llvm-project?rev=68865&view=rev
Log:
Fixes a ir-gen crash for K&R style blocks.


Added:
    cfe/trunk/test/CodeGen/kr-style-block.c
Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=68865&r1=68864&r2=68865&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sat Apr 11 12:55:15 2009
@@ -623,8 +623,19 @@
       .getTypeStoreSizeInBits(CGM.getGenericExtendedBlockLiteralType()) / 8;
   BlockAlign = getContext().getTypeAlign(getContext().VoidPtrTy) / 8;
 
-  const FunctionProtoType *FTy =
-    cast<FunctionProtoType>(BExpr->getFunctionType());
+  const FunctionType *BlockFunctionType = BExpr->getFunctionType();
+  QualType ResultType;
+  bool IsVariadic;
+  if (!isa<FunctionNoProtoType>(BlockFunctionType)) {
+    const FunctionProtoType *FTy = cast<FunctionProtoType>(BlockFunctionType);
+    ResultType = FTy->getResultType();
+    IsVariadic = FTy->isVariadic();
+  }
+  else {
+    // K&R style block.
+    ResultType = BlockFunctionType->getResultType();
+    IsVariadic = false;
+  }
 
   FunctionArgList Args;
 
@@ -644,18 +655,18 @@
     Args.push_back(std::make_pair(*i, (*i)->getType()));
 
   const CGFunctionInfo &FI =
-    CGM.getTypes().getFunctionInfo(FTy->getResultType(), Args);
+    CGM.getTypes().getFunctionInfo(ResultType, Args);
 
   std::string Name = std::string("__") + Info.Name + "_block_invoke_";
   CodeGenTypes &Types = CGM.getTypes();
-  const llvm::FunctionType *LTy = Types.GetFunctionType(FI, FTy->isVariadic());
+  const llvm::FunctionType *LTy = Types.GetFunctionType(FI, IsVariadic);
 
   llvm::Function *Fn =
     llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
                            Name,
                            &CGM.getModule());
 
-  StartFunction(BD, FTy->getResultType(), Fn, Args,
+  StartFunction(BD, ResultType, Fn, Args,
                 BExpr->getBody()->getLocEnd());
   CurFuncDecl = OuterFuncDecl;
   EmitStmt(BExpr->getBody());

Added: cfe/trunk/test/CodeGen/kr-style-block.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/kr-style-block.c?rev=68865&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/kr-style-block.c (added)
+++ cfe/trunk/test/CodeGen/kr-style-block.c Sat Apr 11 12:55:15 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc -emit-llvm %s -o %t
+
+void foo (void(^)());
+
+int main()
+{
+foo(
+  ^()
+   {
+   }
+);
+}





More information about the cfe-commits mailing list