[clang] [Liveness][analyzer] Fix liveness of binary logical operators and their subexpressions (PR #231419)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 13 03:08:55 PDT 2026


================
@@ -339,6 +339,12 @@ void TransferFunctions::Visit(Stmt *S) {
       AddLiveExpr(val.liveExprs, LV.ESetFact, CO->getFalseExpr());
       return;
     }
+    case Stmt::BinaryOperatorClass: {
+      auto const *BO = cast<BinaryOperator>(S);
+      if (BO->isLogicalOp())
+        AddAllConditionalTerms(val.liveExprs, LV.ESetFact, BO);
----------------
NagyDonat wrote:

```suggestion
      if (BO->isLogicalOp()) {
        AddAllConditionalTerms(val.liveExprs, LV.ESetFact, BO);
        return;
      }
```
Using `break;` instead of `return;` means that the loop over `S->children()` is also executed -- which is necessary for non-logical binary operators, but completely redundant and a bit surprising for a logical operator.

Consider adding a `return;` in the `if` here – this is not necessary for correct behavior, but perhaps makes the intent more clear.

https://github.com/llvm/llvm-project/pull/231419


More information about the cfe-commits mailing list