Mark dtors for parameter variables and eliminate some redundant type munging.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95079 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index e49ce73..d971b9c 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -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);
diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp
index 98beb61..9e1ab8c 100644
--- a/lib/Sema/SemaAccess.cpp
+++ b/lib/Sema/SemaAccess.cpp
@@ -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();
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 0d9918f..cb0e5fb 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -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;
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 3798aaa..ea1f2f2 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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();
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 931c058..4552d54 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -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