diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2010-07-28 19:07:18 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-07-28 19:07:18 +0000 |
| commit | d5010898ab66a638a7f7e427380a8b419e34561c (patch) | |
| tree | dae2e46ec880a8ae5c4b8fea5786121057f79c6a | |
| parent | 45bd34a104eb9e421d3fcc5518fb9d16fdc4ac52 (diff) | |
| download | bcm5719-llvm-d5010898ab66a638a7f7e427380a8b419e34561c.tar.gz bcm5719-llvm-d5010898ab66a638a7f7e427380a8b419e34561c.zip | |
Fix flags in global block descriptor when
block returns structs. Fies radar 8241648.
Executable test added to llvm test suite.
llvm-svn: 109620
| -rw-r--r-- | clang/lib/CodeGen/CGBlocks.cpp | 37 | ||||
| -rw-r--r-- | clang/test/CodeGen/blockstret.c | 4 |
2 files changed, 24 insertions, 17 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index f38c04bcc43..94ba269aecb 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -184,6 +184,21 @@ static void AllocateAllBlockDeclRefs(CodeGenFunction &CGF, CGBlockInfo &Info) { } } +static unsigned computeBlockFlag(CodeGenModule &CGM, + const BlockExpr *BE, unsigned flags) { + QualType BPT = BE->getType(); + const FunctionType *ftype = BPT->getPointeeType()->getAs<FunctionType>(); + QualType ResultType = ftype->getResultType(); + + CallArgList Args; + CodeGenTypes &Types = CGM.getTypes(); + const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, Args, + FunctionType::ExtInfo()); + if (CGM.ReturnTypeUsesSRet(FnInfo)) + flags |= CodeGenFunction::BLOCK_USE_STRET; + return flags; +} + // FIXME: Push most into CGM, passing down a few bits, like current function // name. llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) { @@ -230,18 +245,7 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) { Elts[0] = C; // __flags - { - QualType BPT = BE->getType(); - const FunctionType *ftype = BPT->getPointeeType()->getAs<FunctionType>(); - QualType ResultType = ftype->getResultType(); - - CallArgList Args; - CodeGenTypes &Types = CGM.getTypes(); - const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, Args, - FunctionType::ExtInfo()); - if (CGM.ReturnTypeUsesSRet(FnInfo)) - flags |= BLOCK_USE_STRET; - } + flags = computeBlockFlag(CGM, BE, flags); const llvm::IntegerType *IntTy = cast<llvm::IntegerType>( CGM.getTypes().ConvertType(CGM.getContext().IntTy)); C = llvm::ConstantInt::get(IntTy, flags); @@ -681,16 +685,19 @@ BlockModule::GetAddrOfGlobalBlock(const BlockExpr *BE, const char * n) { CGBlockInfo Info(n); llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; llvm::Function *Fn - = CodeGenFunction(CGM).GenerateBlockFunction(GlobalDecl(), BE, Info, 0, LocalDeclMap); + = CodeGenFunction(CGM).GenerateBlockFunction(GlobalDecl(), BE, + Info, 0, LocalDeclMap); assert(Info.BlockSize == BlockLiteralSize && "no imports allowed for global block"); // isa LiteralFields[0] = CGM.getNSConcreteGlobalBlock(); - // Flags + // __flags + unsigned flags = computeBlockFlag(CGM, BE, + (BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE)); LiteralFields[1] = - llvm::ConstantInt::get(IntTy, BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE); + llvm::ConstantInt::get(IntTy, flags); // Reserved LiteralFields[2] = llvm::Constant::getNullValue(IntTy); diff --git a/clang/test/CodeGen/blockstret.c b/clang/test/CodeGen/blockstret.c index 09292b809f5..f630f22b167 100644 --- a/clang/test/CodeGen/blockstret.c +++ b/clang/test/CodeGen/blockstret.c @@ -98,8 +98,8 @@ int main(int argc, char *argv[]) { /* desired global flags: 1879048192 desired stack flags: 1610612736 -should be non-zero: 0 -should be non-zero: 0 +should be non-zero: 1 +should be non-zero: 1 should be non-zero: 1 should be zero: 0 |

