[cfe-commits] r95079 - in /cfe/trunk/lib/Sema: Sema.h SemaAccess.cpp SemaChecking.cpp SemaDecl.cpp SemaDeclCXX.cpp

John McCall rjmccall at apple.com
Tue Feb 2 01:10:12 PST 2010


Author: rjmccall
Date: Tue Feb  2 03:10:11 2010
New Revision: 95079

URL: http://llvm.org/viewvc/llvm-project?rev=95079&view=rev
Log:
Mark dtors for parameter variables and eliminate some redundant type munging.


Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaAccess.cpp
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=95079&r1=95078&r2=95079&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Feb  2 03:10:11 2010
@@ -1932,7 +1932,7 @@
 
   /// FinalizeVarWithDestructor - Prepare for calling destructor on the
   /// constructed variable.
-  void FinalizeVarWithDestructor(VarDecl *VD, QualType DeclInitType);
+  void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType);
 
   /// DefineImplicitDefaultConstructor - Checks for feasibility of
   /// defining this constructor as the default constructor.
@@ -2417,7 +2417,7 @@
                                    AccessSpecifier Access);
   bool CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D,
                               AccessSpecifier Access);
-  bool CheckDestructorAccess(SourceLocation Loc, QualType T);
+  bool CheckDestructorAccess(SourceLocation Loc, const RecordType *Record);
   bool CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr,
                                  NamedDecl *D, AccessSpecifier Access);
   bool CheckAccess(const LookupResult &R, NamedDecl *D, AccessSpecifier Access);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Tue Feb  2 03:10:11 2010
@@ -306,16 +306,11 @@
   return false;
 }
 
-bool Sema::CheckDestructorAccess(SourceLocation Loc,
-                                 QualType T) {
+bool Sema::CheckDestructorAccess(SourceLocation Loc, const RecordType *RT) {
   if (!getLangOptions().AccessControl)
     return false;
 
-  const RecordType *Record = T->getAs<RecordType>();
-  if (!Record)
-    return false;
-
-  CXXRecordDecl *NamingClass = cast<CXXRecordDecl>(Record->getDecl());
+  CXXRecordDecl *NamingClass = cast<CXXRecordDecl>(RT->getDecl());
   CXXDestructorDecl *Dtor = NamingClass->getDestructor(Context);
 
   AccessSpecifier Access = Dtor->getAccess();

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Feb  2 03:10:11 2010
@@ -2638,8 +2638,9 @@
       }
     }
 
-    if (getLangOptions().AccessControl)
-      CheckDestructorAccess(Param->getLocation(), Param->getType());
+    if (getLangOptions().CPlusPlus)
+      if (const RecordType *RT = Param->getType()->getAs<RecordType>())
+        FinalizeVarWithDestructor(Param, RT);
   }
 
   return HasInvalidParm;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb  2 03:10:11 2010
@@ -3575,8 +3575,8 @@
     QualType InitType = VDecl->getType();
     while (const ArrayType *Array = Context.getAsArrayType(InitType))
       InitType = Context.getBaseElementType(Array);
-    if (InitType->isRecordType())
-      FinalizeVarWithDestructor(VDecl, InitType);
+    if (const RecordType *Record = InitType->getAs<RecordType>())
+      FinalizeVarWithDestructor(VDecl, Record);
   }
 
   return;
@@ -3667,7 +3667,7 @@
           else {
             Var->setInit(Context, 
                        MaybeCreateCXXExprWithTemporaries(Init.takeAs<Expr>()));
-            FinalizeVarWithDestructor(Var, InitType);
+            FinalizeVarWithDestructor(Var, InitType->getAs<RecordType>());
           }
         } else {
           Var->setInvalidDecl();

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Feb  2 03:10:11 2010
@@ -3982,13 +3982,12 @@
   return false;
 }
 
-void Sema::FinalizeVarWithDestructor(VarDecl *VD, QualType DeclInitType) {
-  CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(
-                                  DeclInitType->getAs<RecordType>()->getDecl());
+void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
+  CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Record->getDecl());
   if (!ClassDecl->hasTrivialDestructor()) {
     CXXDestructorDecl *Destructor = ClassDecl->getDestructor(Context);
     MarkDeclarationReferenced(VD->getLocation(), Destructor);
-    CheckDestructorAccess(VD->getLocation(), VD->getType());
+    CheckDestructorAccess(VD->getLocation(), Record);
   }
 }
 
@@ -4093,8 +4092,8 @@
   VDecl->setInit(Context, Result.takeAs<Expr>());
   VDecl->setCXXDirectInitializer(true);
 
-  if (VDecl->getType()->getAs<RecordType>())
-    FinalizeVarWithDestructor(VDecl, DeclInitType);
+  if (const RecordType *Record = VDecl->getType()->getAs<RecordType>())
+    FinalizeVarWithDestructor(VDecl, Record);
 }
 
 /// \brief Add the applicable constructor candidates for an initialization





More information about the cfe-commits mailing list