Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2015-02-17 02:51:02 -0500
committerGerrit Code Review @ Eclipse.org2015-02-20 09:30:19 -0500
commit80c624f2c3bf45de6029e1bc2e2333aa9b241160 (patch)
tree6c7972891efe8ae73b48e0a6f94f8b6b5deb56dd /codan/org.eclipse.cdt.codan.core
parentbb8cc948c43591ac7f47fcaf8813a5cd07118606 (diff)
downloadorg.eclipse.cdt-80c624f2c3bf45de6029e1bc2e2333aa9b241160.tar.gz
org.eclipse.cdt-80c624f2c3bf45de6029e1bc2e2333aa9b241160.tar.xz
org.eclipse.cdt-80c624f2c3bf45de6029e1bc2e2333aa9b241160.zip
Bug 455828 - Don't be over-eager when collecting dead nodes in the
control flow graph Change-Id: I54013e31a197c02698e3161f9f52755e4cb6b203 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core')
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java47
1 files changed, 38 insertions, 9 deletions
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java
index 059c83f5a2..53ea9e5c2b 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java
@@ -125,18 +125,11 @@ public class ControlFlowGraph implements IControlFlowGraph {
public Collection<IBasicBlock> getNodes() {
Collection<IBasicBlock> result = new LinkedHashSet<IBasicBlock>();
getNodes(getStartNode(), result);
- for (Iterator<IBasicBlock> iterator = deadNodes.iterator(); iterator.hasNext();) {
- IBasicBlock d = iterator.next();
- getNodes(d, result);
- }
+ getDeadNodes(result);
return result;
}
- /**
- * @param d
- * @param result
- */
- public void getNodes(IBasicBlock start, Collection<IBasicBlock> result) {
+ private void getNodes(IBasicBlock start, Collection<IBasicBlock> result) {
if (start == null)
return; // huh
if (result.contains(start))
@@ -152,4 +145,40 @@ public class ControlFlowGraph implements IControlFlowGraph {
}
}
}
+
+ public Collection<IBasicBlock> getDeadNodes() {
+ Collection<IBasicBlock> result = new LinkedHashSet<IBasicBlock>();
+ getDeadNodes(result);
+ return result;
+ }
+
+ private void getDeadNodes(Collection<IBasicBlock> result) {
+ Collection<IBasicBlock> liveNodes = new LinkedHashSet<IBasicBlock>();
+ getNodes(getStartNode(), liveNodes);
+
+ for (Iterator<IBasicBlock> iterator = deadNodes.iterator(); iterator.hasNext();) {
+ IBasicBlock d = iterator.next();
+ getDeadNodes(d, result, liveNodes);
+ }
+ }
+
+ public void getDeadNodes(IBasicBlock start, Collection<IBasicBlock> result, Collection<IBasicBlock> liveNodes) {
+ if (start == null)
+ return; // huh
+ if (result.contains(start))
+ return;
+ if (liveNodes.contains(start))
+ return; // a live node is by definition not dead
+ result.add(start);
+ for (IBasicBlock bb : start.getOutgoingNodes()) {
+ getDeadNodes(bb, result, liveNodes);
+ }
+ if (start instanceof IConnectorNode) {
+ // Sometimes, a dead connector node can have incoming nodes that are not otherwise reachable
+ // from unconnected nodes (this happens for a branch node for a dead label).
+ for (IBasicBlock bb : start.getIncomingNodes()) {
+ getDeadNodes(bb, result, liveNodes);
+ }
+ }
+ }
}

Back to the top