================
@@ -202,53 +203,74 @@ class AnalysisImpl
return getLoans(getState(P), OID);
}
- llvm::SmallVector<OriginID>
- buildOriginFlowChain(ProgramPoint StartPoint, const OriginID StartOID,
- const LoanID TargetLoan) const {
+ llvm::SmallVector<OriginID> buildOriginFlowChain(ProgramPoint StartPoint,
+ const OriginID StartOID,
+ const LoanID TargetLoan,
+ const CFG *Cfg) const {
assert(getLoans(StartOID, StartPoint).contains(TargetLoan) &&
"TargetLoan must be present in the StartOID at the StartPoint");
- OriginID CurrOID = StartOID;
- llvm::SmallVector<OriginID> OriginFlowChain;
- llvm::ArrayRef<const Fact *> Facts =
FactMgr.getBlockContaining(StartPoint);
- const auto *StartIt = llvm::find(Facts, StartPoint);
- assert(StartIt != Facts.end());
-
- for (const Fact *F :
- llvm::reverse(llvm::make_range(Facts.begin(), StartIt))) {
- if (const auto *IF = F->getAs<IssueFact>())
- if (IF->getLoanID() == TargetLoan) {
- assert(IF->getOriginID() == CurrOID);
- return OriginFlowChain;
- }
+ // Locate the CFG block containing the StartPoint
+ const CFGBlock *EndBlock = nullptr;
+ size_t BlockID = FactMgr.getBlockID(StartPoint);
+ for (const CFGBlock *Block : *Cfg)
+ if (Block->getBlockID() == BlockID) {
+ EndBlock = Block;
+ break;
+ }
- const auto *OFF = F->getAs<OriginFlowFact>();
- if (!OFF)
- continue;
- if (OFF->getDestOriginID() != CurrOID)
- continue;
+ // Set up DFS traversal state
+ // SearchState tracks which block we're in and which origin we're tracing
+ // Each DFSNode maintains its own OriginFlowChain.
+ using SearchState = std::pair<const CFGBlock *, OriginID>;
+ struct DFSNode {
+ SearchState CurrState;
+ llvm::SmallVector<OriginID> OriginFlowChain;
----------------
usx95 wrote:
Oh my bad. I totally did not know we already had an `ImmutableList` impl. I
think it makes sense to even do this eagerly in the next PR. This triggers in
case we have real violations findings and it is possible that people do not
report delays in this.
cc: @suoyuan666
https://github.com/llvm/llvm-project/pull/204592
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits