[cfe-commits] r53955 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDecl.cpp

Ted Kremenek kremenek at apple.com
Wed Jul 23 11:04:18 PDT 2008


Author: kremenek
Date: Wed Jul 23 13:04:17 2008
New Revision: 53955

URL: http://llvm.org/viewvc/llvm-project?rev=53955&view=rev
Log:
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).

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=53955&r1=53954&r2=53955&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Wed Jul 23 13:04:17 2008
@@ -479,16 +479,21 @@
 ///   }
 ///
 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); }

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=53955&r1=53954&r2=53955&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Wed Jul 23 13:04:17 2008
@@ -87,9 +87,10 @@
 
 
 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,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=53955&r1=53954&r2=53955&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul 23 13:04:17 2008
@@ -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;
 }
 





More information about the cfe-commits mailing list