[PATCH] D91037: [clang-tidy] Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 10 06:26:54 PST 2020
aaron.ballman added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp:85
// remove the inner `if`.
- const auto *BinOpCond = dyn_cast<BinaryOperator>(InnerIf->getCond());
+ const auto *BinOpCond = dyn_cast_or_null<BinaryOperator>(InnerIf->getCond());
+ if (!BinOpCond)
----------------
Under what circumstances does `getCond()` return `nullptr`?
================
Comment at: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp:90
+ BinOpCond = dyn_cast_or_null<BinaryOperator>(
+ *ExprWithCleanupsCond->children().begin());
+
----------------
You can call `ExprWithCleanupsCond->getSubExpr()` to do this more cleanly -- but similar question here as above -- what circumstances lead to a null sub expression?
================
Comment at: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp:138
} else {
- const auto *CondOp = cast<BinaryOperator>(InnerIf->getCond());
+ const auto *CondOp = dyn_cast_or_null<BinaryOperator>(InnerIf->getCond());
+ if (!CondOp)
----------------
Same feedback here as above.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91037/new/
https://reviews.llvm.org/D91037
More information about the cfe-commits
mailing list