1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 343767 - [fp] 'No return' warning when return in both if and else

This commit is contained in:
Alena Laskavaia 2011-05-01 21:14:42 +00:00
parent a0ff5b6b4f
commit a63a62bc4f
2 changed files with 39 additions and 4 deletions

View file

@ -77,14 +77,14 @@ public class ControlFlowGraphBuilder {
exits = new ArrayList<IExitNode>();
dead = new ArrayList<IBasicBlock>();
IBasicBlock last = createSubGraph(start, body);
if (!(last instanceof IExitNode)) {
returnExit = (CxxExitNode) factory.createExitNode(null);
if (!(last instanceof IExitNode) && !deadConnector(last)) {
returnExit = factory.createExitNode(null);
returnExit.setStartNode(start);
addOutgoing(last, returnExit);
exits.add(returnExit);
if (dead.size() > 0) {
for (Iterator iterator = dead.iterator(); iterator.hasNext();) {
IBasicBlock ds = (IBasicBlock) iterator.next();
for (Iterator<IBasicBlock> iterator = dead.iterator(); iterator.hasNext();) {
IBasicBlock ds = iterator.next();
IBasicBlock dl = findLast(ds);
if (dl != null && dl.getOutgoingSize() == 0 && dl != returnExit) {
((AbstractBasicBlock) dl).addOutgoing(returnExit);
@ -97,6 +97,31 @@ public class ControlFlowGraphBuilder {
return graph;
}
/**
* @param last
* @return
*/
private boolean deadConnector(IBasicBlock conn) {
if (conn instanceof IJumpNode || conn instanceof IConnectorNode) {
if (conn.getIncomingSize() == 0) {
return true;
}
if (conn instanceof IJumpNode) {
IJumpNode jm = (IJumpNode) conn;
if (jm.isBackwardArc())
return false;
}
IBasicBlock[] conns = conn.getIncomingNodes();
for (int i = 0; i < conns.length; i++) {
IBasicBlock bb = conns[i];
if (!deadConnector(bb))
return false;
}
return true;
}
return false;
}
public IBasicBlock findLast(IBasicBlock node) {
if (node instanceof IJumpNode)
return null;

View file

@ -245,4 +245,14 @@ public class ReturnCheckerTest extends CheckerTestCase {
loadCodeAndRunCpp(getAboveComment());
checkNoErrors();
}
//int bar(int foo)
//{
// while(foo) {
// return 0;
// }
//}
public void testWhile() {
loadCodeAndRunCpp(getAboveComment());
checkErrorLine(1);
}
}