From 3a1fbb70a39cff9eea852f6709ecb63f45b29c40 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 16 Mar 2023 12:06:43 +0100 Subject: Prepare compilerplugins for C++23 `if consteval` ...for which clang::IfStmt::getCond returns null Change-Id: I8b86a033d52de87dedbdf6d867f2b3d3f57c1b5a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148979 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- compilerplugins/clang/simplifydynamiccast.cxx | 18 +++++++++++------- compilerplugins/clang/simplifypointertobool.cxx | 14 ++++++++++---- compilerplugins/clang/unnecessaryparen.cxx | 6 ++++-- 3 files changed, 25 insertions(+), 13 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/simplifydynamiccast.cxx b/compilerplugins/clang/simplifydynamiccast.cxx index ffb81658d8c8..3b94f284de1e 100644 --- a/compilerplugins/clang/simplifydynamiccast.cxx +++ b/compilerplugins/clang/simplifydynamiccast.cxx @@ -46,15 +46,19 @@ private: bool SimplifyDynamicCast::TraverseIfStmt(IfStmt* ifStmt) { - auto condExpr = ifStmt->getCond()->IgnoreParenImpCasts(); - auto dynamicCastExpr = dyn_cast(condExpr); - if (!dynamicCastExpr) + CXXDynamicCastExpr const* dynamicCastExpr = nullptr; + if (Expr const* condExpr = ifStmt->getCond()) { - if (auto binaryOp = dyn_cast(condExpr)) + condExpr = condExpr->IgnoreParenImpCasts(); + dynamicCastExpr = dyn_cast(condExpr); + if (!dynamicCastExpr) { - if (binaryOp->getOpcode() == BO_NE) - dynamicCastExpr - = dyn_cast(binaryOp->getLHS()->IgnoreParenImpCasts()); + if (auto binaryOp = dyn_cast(condExpr)) + { + if (binaryOp->getOpcode() == BO_NE) + dynamicCastExpr + = dyn_cast(binaryOp->getLHS()->IgnoreParenImpCasts()); + } } } Decl const* subExprDecl = nullptr; diff --git a/compilerplugins/clang/simplifypointertobool.cxx b/compilerplugins/clang/simplifypointertobool.cxx index 097a78e16f67..11aed0f317b7 100644 --- a/compilerplugins/clang/simplifypointertobool.cxx +++ b/compilerplugins/clang/simplifypointertobool.cxx @@ -131,14 +131,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; } diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx index 11655d51389e..1d11aca4ab47 100644 --- a/compilerplugins/clang/unnecessaryparen.cxx +++ b/compilerplugins/clang/unnecessaryparen.cxx @@ -262,8 +262,10 @@ bool UnnecessaryParen::VisitParenExpr(const ParenExpr* parenExpr) bool UnnecessaryParen::VisitIfStmt(const IfStmt* ifStmt) { - handleUnreachableCodeConditionParens(ifStmt->getCond()); - VisitSomeStmt(ifStmt, ifStmt->getCond(), "if"); + if (auto const cond = ifStmt->getCond()) { + handleUnreachableCodeConditionParens(cond); + VisitSomeStmt(ifStmt, cond, "if"); + } return true; } -- cgit