================
@@ -400,12 +401,58 @@ void FactsGenerator::VisitBinaryOperator(const 
BinaryOperator *BO) {
   // TODO: Handle assignments involving dereference like `*p = q`.
 }
 
+void FactsGenerator::handleTernaryOperator(const ConditionalOperator *CO) {
+  const Expr *TrueExpr = CO->getTrueExpr();
+  const Expr *FalseExpr = CO->getFalseExpr();
+
+  const auto Preds = CurrentBlock->preds();
+  auto PredHasStmt = [](const CFGBlock::AdjacentBlock &Pred, const Stmt *S) {
+    return llvm::any_of(*Pred, [S](const CFGElement &Elt) {
+      if (auto CS = Elt.getAs<CFGStmt>()) {
+        return CS->getStmt() == S;
+      }
+      return false;
+    });
+  };
+
+  bool TBHasEdge = true;
+  bool FBHasEdge = true;
+
+  switch (CurrentBlock->pred_size()) {
+  case 0:
+    return;
+  case 1:
+    TBHasEdge = PredHasStmt(*Preds.begin(), TrueExpr->IgnoreParenImpCasts());
+    FBHasEdge = !TBHasEdge;
+    break;
+  case 2: {
+    const auto *It = Preds.begin();
+    TBHasEdge = It->isReachable();
+    FBHasEdge = (++It)->isReachable();
+    break;
+  }
+  default:
+    llvm_unreachable("expected at most 2 predecessors");
+    return;
+  }
+
+  bool FirstFlow = true;
+  auto HandleFlow = [&](const Expr *E, bool HasAnEdge) {
+    if (!HasAnEdge)
+      return;
+    if (FirstFlow) {
+      killAndFlowOrigin(*CO, *E);
+      FirstFlow = false;
+    } else
+      flowOrigin(*CO, *E);
+  };
+  HandleFlow(TrueExpr, TBHasEdge);
----------------
usx95 wrote:

super nit: let's be explicit about the use of `TBHasEdge`. E.g.

`if(TBHasEdge) HandleFlow(TrueExpr);`

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

Reply via email to