When constructing an ObjCIvarDecl object in Sema, provide its visibility up front instead of setting it afterwards.
This change also fixes a subtle bug where the access control of an ivar would be initialized to garbage if we didn't have an explicit visibility specifier (e.g., @private).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53955 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7753a75..25d4ad5 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1947,16 +1947,21 @@
     InvalidDecl = true;
   }
   
-  ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T,
+  // Get the visibility (access control) for this ivar.
+  ObjCIvarDecl::AccessControl ac = 
+    Visibility != tok::objc_not_keyword ? TranslateIvarVisibility(Visibility)
+                                        : ObjCIvarDecl::None;
+
+  // Construct the decl.
+  ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, Loc, II, T, ac,                                             
                                              (Expr *)BitfieldWidth);
   
+  // Process attributes attached to the ivar.
   ProcessDeclAttributes(NewID, D);
   
   if (D.getInvalidType() || InvalidDecl)
     NewID->setInvalidDecl();
-  // If we have visibility info, make sure the AST is set accordingly.
-  if (Visibility != tok::objc_not_keyword)
-    NewID->setAccessControl(TranslateIvarVisibility(Visibility));
+
   return NewID;
 }