From: John McCall Date: Tue, 2 Feb 2010 09:10:11 +0000 (+0000) Subject: Mark dtors for parameter variables and eliminate some redundant type munging. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68c6c9a21e2d9d587477e07522fe55769d3aa26a;p=clang 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 e49ce73319..d971b9caeb 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1932,7 +1932,7 @@ public: /// 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 @@ public: 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 98beb610a5..9e1ab8cefd 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -306,16 +306,11 @@ bool Sema::CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, 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(); - if (!Record) - return false; - - CXXRecordDecl *NamingClass = cast(Record->getDecl()); + CXXRecordDecl *NamingClass = cast(RT->getDecl()); CXXDestructorDecl *Dtor = NamingClass->getDestructor(Context); AccessSpecifier Access = Dtor->getAccess(); diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 0d9918f6e4..cb0e5fb218 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -2638,8 +2638,9 @@ bool Sema::CheckParmsForFunctionDef(FunctionDecl *FD) { } } - if (getLangOptions().AccessControl) - CheckDestructorAccess(Param->getLocation(), Param->getType()); + if (getLangOptions().CPlusPlus) + if (const RecordType *RT = Param->getType()->getAs()) + FinalizeVarWithDestructor(Param, RT); } return HasInvalidParm; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 3798aaa5d1..ea1f2f2bf5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3575,8 +3575,8 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { 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()) + FinalizeVarWithDestructor(VDecl, Record); } return; @@ -3667,7 +3667,7 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl, else { Var->setInit(Context, MaybeCreateCXXExprWithTemporaries(Init.takeAs())); - FinalizeVarWithDestructor(Var, InitType); + FinalizeVarWithDestructor(Var, InitType->getAs()); } } else { Var->setInvalidDecl(); diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 931c058670..4552d544b9 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -3982,13 +3982,12 @@ bool Sema::InitializeVarWithConstructor(VarDecl *VD, return false; } -void Sema::FinalizeVarWithDestructor(VarDecl *VD, QualType DeclInitType) { - CXXRecordDecl *ClassDecl = cast( - DeclInitType->getAs()->getDecl()); +void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) { + CXXRecordDecl *ClassDecl = cast(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 @@ void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl, VDecl->setInit(Context, Result.takeAs()); VDecl->setCXXDirectInitializer(true); - if (VDecl->getType()->getAs()) - FinalizeVarWithDestructor(VDecl, DeclInitType); + if (const RecordType *Record = VDecl->getType()->getAs()) + FinalizeVarWithDestructor(VDecl, Record); } /// \brief Add the applicable constructor candidates for an initialization