================ @@ -1699,11 +1699,18 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { llvm::Value *EmitIvarOffset(CodeGenFunction &CGF, const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar) override { - const std::string Name = GetIVarOffsetVariableName(Ivar->getContainingInterface(), Ivar); + const ObjCInterfaceDecl *ContainingInterface = + Ivar->getContainingInterface(); + const std::string Name = + GetIVarOffsetVariableName(ContainingInterface, Ivar); llvm::GlobalVariable *IvarOffsetPointer = TheModule.getNamedGlobal(Name); - if (!IvarOffsetPointer) + if (!IvarOffsetPointer) { IvarOffsetPointer = new llvm::GlobalVariable(TheModule, IntTy, false, llvm::GlobalValue::ExternalLinkage, nullptr, Name); + if (Ivar->getAccessControl() != ObjCIvarDecl::Private && + Ivar->getAccessControl() != ObjCIvarDecl::Package) ---------------- qmfrederik wrote:
It appears to be a pattern in both [this file](https://github.com/llvm/llvm-project/blob/de88d7db7b77141297fbb5638ee1e18d1fba53b8/clang/lib/CodeGen/CGObjCGNU.cpp#L1871-L1876) and in [CGObjCMac.cpp](https://github.com/llvm/llvm-project/blob/de88d7db7b77141297fbb5638ee1e18d1fba53b8/clang/lib/CodeGen/CGObjCMac.cpp#L6842-L6844) to consider an ivar hidden if the visibility is `ObjCIvarDecl::Private` and `ObjCIvarDecl::Package` and visible otherwise. In Objective C, [a scoping directive applies to all the instance variables listed after it, up to the next directive or the end of the list and unmarked instance variables are `@protected`](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocDefiningClasses.html). So I don't think we'd ever a hit case where `getAccessControl()` would return `ObjCIvarDecl::None`. So I left it like this for the sake of consistency, but I'm not particularly wed to that opinion -- let me know if you prefer me to make the change! https://github.com/llvm/llvm-project/pull/107604 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits