diff options
Diffstat (limited to 'clang/lib/CodeGen/CGObjCMac.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGObjCMac.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index f558412f716..ebbd7007c14 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -1442,11 +1442,10 @@ private: bool ImplementationIsNonLazy(const ObjCImplDecl *OD) const; bool IsIvarOffsetKnownIdempotent(const CodeGen::CodeGenFunction &CGF, - const ObjCInterfaceDecl *ID, const ObjCIvarDecl *IV) { - // Annotate the load as an invariant load iff the object type is the type, - // or a derived type, of the class containing the ivar within an ObjC - // method. This check is needed because the ivar offset is a lazily + // Annotate the load as an invariant load iff inside an instance method + // and ivar belongs to instance method's class and one of its super class. + // This check is needed because the ivar offset is a lazily // initialised value that may depend on objc_msgSend to perform a fixup on // the first message dispatch. // @@ -1454,9 +1453,12 @@ private: // base of the ivar access is a parameter to an Objective C method. // However, because the parameters are not available in the current // interface, we cannot perform this check. - if (CGF.CurFuncDecl && isa<ObjCMethodDecl>(CGF.CurFuncDecl)) - if (IV->getContainingInterface()->isSuperClassOf(ID)) - return true; + if (const ObjCMethodDecl *MD = + dyn_cast_or_null<ObjCMethodDecl>(CGF.CurFuncDecl)) + if (MD->isInstanceMethod() && + !isa<ObjCProtocolDecl>(MD->getDeclContext())) + if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) + return IV->getContainingInterface()->isSuperClassOf(ID); return false; } @@ -6479,7 +6481,7 @@ LValue CGObjCNonFragileABIMac::EmitObjCValueForIvar( ObjCInterfaceDecl *ID = ObjectTy->getAs<ObjCObjectType>()->getInterface(); llvm::Value *Offset = EmitIvarOffset(CGF, ID, Ivar); - if (IsIvarOffsetKnownIdempotent(CGF, ID, Ivar)) + if (IsIvarOffsetKnownIdempotent(CGF, Ivar)) if (llvm::LoadInst *LI = cast<llvm::LoadInst>(Offset)) LI->setMetadata(CGM.getModule().getMDKindID("invariant.load"), llvm::MDNode::get(VMContext, ArrayRef<llvm::Value*>())); |