[clang] [Sema] Fix -Wunreachable-code false negative when operands differ only by implicit casts (PR #149972)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 24 09:49:03 PDT 2025
================
@@ -1160,8 +1160,11 @@ class CFGBuilder {
return {};
// Check that it is the same variable on both sides.
- if (!Expr::isSameComparisonOperand(DeclExpr1, DeclExpr2))
- return {};
+ if (!Expr::isSameComparisonOperand(DeclExpr1, DeclExpr2)) {
+ if (!Expr::isSameComparisonOperand(DeclExpr1->IgnoreParenImpCasts(),
+ DeclExpr2->IgnoreParenImpCasts()))
+ return {};
----------------
AaronBallman wrote:
Thank you for the explanation, that was helpful!
Perhaps dumb question: would it make more sense to have the cast checks in `isSameComparisonOperand()` single-step through the casts to find matching ones? Because it seems a bit odd that inserting a Noop cast in one node but not the other would mean they're automatically different comparison operands.
https://github.com/llvm/llvm-project/pull/149972
More information about the cfe-commits
mailing list