Fixed visibility issues related to objc2's synthesized

ivars.

llvm-svn: 68453
This commit is contained in:
Fariborz Jahanian 2009-04-06 18:30:00 +00:00
parent 6f811f149b
commit bc3c77b881
3 changed files with 31 additions and 21 deletions

View File

@ -4493,37 +4493,34 @@ llvm::Constant * CGObjCNonFragileABIMac::EmitIvarOffsetVar(
std::string ExternalName("\01_OBJC_IVAR_$_" + ID->getNameAsString() + '.' std::string ExternalName("\01_OBJC_IVAR_$_" + ID->getNameAsString() + '.'
+ Ivar->getNameAsString()); + Ivar->getNameAsString());
llvm::Constant *Init = llvm::ConstantInt::get(ObjCTypes.LongTy, Offset); llvm::Constant *Init = llvm::ConstantInt::get(ObjCTypes.LongTy, Offset);
llvm::GlobalVariable *IvarOffsetGV = llvm::GlobalVariable *IvarOffsetGV =
CGM.getModule().getGlobalVariable(ExternalName); CGM.getModule().getGlobalVariable(ExternalName);
if (IvarOffsetGV) { if (IvarOffsetGV)
// ivar offset symbol already built due to user code referencing it. // ivar offset symbol already built due to user code referencing it.
IvarOffsetGV->setAlignment(
CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.LongTy));
IvarOffsetGV->setInitializer(Init); IvarOffsetGV->setInitializer(Init);
IvarOffsetGV->setSection("__DATA, __objc_const"); else
UsedGlobals.push_back(IvarOffsetGV); IvarOffsetGV =
return IvarOffsetGV; new llvm::GlobalVariable(Init->getType(),
} false,
llvm::GlobalValue::ExternalLinkage,
IvarOffsetGV = Init,
new llvm::GlobalVariable(Init->getType(), ExternalName,
false, &CGM.getModule());
llvm::GlobalValue::ExternalLinkage,
Init,
ExternalName,
&CGM.getModule());
IvarOffsetGV->setAlignment( IvarOffsetGV->setAlignment(
CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.LongTy)); CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.LongTy));
// @private and @package have hidden visibility. // @private and @package have hidden visibility.
bool globalVisibility = (Ivar->getAccessControl() == ObjCIvarDecl::Public || bool globalVisibility = (Ivar->getAccessControl() == ObjCIvarDecl::Public ||
Ivar->getAccessControl() == ObjCIvarDecl::Protected); Ivar->getAccessControl() == ObjCIvarDecl::Protected);
if (!globalVisibility) if (!globalVisibility)
IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility); IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
else else if (IsClassHidden(ID))
if (IsClassHidden(ID))
IvarOffsetGV->setVisibility(llvm::GlobalValue::HiddenVisibility); 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"); IvarOffsetGV->setSection("__DATA, __objc_const");
UsedGlobals.push_back(IvarOffsetGV); UsedGlobals.push_back(IvarOffsetGV);
return IvarOffsetGV; return IvarOffsetGV;

View File

@ -1795,7 +1795,7 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
if (getLangOptions().ObjCNonFragileABI) { if (getLangOptions().ObjCNonFragileABI) {
Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc, Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc,
PropertyIvar, PropType, PropertyIvar, PropType,
ObjCIvarDecl::Private, ObjCIvarDecl::Public,
(Expr *)0); (Expr *)0);
property->setPropertyIvarDecl(Ivar); property->setPropertyIvarDecl(Ivar);
} }

View File

@ -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