diff options
author | George Burgess IV <george.burgess.iv@gmail.com> | 2018-03-01 05:43:23 +0000 |
---|---|---|
committer | George Burgess IV <george.burgess.iv@gmail.com> | 2018-03-01 05:43:23 +0000 |
commit | 00f70bd9337f19972da728185ac5c8410ca21e69 (patch) | |
tree | de502f7ffa65b4b2566f7eac90eb2ed7c21bd67b /clang/lib/StaticAnalyzer | |
parent | 05660dacedc14fa911d90317312cb613c3b776af (diff) | |
download | bcm5719-llvm-00f70bd9337f19972da728185ac5c8410ca21e69.tar.gz bcm5719-llvm-00f70bd9337f19972da728185ac5c8410ca21e69.zip |
Remove redundant casts. NFC
So I wrote a clang-tidy check to lint out redundant `isa`, `cast`, and
`dyn_cast`s for fun. This is a portion of what it found for clang; I
plan to do similar cleanups in LLVM and other subprojects when I find
time.
Because of the volume of changes, I explicitly avoided making any change
that wasn't highly local and obviously correct to me (e.g. we still have
a number of foo(cast<Bar>(baz)) that I didn't touch, since overloading
is a thing and the cast<Bar> did actually change the type -- just up the
class hierarchy).
I also tried to leave the types we were cast<>ing to somewhere nearby,
in cases where it wasn't locally obvious what we were dealing with
before.
llvm-svn: 326416
Diffstat (limited to 'clang/lib/StaticAnalyzer')
6 files changed, 13 insertions, 13 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp index 65e81315f09..00e90335572 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp @@ -78,7 +78,7 @@ bool CastToStructVisitor::VisitCastExpr(const CastExpr *CE) { // Don't warn for references const ValueDecl *VD = nullptr; if (const auto *SE = dyn_cast<DeclRefExpr>(U->getSubExpr())) - VD = dyn_cast<ValueDecl>(SE->getDecl()); + VD = SE->getDecl(); else if (const auto *SE = dyn_cast<MemberExpr>(U->getSubExpr())) VD = SE->getMemberDecl(); if (!VD || VD->getType()->isReferenceType()) diff --git a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index 8076ca09591..fd310f8282f 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -402,13 +402,13 @@ visit(const ObjCImplementationDecl *ImplD) const { // Find the setter and the getter. const ObjCMethodDecl *SetterD = PD->getSetterMethodDecl(); if (SetterD) { - SetterD = cast<ObjCMethodDecl>(SetterD->getCanonicalDecl()); + SetterD = SetterD->getCanonicalDecl(); PropSetterToIvarMap[SetterD] = ID; } const ObjCMethodDecl *GetterD = PD->getGetterMethodDecl(); if (GetterD) { - GetterD = cast<ObjCMethodDecl>(GetterD->getCanonicalDecl()); + GetterD = GetterD->getCanonicalDecl(); PropGetterToIvarMap[GetterD] = ID; } } @@ -606,7 +606,7 @@ void IvarInvalidationCheckerImpl::MethodCrawler::checkObjCMessageExpr( const ObjCMessageExpr *ME) { const ObjCMethodDecl *MD = ME->getMethodDecl(); if (MD) { - MD = cast<ObjCMethodDecl>(MD->getCanonicalDecl()); + MD = MD->getCanonicalDecl(); MethToIvarMapTy::const_iterator IvI = PropertyGetterToIvarMap.find(MD); if (IvI != PropertyGetterToIvarMap.end()) markInvalidated(IvI->second); @@ -630,7 +630,7 @@ void IvarInvalidationCheckerImpl::MethodCrawler::checkObjCPropertyRefExpr( if (PA->isImplicitProperty()) { const ObjCMethodDecl *MD = PA->getImplicitPropertySetter(); if (MD) { - MD = cast<ObjCMethodDecl>(MD->getCanonicalDecl()); + MD = MD->getCanonicalDecl(); MethToIvarMapTy::const_iterator IvI =PropertyGetterToIvarMap.find(MD); if (IvI != PropertyGetterToIvarMap.end()) markInvalidated(IvI->second); @@ -702,7 +702,7 @@ void IvarInvalidationCheckerImpl::MethodCrawler::VisitObjCMessageExpr( // Check if we call a setter and set the property to 'nil'. if (MD && (ME->getNumArgs() == 1) && isZero(ME->getArg(0))) { - MD = cast<ObjCMethodDecl>(MD->getCanonicalDecl()); + MD = MD->getCanonicalDecl(); MethToIvarMapTy::const_iterator IvI = PropertySetterToIvarMap.find(MD); if (IvI != PropertySetterToIvarMap.end()) { markInvalidated(IvI->second); diff --git a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp index 4a5ed42c0f3..3ff02f17d03 100644 --- a/clang/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/clang/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -1260,7 +1260,7 @@ CallEventManager::getCaller(const StackFrameContext *CalleeCtx, if (Optional<CFGAutomaticObjDtor> AutoDtor = E.getAs<CFGAutomaticObjDtor>()) Trigger = AutoDtor->getTriggerStmt(); else if (Optional<CFGDeleteDtor> DeleteDtor = E.getAs<CFGDeleteDtor>()) - Trigger = cast<Stmt>(DeleteDtor->getDeleteExpr()); + Trigger = DeleteDtor->getDeleteExpr(); else Trigger = Dtor->getBody(); diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp index 44099f4f73e..1562ff1193f 100644 --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -774,9 +774,9 @@ getStackOrCaptureRegionForDeclContext(const LocationContext *LC, for (BlockDataRegion::referenced_vars_iterator I = BR->referenced_vars_begin(), E = BR->referenced_vars_end(); I != E; ++I) { - if (const VarRegion *VR = dyn_cast<VarRegion>(I.getOriginalRegion())) - if (VR->getDecl() == VD) - return cast<VarRegion>(I.getCapturedRegion()); + const VarRegion *VR = I.getOriginalRegion(); + if (VR->getDecl() == VD) + return cast<VarRegion>(I.getCapturedRegion()); } } diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp index 2546bf074a6..deb2e4a5074 100644 --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -255,7 +255,7 @@ SVal ProgramState::getSValAsScalarOrLoc(const MemRegion *R) const { } SVal ProgramState::getSVal(Loc location, QualType T) const { - SVal V = getRawSVal(cast<Loc>(location), T); + SVal V = getRawSVal(location, T); // If 'V' is a symbolic value that is *perfectly* constrained to // be a constant value, use that value instead to lessen the burden diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp index 686216ae29e..01812991892 100644 --- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -825,7 +825,7 @@ collectSubRegionBindings(SmallVectorImpl<BindingPair> &Bindings, FieldVector FieldsInSymbolicSubregions; if (TopKey.hasSymbolicOffset()) { getSymbolicOffsetFields(TopKey, FieldsInSymbolicSubregions); - Top = cast<SubRegion>(TopKey.getConcreteOffsetRegion()); + Top = TopKey.getConcreteOffsetRegion(); TopKey = BindingKey::Make(Top, BindingKey::Default); } @@ -1774,7 +1774,7 @@ RegionStoreManager::getBindingForFieldOrElementCommon(RegionBindingsConstRef B, // quickly result in a warning. bool hasPartialLazyBinding = false; - const SubRegion *SR = dyn_cast<SubRegion>(R); + const SubRegion *SR = R; while (SR) { const MemRegion *Base = SR->getSuperRegion(); if (Optional<SVal> D = getBindingForDerivedDefaultValue(B, Base, R, Ty)) { |