diff options
author | John McCall <rjmccall@apple.com> | 2013-03-27 00:03:48 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2013-03-27 00:03:48 +0000 |
commit | fdb468fc8ab84af5f32868cc6511cf1160074d53 (patch) | |
tree | 610a0b3436dc17922bbc1c7d4b1293558075472e /lib/Sema/SemaCast.cpp | |
parent | 8b43d2b0ea2d72b53a10f38903b176e58cb93b9c (diff) |
Make the -Wreinterpret-base-class logic safe against invalid
declarations at any point. Patch by Alexander Zinenko, and
report by Richard Smith.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178098 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaCast.cpp')
-rw-r--r-- | lib/Sema/SemaCast.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index 1dbc9aaca5..0e19adfd28 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -695,14 +695,15 @@ static void DiagnoseReinterpretUpDownCast(Sema &Self, const Expr *SrcExpr, const CXXRecordDecl *SrcRD = SrcPointeeRD ? SrcPointeeRD : SrcType->getAsCXXRecordDecl(); - // Examining subobjects for records is only possible if the complete - // definition is available. Also, template instantiation is not allowed here. - if(!SrcRD || !SrcRD->isCompleteDefinition()) + // Examining subobjects for records is only possible if the complete and + // valid definition is available. Also, template instantiation is not + // allowed here. + if (!SrcRD || !SrcRD->isCompleteDefinition() || SrcRD->isInvalidDecl()) return; const CXXRecordDecl *DestRD = DestType->getPointeeCXXRecordDecl(); - if(!DestRD || !DestRD->isCompleteDefinition()) + if (!DestRD || !DestRD->isCompleteDefinition() || DestRD->isInvalidDecl()) return; enum { @@ -721,7 +722,7 @@ static void DiagnoseReinterpretUpDownCast(Sema &Self, const Expr *SrcExpr, bool VirtualBase = true; bool NonZeroOffset = false; - for (CXXBasePaths::const_paths_iterator I = BasePaths.begin(), + for (CXXBasePaths::const_paths_iterator I = BasePaths.begin(), E = BasePaths.end(); I != E; ++I) { const CXXBasePath &Path = *I; @@ -734,8 +735,16 @@ static void DiagnoseReinterpretUpDownCast(Sema &Self, const Expr *SrcExpr, break; const CXXRecordDecl *BaseRD = IElem->Base->getType()->getAsCXXRecordDecl(); assert(BaseRD && "Base type should be a valid unqualified class type"); + // Don't check if any base has invalid declaration or has no definition + // since it has no layout info. + const CXXRecordDecl *Class = IElem->Class, + *ClassDefinition = Class->getDefinition(); + if (Class->isInvalidDecl() || !ClassDefinition || + !ClassDefinition->isCompleteDefinition()) + return; + const ASTRecordLayout &DerivedLayout = - Self.Context.getASTRecordLayout(IElem->Class); + Self.Context.getASTRecordLayout(Class); Offset += DerivedLayout.getBaseClassOffset(BaseRD); } if (!IsVirtual) { |