Skip to content

Commit

Permalink
fix insertBefore for a stmt before block head
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzun66 committed Nov 28, 2024
1 parent dec694a commit 45e96d4
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ public void addBlock(@Nonnull List<Stmt> stmts, @Nonnull Map<ClassType, Stmt> tr
}

/**
* Create a new Block for the given stmts, and add exceptional successor to the block
*
* @param stmts List has to be non-empty!
* @param trapMap
*/
Expand All @@ -516,7 +518,7 @@ private MutableBasicBlock addBlockInternal(
MutableBasicBlock block = getOrCreateBlock(node);
if (block.getHead() != node || block.getSuccessors().stream().anyMatch(Objects::nonNull)) {
throw new IllegalArgumentException(
"The first Stmt in the List is already in the StmtGraph and and is not the head of a Block where currently no successor are set, yet.");
"The first Stmt in the List is already in the StmtGraph and is not the head of a Block where currently no successor are set, yet.");
} else if (block.getStmtCount() > 1) {
throw new IllegalArgumentException(
"The first Stmt in the List is already in the StmtGraph and has at least one (fallsthrough) successor in its Block.");
Expand Down Expand Up @@ -787,9 +789,10 @@ protected boolean isMergeable(
|| (fBlocksuccessors.size() == 1 && fBlocksuccessors.get(0) != followingBlock)) {
return false;
}
// if we are here the datastructure should have managed that the next if is true..
// if we are here the data-structure should have managed that the next if is true.
final List<MutableBasicBlock> sBlockPredecessors = followingBlock.getPredecessors();
if (sBlockPredecessors.size() != 1 || sBlockPredecessors.get(0) != firstBlock) {
if (sBlockPredecessors.size() > 1
|| (sBlockPredecessors.size() == 1 && sBlockPredecessors.get(0) != firstBlock)) {
return false;
}
// check if the same traps are applied to both blocks
Expand Down Expand Up @@ -819,7 +822,7 @@ protected boolean tryMergeBlocks(

blocks.remove(followingBlock);

// cleanup old block..
// cleanup old block.
followingBlock.clearPredecessorBlocks();
}
return mergeable;
Expand Down

0 comments on commit 45e96d4

Please sign in to comment.