Fixes an obscure bug in importd block variable layout

information when imported variable is used
more than once. Originally though to be a bug in importing
block varibles. Fixes radar 8417746.

llvm-svn: 113675
This commit is contained in:
Fariborz Jahanian 2010-09-11 01:27:29 +00:00
parent 8f22a243b7
commit 933c6723a4
5 changed files with 31 additions and 8 deletions

View File

@ -757,7 +757,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, const BlockExpr *BExpr,
// Capture block layout info. here.
if (CGM.getContext().getLangOptions().ObjC1)
BlockVarLayout = CGM.getObjCRuntime().GCBlockLayout(*this, Info.DeclRefs);
BlockVarLayout = CGM.getObjCRuntime().GCBlockLayout(*this, BlockLayout);
else
BlockVarLayout = llvm::Constant::getNullValue(PtrToInt8Ty);

View File

@ -213,7 +213,7 @@ public:
const ObjCInterfaceDecl *Interface,
const ObjCIvarDecl *Ivar);
virtual llvm::Constant *GCBlockLayout(CodeGen::CodeGenFunction &CGF,
const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &) {
const llvm::SmallVectorImpl<const Expr *> &) {
return NULLPtr;
}
};

View File

@ -1000,7 +1000,7 @@ public:
/// definition is seen. The return value has type ProtocolPtrTy.
virtual llvm::Constant *GetOrEmitProtocolRef(const ObjCProtocolDecl *PD)=0;
virtual llvm::Constant *GCBlockLayout(CodeGen::CodeGenFunction &CGF,
const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &);
const llvm::SmallVectorImpl<const Expr *> &);
};
@ -1663,11 +1663,11 @@ static Qualifiers::GC GetGCAttrTypeForType(ASTContext &Ctx, QualType FQT) {
}
llvm::Constant *CGObjCCommonMac::GCBlockLayout(CodeGen::CodeGenFunction &CGF,
const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &DeclRefs) {
const llvm::SmallVectorImpl<const Expr *> &BlockLayout) {
llvm::Constant *NullPtr =
llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
if ((CGM.getLangOptions().getGCMode() == LangOptions::NonGC) ||
DeclRefs.empty())
BlockLayout.empty())
return NullPtr;
bool hasUnion = false;
SkipIvars.clear();
@ -1678,8 +1678,11 @@ llvm::Constant *CGObjCCommonMac::GCBlockLayout(CodeGen::CodeGenFunction &CGF,
// __isa is the first field in block descriptor and must assume by runtime's
// convention that it is GC'able.
IvarsInfo.push_back(GC_IVAR(0, 1));
for (size_t i = 0; i < DeclRefs.size(); ++i) {
const BlockDeclRefExpr *BDRE = DeclRefs[i];
for (size_t i = 0; i < BlockLayout.size(); ++i) {
const Expr *E = BlockLayout[i];
const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E);
if (!BDRE)
continue;
const ValueDecl *VD = BDRE->getDecl();
CharUnits Offset = CGF.BlockDecls[VD];
uint64_t FieldOffset = Offset.getQuantity();

View File

@ -220,7 +220,7 @@ public:
llvm::Value *SrcPtr,
llvm::Value *Size) = 0;
virtual llvm::Constant *GCBlockLayout(CodeGen::CodeGenFunction &CGF,
const llvm::SmallVectorImpl<const BlockDeclRefExpr *> &) = 0;
const llvm::SmallVectorImpl<const Expr *> &) = 0;
};

View File

@ -107,6 +107,23 @@ c();
}
// rdar: //8417746
void CFRelease(id);
void notifyBlock(id dependentBlock) {
id singleObservationToken;
id token;
void (^b)();
void (^wrapperBlock)() = ^() {
CFRelease(singleObservationToken);
CFRelease(singleObservationToken);
CFRelease(token);
CFRelease(singleObservationToken);
b();
};
wrapperBlock();
}
// CHECK-LP64: L_OBJC_CLASS_NAME_:
// CHECK-LP64-NEXT: .asciz "\0011\024"
@ -121,3 +138,6 @@ c();
// CHECK-LP64: L_OBJC_CLASS_NAME_14:
// CHECK-LP64-NEXT: .asciz "\001A\021\022p"
// CHECK-LP64: L_OBJC_CLASS_NAME_16:
// CHECK-LP64-NEXT: .asciz "\0013"