]> granicus.if.org Git - clang/commitdiff
Fix flags in global block descriptor when
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 28 Jul 2010 19:07:18 +0000 (19:07 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 28 Jul 2010 19:07:18 +0000 (19:07 +0000)
block returns structs. Fies radar 8241648.
Executable test added to llvm test suite.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109620 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
test/CodeGen/blockstret.c

index f38c04bcc43031eb660dcbee8ceeed33017ed9f6..94ba269aecb49f0d831616e79e0f6033df76f468 100644 (file)
@@ -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);
index 09292b809f5ab1eb07e2981a9412e672db0a2ca2..f630f22b167612fc762ac5ef0230637dcad2c1ba 100644 (file)
@@ -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