diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-09-11 01:27:29 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-09-11 01:27:29 +0000 |
commit | 933c6723a43f26ff55cfa582a5826fc3c798bc7f (patch) | |
tree | 2b4590dd012f9e2d4dcee5150ee78ca233648c41 | |
parent | 8f22a243b743efee5cf94f5afc8461f70ce00fd2 (diff) | |
download | bcm5719-llvm-933c6723a43f26ff55cfa582a5826fc3c798bc7f.tar.gz bcm5719-llvm-933c6723a43f26ff55cfa582a5826fc3c798bc7f.zip |
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
-rw-r--r-- | clang/lib/CodeGen/CGBlocks.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGObjCGNU.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGObjCMac.cpp | 13 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGObjCRuntime.h | 2 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/block-var-layout.m | 20 |
5 files changed, 31 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 04f1ef24b29..d4e703ce03a 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -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); diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index d7960beb1d1..0b3e31db049 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -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; } }; diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 82541356863..73074b6bbe5 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -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(); diff --git a/clang/lib/CodeGen/CGObjCRuntime.h b/clang/lib/CodeGen/CGObjCRuntime.h index 584760f6f34..c9b0c6d10c7 100644 --- a/clang/lib/CodeGen/CGObjCRuntime.h +++ b/clang/lib/CodeGen/CGObjCRuntime.h @@ -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; }; diff --git a/clang/test/CodeGenObjC/block-var-layout.m b/clang/test/CodeGenObjC/block-var-layout.m index f57d7d99cd5..c2a01d35fe0 100644 --- a/clang/test/CodeGenObjC/block-var-layout.m +++ b/clang/test/CodeGenObjC/block-var-layout.m @@ -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" |