From 2883175e4cdf6e86d967433df0284f376fab7579 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 23 Aug 2012 20:46:57 +0000 Subject: Change a bunch of cases where we do "getAs<...>->doSomething()" to "castAs<...>->doSomething()". The analyzer was flagging these as potential null dereferences, which is technically true. The invariants appear to be that these casts should never fail, so let's use castAs<> instead and avoid a runtime check. llvm-svn: 162468 --- clang/lib/AST/CXXInheritance.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'clang/lib/AST/CXXInheritance.cpp') diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp index 247f3753f08..3884e4e8573 100644 --- a/clang/lib/AST/CXXInheritance.cpp +++ b/clang/lib/AST/CXXInheritance.cpp @@ -363,8 +363,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier *Specifier, void *BaseRecord) { assert(((Decl *)BaseRecord)->getCanonicalDecl() == BaseRecord && "User data for FindBaseClass is not canonical!"); - return Specifier->getType()->getAs()->getDecl() - ->getCanonicalDecl() == BaseRecord; + return Specifier->getType()->castAs()->getDecl() + ->getCanonicalDecl() == BaseRecord; } bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, @@ -373,14 +373,15 @@ bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, assert(((Decl *)BaseRecord)->getCanonicalDecl() == BaseRecord && "User data for FindBaseClass is not canonical!"); return Specifier->isVirtual() && - Specifier->getType()->getAs()->getDecl() - ->getCanonicalDecl() == BaseRecord; + Specifier->getType()->castAs()->getDecl() + ->getCanonicalDecl() == BaseRecord; } bool CXXRecordDecl::FindTagMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, void *Name) { - RecordDecl *BaseRecord = Specifier->getType()->getAs()->getDecl(); + RecordDecl *BaseRecord = + Specifier->getType()->castAs()->getDecl(); DeclarationName N = DeclarationName::getFromOpaquePtr(Name); for (Path.Decls = BaseRecord->lookup(N); @@ -396,7 +397,8 @@ bool CXXRecordDecl::FindTagMember(const CXXBaseSpecifier *Specifier, bool CXXRecordDecl::FindOrdinaryMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, void *Name) { - RecordDecl *BaseRecord = Specifier->getType()->getAs()->getDecl(); + RecordDecl *BaseRecord = + Specifier->getType()->castAs()->getDecl(); const unsigned IDNS = IDNS_Ordinary | IDNS_Tag | IDNS_Member; DeclarationName N = DeclarationName::getFromOpaquePtr(Name); @@ -414,7 +416,8 @@ bool CXXRecordDecl:: FindNestedNameSpecifierMember(const CXXBaseSpecifier *Specifier, CXXBasePath &Path, void *Name) { - RecordDecl *BaseRecord = Specifier->getType()->getAs()->getDecl(); + RecordDecl *BaseRecord = + Specifier->getType()->castAs()->getDecl(); DeclarationName N = DeclarationName::getFromOpaquePtr(Name); for (Path.Decls = BaseRecord->lookup(N); @@ -692,7 +695,7 @@ AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext &Context, "Cannot get indirect primary bases for class with dependent bases."); const CXXRecordDecl *BaseDecl = - cast(I->getType()->getAs()->getDecl()); + cast(I->getType()->castAs()->getDecl()); // Only bases with virtual bases participate in computing the // indirect primary virtual base classes. -- cgit v1.2.3