@@ -27,7 +27,7 @@ using namespace CodeGen;
27
27
28
28
CGBlockInfo::CGBlockInfo (const BlockExpr *blockExpr, const char *N)
29
29
: Name(N), CXXThisIndex(0 ), CanBeGlobal(false ), NeedsCopyDispose(false ),
30
- HasCXXObject(false ), StructureType(0 ), Block(blockExpr) {
30
+ HasCXXObject(false ), UsesStret( false ), StructureType(0 ), Block(blockExpr) {
31
31
32
32
// Skip asm prefix, if any.
33
33
if (Name && Name[0 ] == ' \01 ' )
@@ -104,23 +104,6 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM,
104
104
return llvm::ConstantExpr::getBitCast (global, CGM.getBlockDescriptorType ());
105
105
}
106
106
107
- static BlockFlags computeBlockFlag (CodeGenModule &CGM,
108
- const BlockExpr *BE,
109
- BlockFlags flags) {
110
- const FunctionType *ftype = BE->getFunctionType ();
111
-
112
- // This is a bit overboard.
113
- CallArgList args;
114
- const CGFunctionInfo &fnInfo =
115
- CGM.getTypes ().getFunctionInfo (ftype->getResultType (), args,
116
- ftype->getExtInfo ());
117
-
118
- if (CGM.ReturnTypeUsesSRet (fnInfo))
119
- flags |= BLOCK_USE_STRET;
120
-
121
- return flags;
122
- }
123
-
124
107
/*
125
108
Purely notional variadic template describing the layout of a block.
126
109
@@ -536,7 +519,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
536
519
BlockFlags flags = BLOCK_HAS_SIGNATURE;
537
520
if (blockInfo.NeedsCopyDispose ) flags |= BLOCK_HAS_COPY_DISPOSE;
538
521
if (blockInfo.HasCXXObject ) flags |= BLOCK_HAS_CXX_OBJ;
539
- flags = computeBlockFlag (CGM, blockInfo.getBlockExpr (), flags) ;
522
+ if ( blockInfo.UsesStret ) flags |= BLOCK_USE_STRET ;
540
523
541
524
// Initialize the block literal.
542
525
Builder.CreateStore (isa, Builder.CreateStructGEP (blockAddr, 0 , " block.isa" ));
@@ -747,7 +730,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E,
747
730
// Load the function.
748
731
llvm::Value *Func = Builder.CreateLoad (FuncPtr, " tmp" );
749
732
750
- const FunctionType *FuncTy = FnType->getAs <FunctionType>();
733
+ const FunctionType *FuncTy = FnType->castAs <FunctionType>();
751
734
QualType ResultType = FuncTy->getResultType ();
752
735
753
736
const CGFunctionInfo &FnInfo =
@@ -836,8 +819,9 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
836
819
fields[0 ] = CGM.getNSConcreteGlobalBlock ();
837
820
838
821
// __flags
839
- BlockFlags flags = computeBlockFlag (CGM, blockInfo.getBlockExpr (),
840
- BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE);
822
+ BlockFlags flags = BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE;
823
+ if (blockInfo.UsesStret ) flags |= BLOCK_USE_STRET;
824
+
841
825
fields[1 ] = llvm::ConstantInt::get (CGM.IntTy , flags.getBitMask ());
842
826
843
827
// Reserved
@@ -915,6 +899,9 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
915
899
const CGFunctionInfo &fnInfo =
916
900
CGM.getTypes ().getFunctionInfo (fnType->getResultType (), args,
917
901
fnType->getExtInfo ());
902
+ if (CGM.ReturnTypeUsesSRet (fnInfo))
903
+ blockInfo.UsesStret = true ;
904
+
918
905
const llvm::FunctionType *fnLLVMType =
919
906
CGM.getTypes ().GetFunctionType (fnInfo, fnType->isVariadic ());
920
907
0 commit comments