diff options
Diffstat (limited to 'compilerplugins/clang/simplifydynamiccast.cxx')
-rw-r--r-- | compilerplugins/clang/simplifydynamiccast.cxx | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/compilerplugins/clang/simplifydynamiccast.cxx b/compilerplugins/clang/simplifydynamiccast.cxx index b1f06179ee71..3b94f284de1e 100644 --- a/compilerplugins/clang/simplifydynamiccast.cxx +++ b/compilerplugins/clang/simplifydynamiccast.cxx @@ -14,7 +14,6 @@ #include <set> #include <clang/AST/CXXInheritance.h> -#include "compat.hxx" #include "plugin.hxx" namespace @@ -47,15 +46,19 @@ private: bool SimplifyDynamicCast::TraverseIfStmt(IfStmt* ifStmt) { - auto condExpr = ifStmt->getCond()->IgnoreParenImpCasts(); - auto dynamicCastExpr = dyn_cast<CXXDynamicCastExpr>(condExpr); - if (!dynamicCastExpr) + CXXDynamicCastExpr const* dynamicCastExpr = nullptr; + if (Expr const* condExpr = ifStmt->getCond()) { - if (auto binaryOp = dyn_cast<BinaryOperator>(condExpr)) + condExpr = condExpr->IgnoreParenImpCasts(); + dynamicCastExpr = dyn_cast<CXXDynamicCastExpr>(condExpr); + if (!dynamicCastExpr) { - if (binaryOp->getOpcode() == BO_NE) - dynamicCastExpr - = dyn_cast<CXXDynamicCastExpr>(binaryOp->getLHS()->IgnoreParenImpCasts()); + if (auto binaryOp = dyn_cast<BinaryOperator>(condExpr)) + { + if (binaryOp->getOpcode() == BO_NE) + dynamicCastExpr + = dyn_cast<CXXDynamicCastExpr>(binaryOp->getLHS()->IgnoreParenImpCasts()); + } } } Decl const* subExprDecl = nullptr; @@ -102,12 +105,10 @@ bool SimplifyDynamicCast::VisitCXXStaticCastExpr(CXXStaticCastExpr const* static return true; if (dynamicCastSubExprVec[idx] != subExprDecl->getDecl()) return true; - report(DiagnosticsEngine::Warning, "simplify, use var in if", - compat::getBeginLoc(staticCastExpr)) + report(DiagnosticsEngine::Warning, "simplify, use var in if", staticCastExpr->getBeginLoc()) << staticCastExpr->getSourceRange(); auto ifStmt = ifVec[idx]; - report(DiagnosticsEngine::Note, "if here", compat::getBeginLoc(ifStmt)) - << ifStmt->getSourceRange(); + report(DiagnosticsEngine::Note, "if here", ifStmt->getBeginLoc()) << ifStmt->getSourceRange(); return true; } |