From: Simon Pilgrim Date: Sat, 12 Feb 2022 19:59:13 +0000 (+0000) Subject: [clang-tidy] SimplifyBooleanExprCheck - use cast<> instead of dyn_cast<> to avoid... X-Git-Tag: upstream/15.0.7~16698 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5d1e3ed3e257535fbd51706023685d2c2d9eba51;p=platform%2Fupstream%2Fllvm.git [clang-tidy] SimplifyBooleanExprCheck - use cast<> instead of dyn_cast<> to avoid dereference of nullptr The IfStmt pointer is always referenced inside the replaceCompoundReturnWithCondition call, so assert the cast is correct instead of returning nullptr --- diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp index 9c2ddf1..61ba4b8 100644 --- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp @@ -750,7 +750,7 @@ void SimplifyBooleanExprCheck::replaceCompoundReturnWithCondition( void SimplifyBooleanExprCheck::replaceCaseCompoundReturnWithCondition( const MatchFinder::MatchResult &Result, bool Negated) { const auto *CaseDefault = Result.Nodes.getNodeAs(CaseId); - const auto *If = dyn_cast(CaseDefault->getSubStmt()); + const auto *If = cast(CaseDefault->getSubStmt()); replaceCompoundReturnWithCondition(Result, Negated, If); } @@ -758,14 +758,14 @@ void SimplifyBooleanExprCheck::replaceDefaultCompoundReturnWithCondition( const MatchFinder::MatchResult &Result, bool Negated) { const SwitchCase *CaseDefault = Result.Nodes.getNodeAs(DefaultId); - const auto *If = dyn_cast(CaseDefault->getSubStmt()); + const auto *If = cast(CaseDefault->getSubStmt()); replaceCompoundReturnWithCondition(Result, Negated, If); } void SimplifyBooleanExprCheck::replaceLabelCompoundReturnWithCondition( const MatchFinder::MatchResult &Result, bool Negated) { const auto *Label = Result.Nodes.getNodeAs(LabelId); - const auto *If = dyn_cast(Label->getSubStmt()); + const auto *If = cast(Label->getSubStmt()); replaceCompoundReturnWithCondition(Result, Negated, If); }