]> granicus.if.org Git - clang/commitdiff
When constructing an ObjCIvarDecl object in Sema, provide its visibility up front...
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Jul 2008 18:04:17 +0000 (18:04 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Jul 2008 18:04:17 +0000 (18:04 +0000)
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

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Sema/SemaDecl.cpp

index 264a84035db8ba5e60a8c7ee3576bf26d00632bf..9267bde14a6eacf740d170a9bb73efa98d36cb09 100644 (file)
@@ -479,16 +479,21 @@ public:
 ///   }
 ///
 class ObjCIvarDecl : public FieldDecl {
-  ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Expr *BW)
-    : FieldDecl(ObjCIvar, L, Id, T, BW) {}
 public:
-  static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L,
-                              IdentifierInfo *Id, QualType T, Expr *BW = NULL);
-  
   enum AccessControl {
     None, Private, Protected, Public, Package
   };
   
+private:
+  ObjCIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T,
+               AccessControl ac, Expr *BW)
+    : FieldDecl(ObjCIvar, L, Id, T, BW) {}
+  
+public:
+  static ObjCIvarDecl *Create(ASTContext &C, SourceLocation L,
+                              IdentifierInfo *Id, QualType T,
+                              AccessControl ac, Expr *BW = NULL);
+    
   void setAccessControl(AccessControl ac) { DeclAccess = ac; }
 
   AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
index 4b798474f626df2bca434222a5f380b96311b27d..9ba6e86cf097705d761415309873a45fad6b6211 100644 (file)
@@ -87,9 +87,10 @@ void ObjCInterfaceDecl::Destroy(ASTContext& C) {
 
 
 ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L,
-                                   IdentifierInfo *Id, QualType T, Expr *BW) {
+                                   IdentifierInfo *Id, QualType T, 
+                                   AccessControl ac, Expr *BW) {
   void *Mem = C.getAllocator().Allocate<ObjCIvarDecl>();
-  return new (Mem) ObjCIvarDecl(L, Id, T, BW);
+  return new (Mem) ObjCIvarDecl(L, Id, T, ac, BW);
 }
 
 ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C,
index 7753a757961de0a0f1188e4c3bcd9ba9a5756597..25d4ad5751b4faee6911c550f21a07fac8f56368 100644 (file)
@@ -1947,16 +1947,21 @@ Sema::DeclTy *Sema::ActOnIvar(Scope *S,
     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;
 }