[PATCH] D91037: [clang-tidy] Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups

Zinovy Nis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 10 10:02:27 PST 2020


zinovy.nis marked an inline comment as done and 2 inline comments as not done.
zinovy.nis 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)
----------------
aaron.ballman wrote:
> Under what circumstances does `getCond()` return `nullptr`?
`getCond()` is not null, but it can be `ExprWithCleanupsCond` leading the original `dyn_cast` to crash. That what this bug is about.



================
Comment at: clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp:90
+      BinOpCond = dyn_cast_or_null<BinaryOperator>(
+          *ExprWithCleanupsCond->children().begin());
+
----------------
aaron.ballman wrote:
> You can call `ExprWithCleanupsCond->getSubExpr()` to do this more cleanly -- but similar question here as above -- what circumstances lead to a null sub expression?
Thanks, fixed to use `getSubExpr()`.




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91037/new/

https://reviews.llvm.org/D91037



More information about the cfe-commits mailing list