]> granicus.if.org Git - clang/commitdiff
Fixed visibility issues related to objc2's synthesized
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 6 Apr 2009 18:30:00 +0000 (18:30 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 6 Apr 2009 18:30:00 +0000 (18:30 +0000)
ivars.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68453 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCMac.cpp
lib/Sema/SemaDeclObjC.cpp
test/CodeGenObjC/hidden-synthesized-ivar.m [new file with mode: 0644]

index a354ef7fa09670fdd9dbf9c24fa064779d18858b..426ad8c0f5f0a229484b2b236ee4bf616519109d 100644 (file)
@@ -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;
index 80d46bcabbed5ee60a662bce99df7de373862496..0103393ddc684ee6e9d28ace02e53cf19ab664d2 100644 (file)
@@ -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/test/CodeGenObjC/hidden-synthesized-ivar.m b/test/CodeGenObjC/hidden-synthesized-ivar.m
new file mode 100644 (file)
index 0000000..50a87cb
--- /dev/null
@@ -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
+