From bc3c77b8818893eac8701101fdc7c89b8bbf0b7f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 6 Apr 2009 18:30:00 +0000 Subject: [PATCH] Fixed visibility issues related to objc2's synthesized ivars. llvm-svn: 68453 --- clang/lib/CodeGen/CGObjCMac.cpp | 37 +++++++++---------- clang/lib/Sema/SemaDeclObjC.cpp | 2 +- .../CodeGenObjC/hidden-synthesized-ivar.m | 13 +++++++ 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 clang/test/CodeGenObjC/hidden-synthesized-ivar.m diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index a354ef7fa096..426ad8c0f5f0 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -4493,37 +4493,34 @@ llvm::Constant * CGObjCNonFragileABIMac::EmitIvarOffsetVar( std::string ExternalName("\01_OBJC_IVAR_$_" + ID->getNameAsString() + '.' + Ivar->getNameAsString()); llvm::Constant *Init = llvm::ConstantInt::get(ObjCTypes.LongTy, Offset); - llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(ExternalName); - if (IvarOffsetGV) { + if (IvarOffsetGV) // ivar offset symbol already built due to user code referencing it. - IvarOffsetGV->setAlignment( - CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.LongTy)); IvarOffsetGV->setInitializer(Init); - IvarOffsetGV->setSection("__DATA, __objc_const"); - UsedGlobals.push_back(IvarOffsetGV); - return IvarOffsetGV; - } - - IvarOffsetGV = - new llvm::GlobalVariable(Init->getType(), - false, - llvm::GlobalValue::ExternalLinkage, - Init, - ExternalName, - &CGM.getModule()); + else + IvarOffsetGV = + new llvm::GlobalVariable(Init->getType(), + false, + llvm::GlobalValue::ExternalLinkage, + Init, + ExternalName, + &CGM.getModule()); IvarOffsetGV->setAlignment( CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.LongTy)); // @private and @package have hidden visibility. bool globalVisibility = (Ivar->getAccessControl() == ObjCIvarDecl::Public || - Ivar->getAccessControl() == ObjCIvarDecl::Protected); + Ivar->getAccessControl() == ObjCIvarDecl::Protected); if (!globalVisibility) IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility); - else - if (IsClassHidden(ID)) + else if (IsClassHidden(ID)) IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility); - + else if (CGM.getLangOptions().getVisibilityMode() == + LangOptions::HiddenVisibility) + IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility); + else if (CGM.getLangOptions().getVisibilityMode() == + LangOptions::DefaultVisibility) + IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility); IvarOffsetGV->setSection("__DATA, __objc_const"); UsedGlobals.push_back(IvarOffsetGV); return IvarOffsetGV; diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 80d46bcabbed..0103393ddc68 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1795,7 +1795,7 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, if (getLangOptions().ObjCNonFragileABI) { Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc, PropertyIvar, PropType, - ObjCIvarDecl::Private, + ObjCIvarDecl::Public, (Expr *)0); property->setPropertyIvarDecl(Ivar); } diff --git a/clang/test/CodeGenObjC/hidden-synthesized-ivar.m b/clang/test/CodeGenObjC/hidden-synthesized-ivar.m new file mode 100644 index 000000000000..50a87cb2f453 --- /dev/null +++ b/clang/test/CodeGenObjC/hidden-synthesized-ivar.m @@ -0,0 +1,13 @@ +// RUN: clang-cc -fvisibility=hidden -triple x86_64-apple-darwin10 -S -o - %s | grep -e "private_extern _OBJC_IVAR_" +@interface I +{ + int P; +} + +@property int P; +@end + +@implementation I +@synthesize P; +@end +