Skip to content

Commit 0b49e52

Browse files
committed
fix: fix a bug when handling complex loop
Signed-off-by: cppbear <[email protected]>
1 parent e709a23 commit 0b49e52

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

clang-tools-extra/brinfo/Analysis.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,9 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
331331
vector<unsigned> LoopBlks = BlkCond.LoopBlks;
332332
unsigned ID = Blk->getBlockID();
333333

334-
DEBUG_PRINT("Block: " << ID << " Parent: " << Parent);
334+
// DEBUG_PRINT("Block: " << ID << " Parent: " << Parent);
335335
// DEBUG_EXEC(dumpBlkChain());
336336

337-
if (ID == 43)
338-
int A = 0;
339-
340337
if (ColorOfBlk[ID] == 0)
341338
ColorOfBlk[ID] = 1;
342339

@@ -354,24 +351,21 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
354351
llvm::sort(SortedPath.begin(), SortedPath.end());
355352
// Loop detected
356353
if (binary_search(SortedPath.begin(), SortedPath.end(), Blk)) {
357-
DEBUG_PRINT("Loop detected at Block " << Blk->getBlockID() << " in "
358-
<< Signature);
359-
if (Blk->getBlockID() == 44)
360-
int A = 0;
361-
DEBUG_EXEC(unsigned I = 0; for (const CFGBlock *Blk
362-
: Path) {
363-
if (I++ > 0)
364-
outs() << " \033[36m\033[1m->\033[0m ";
365-
outs() << Blk->getBlockID();
366-
} outs() << "\n";);
354+
// DEBUG_PRINT("Loop detected at Block " << Blk->getBlockID() << " in "
355+
// << Signature);
356+
// DEBUG_EXEC(unsigned I = 0; for (const CFGBlock *Blk
357+
// : Path) {
358+
// if (I++ > 0)
359+
// outs() << " \033[36m\033[1m->\033[0m ";
360+
// outs() << Blk->getBlockID();
361+
// } outs() << "\n";);
367362
bool Traverse = false;
368363
for (CFGBlock::AdjacentBlock Adj : Blk->succs()) {
369364
if (Adj.isReachable()) {
370365
if (!binary_search(SortedPath.begin(), SortedPath.end(), Adj)) {
371366
if (LoopInner[Blk->getBlockID()].find(Adj->getBlockID()) !=
372367
LoopInner[Blk->getBlockID()].end())
373368
continue;
374-
outs() << "Stack push " << Adj->getBlockID() << "\n";
375369
vector<unsigned> Loop = {};
376370
for (const CFGBlock *Blk : Path) {
377371
Loop.push_back(Blk->getBlockID());
@@ -381,14 +375,11 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
381375
}
382376
}
383377
}
384-
//FIXME: consider remove this
385378
if (!Traverse && InLoop) {
386379
unsigned PathSize = Path.size();
387380
for (unsigned I = PathSize - 1; I > 0; --I) {
388381
const CFGBlock *Succ = Path[I];
389382
const CFGBlock *Pred = Path[I - 1];
390-
outs() << "Clear Block " << Succ->getBlockID() << "\n";
391-
CondChainForBlk[Succ->getBlockID()] = {}; // clear
392383
bool IsSucc = isSucc(Pred, Succ);
393384
if (!IsSucc) {
394385
for (CFGBlock::AdjacentBlock Adj : Pred->succs()) {
@@ -487,18 +478,15 @@ void Analysis::dfsTraverseCFGLoop(long Parent, CFGBlock *FirstBlk) {
487478
const CFGBlock::AdjacentBlock *Adj = Blk->succ_begin();
488479
if (InnerCond) {
489480
if (Adj->isReachable()) {
490-
outs() << "Stack push " << (*Adj)->getBlockID() << "\n";
491481
Stack.push({ID, *Adj, Cond, true, InLoop, LoopBlks});
492482
}
493483
if (Blk->succ_size() == 2) {
494484
++Adj;
495485
if (Adj->isReachable()) {
496-
outs() << "Stack push " << (*Adj)->getBlockID() << "\n";
497486
Stack.push({ID, *Adj, Cond, false, InLoop, LoopBlks});
498487
}
499488
}
500489
} else if (Adj->isReachable()) {
501-
outs() << "Stack push " << (*Adj)->getBlockID() << "\n";
502490
Stack.push({ID, *Adj, nullptr, false, InLoop, LoopBlks});
503491
}
504492
break;

0 commit comments

Comments
 (0)