mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Bug 343767 - [fp] 'No return' warning when return in both if and else
This commit is contained in:
parent
a0ff5b6b4f
commit
a63a62bc4f
2 changed files with 39 additions and 4 deletions
|
@ -77,14 +77,14 @@ public class ControlFlowGraphBuilder {
|
||||||
exits = new ArrayList<IExitNode>();
|
exits = new ArrayList<IExitNode>();
|
||||||
dead = new ArrayList<IBasicBlock>();
|
dead = new ArrayList<IBasicBlock>();
|
||||||
IBasicBlock last = createSubGraph(start, body);
|
IBasicBlock last = createSubGraph(start, body);
|
||||||
if (!(last instanceof IExitNode)) {
|
if (!(last instanceof IExitNode) && !deadConnector(last)) {
|
||||||
returnExit = (CxxExitNode) factory.createExitNode(null);
|
returnExit = factory.createExitNode(null);
|
||||||
returnExit.setStartNode(start);
|
returnExit.setStartNode(start);
|
||||||
addOutgoing(last, returnExit);
|
addOutgoing(last, returnExit);
|
||||||
exits.add(returnExit);
|
exits.add(returnExit);
|
||||||
if (dead.size() > 0) {
|
if (dead.size() > 0) {
|
||||||
for (Iterator iterator = dead.iterator(); iterator.hasNext();) {
|
for (Iterator<IBasicBlock> iterator = dead.iterator(); iterator.hasNext();) {
|
||||||
IBasicBlock ds = (IBasicBlock) iterator.next();
|
IBasicBlock ds = iterator.next();
|
||||||
IBasicBlock dl = findLast(ds);
|
IBasicBlock dl = findLast(ds);
|
||||||
if (dl != null && dl.getOutgoingSize() == 0 && dl != returnExit) {
|
if (dl != null && dl.getOutgoingSize() == 0 && dl != returnExit) {
|
||||||
((AbstractBasicBlock) dl).addOutgoing(returnExit);
|
((AbstractBasicBlock) dl).addOutgoing(returnExit);
|
||||||
|
@ -97,6 +97,31 @@ public class ControlFlowGraphBuilder {
|
||||||
return graph;
|
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) {
|
public IBasicBlock findLast(IBasicBlock node) {
|
||||||
if (node instanceof IJumpNode)
|
if (node instanceof IJumpNode)
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -245,4 +245,14 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
loadCodeAndRunCpp(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
//int bar(int foo)
|
||||||
|
//{
|
||||||
|
// while(foo) {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testWhile() {
|
||||||
|
loadCodeAndRunCpp(getAboveComment());
|
||||||
|
checkErrorLine(1);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue