================
@@ -346,7 +346,7 @@ static std::optional<NonLoc> tryRearrange(ProgramStateRef 
State,
   if (BinaryOperator::isComparisonOp(Op) && !InBounds(LInt, RInt, LSym, RSym))
     return std::nullopt;
 
-  if (LSym == RSym)
+  if (LSym == RSym && Op != BO_Add)
----------------
NagyDonat wrote:

`tryRearrange` only handles expressions where the operator `Op` is additive 
(`BO_Add`, `BO_Sub`) or a comparison (`==`, `!=`, `>`, `<`, `>=`, `<=`). [1] 
This is guaranteed by a clear early return statement a few dozen lines above 
this change.

 Cancelling out is valid for all of these operator except for `BO_Add`.
 
 [1] Technically `BinaryOperator::isComparisonOperator` returns true for the 
spaceship operator `BO_Cmp` as well, but the analyze very quickly filters out 
that operator (IIRC returning `Unknown`), so it never reaches `tryRearrange`.
 
 I'll probably add an early return (or assertion failure?) for `BO_Cmp` to 
ensure correct behavior even if it will become somewhat supported in the 
future, but this belongs to a separate PR.

https://github.com/llvm/llvm-project/pull/237160
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to