summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/simplifypointertobool.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/simplifypointertobool.cxx')
-rw-r--r--compilerplugins/clang/simplifypointertobool.cxx36
1 files changed, 15 insertions, 21 deletions
diff --git a/compilerplugins/clang/simplifypointertobool.cxx b/compilerplugins/clang/simplifypointertobool.cxx
index 7afa2d01ec3e..1a9471fcf877 100644
--- a/compilerplugins/clang/simplifypointertobool.cxx
+++ b/compilerplugins/clang/simplifypointertobool.cxx
@@ -17,8 +17,6 @@
#include <clang/AST/CXXInheritance.h>
-#include "config_clang.h"
-
#include "plugin.hxx"
#include "check.hxx"
#include "compat.hxx"
@@ -78,10 +76,6 @@ public:
return res;
}
-#if CLANG_VERSION < 110000
- bool TraverseUnaryLNot(UnaryOperator* expr) { return TraverseUnaryOperator(expr); }
-#endif
-
bool PreTraverseBinaryOperator(BinaryOperator* expr)
{
auto const op = expr->getOpcode();
@@ -114,11 +108,6 @@ public:
return res;
}
-#if CLANG_VERSION < 110000
- bool TraverseBinLAnd(BinaryOperator* expr) { return TraverseBinaryOperator(expr); }
- bool TraverseBinLOr(BinaryOperator* expr) { return TraverseBinaryOperator(expr); }
-#endif
-
bool PreTraverseConditionalOperator(ConditionalOperator* expr)
{
contextuallyConvertedExprs_.push_back(expr->getCond()->IgnoreParenImpCasts());
@@ -143,14 +132,20 @@ public:
bool PreTraverseIfStmt(IfStmt* stmt)
{
- contextuallyConvertedExprs_.push_back(stmt->getCond()->IgnoreParenImpCasts());
+ if (auto const cond = stmt->getCond())
+ {
+ contextuallyConvertedExprs_.push_back(cond->IgnoreParenImpCasts());
+ }
return true;
}
- bool PostTraverseIfStmt(IfStmt*, bool)
+ bool PostTraverseIfStmt(IfStmt* stmt, bool)
{
- assert(!contextuallyConvertedExprs_.empty());
- contextuallyConvertedExprs_.pop_back();
+ if (stmt->getCond() != nullptr)
+ {
+ assert(!contextuallyConvertedExprs_.empty());
+ contextuallyConvertedExprs_.pop_back();
+ }
return true;
}
@@ -268,7 +263,7 @@ private:
auto const s = StringRef(compiler.getSourceManager().getCharacterData(start),
Lexer::MeasureTokenLength(start, compiler.getSourceManager(),
compiler.getLangOpts()));
- if (s.empty() || s.startswith("\\\n"))
+ if (s.empty() || compat::starts_with(s, "\\\n"))
{
continue;
}
@@ -285,14 +280,13 @@ private:
auto const s = StringRef(compiler.getSourceManager().getCharacterData(start1),
Lexer::MeasureTokenLength(start1, compiler.getSourceManager(),
compiler.getLangOpts()));
- if (!(s.empty() || s.startswith("\\\n")))
+ if (!(s.empty() || compat::starts_with(s, "\\\n")))
{
break;
}
start = start1;
}
- return SourceRange(start,
- compiler.getSourceManager().getSpellingLoc(compat::getEndLoc(expr)));
+ return SourceRange(start, compiler.getSourceManager().getSpellingLoc(expr->getEndLoc()));
}
//TODO: There are some more places where an expression is contextually converted to bool, but
@@ -379,7 +373,7 @@ bool SimplifyPointerToBool::VisitImplicitCastExpr(ImplicitCastExpr const* castEx
if (rewriter)
{
auto const loc
- = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(memberCallExpr));
+ = compiler.getSourceManager().getSpellingLoc(memberCallExpr->getBeginLoc());
auto const range = getCallSourceRange(memberCallExpr);
if (loc.isValid() && range.isValid() && insertText(loc, "bool") && removeText(range))
{
@@ -401,7 +395,7 @@ bool SimplifyPointerToBool::VisitImplicitCastExpr(ImplicitCastExpr const* castEx
if (rewriter)
{
auto const loc
- = compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(memberCallExpr));
+ = compiler.getSourceManager().getSpellingLoc(memberCallExpr->getBeginLoc());
auto const range = getCallSourceRange(memberCallExpr);
if (loc.isValid() && range.isValid() && insertText(loc, "bool(")
&& replaceText(range, ")"))