diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-04-11 17:55:15 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-04-11 17:55:15 +0000 |
commit | 140fb26e747a1ba728287f02d585d0bb65d5d0da (patch) | |
tree | 76a197600594f4bb178d8bf9bbe18206aa7ed9a0 /lib/CodeGen/CGBlocks.cpp | |
parent | 73f35e60966855da052e61d8ee141b879351ffcb (diff) |
Fixes a ir-gen crash for K&R style blocks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68865 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGBlocks.cpp')
-rw-r--r-- | lib/CodeGen/CGBlocks.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 4e9419ed20..d705af1b33 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -623,8 +623,19 @@ CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr, .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 @@ CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr, 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()); |