diff options
author | Tomasz Wesolowski | 2012-11-17 06:38:45 +0000 |
---|---|---|
committer | Marc-Andre Laperle | 2012-11-17 06:49:04 +0000 |
commit | 5e369d662ebc55256faf14dc8b0998a898d4e85f (patch) | |
tree | 663a15b43d5fb00e0f1b2b28ce41a2b38b923ba7 | |
parent | e019d4965e10fec327681acee30ec7ba2774780c (diff) | |
download | org.eclipse.cdt-5e369d662ebc55256faf14dc8b0998a898d4e85f.tar.gz org.eclipse.cdt-5e369d662ebc55256faf14dc8b0998a898d4e85f.tar.xz org.eclipse.cdt-5e369d662ebc55256faf14dc8b0998a898d4e85f.zip |
Bug 348387 - fp in ReturnChecker using try/catch
5 files changed, 71 insertions, 15 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java index 07825aa1ab4..26483db4617 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Alena Laskavaia + * Copyright (c) 2009, 2012 Alena Laskavaia * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Alena Laskavaia - initial API and implementation + * Tomasz Wesolowski - Bug 348387 *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -47,6 +48,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -205,8 +207,9 @@ public class ReturnChecker extends AbstractAstFunctionChecker { */ private boolean isCompoundStatement(IASTStatement last) { return last instanceof IASTIfStatement || last instanceof IASTWhileStatement || - last instanceof IASTDoStatement || last instanceof IASTForStatement || - last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement; + last instanceof IASTDoStatement || last instanceof IASTForStatement || + last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement || + last instanceof ICPPASTTryBlockStatement; } protected boolean isFuncExitStatement(IASTStatement statement) { diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java index 22076c92a50..058ad120e75 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2012 Alena Laskavaia and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alena Laskavaia - initial API and implementation + * Alena Laskavaia - initial API and implementation + * Tomasz Wesolowski - Bug 348387 *******************************************************************************/ package org.eclipse.cdt.codan.core.cxx.internal.model.cfg; @@ -32,6 +33,7 @@ import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; import org.eclipse.cdt.core.dom.ast.IASTContinueStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement; import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement; @@ -231,14 +233,20 @@ public class ControlFlowGraphBuilder { addOutgoing(prev, ifNode); IConnectorNode mergeNode = factory.createConnectorNode(); ifNode.setMergeNode(mergeNode); - IBranchNode thenNode = factory.createBranchNode(IBranchNode.THEN); - addOutgoing(ifNode, thenNode); - IBasicBlock then = createSubGraph(thenNode, body.getTryBody()); - addJump(then, mergeNode); + IBranchNode tryBodyNode = factory.createBranchNode(IBranchNode.TRY_BODY); + addOutgoing(ifNode, tryBodyNode); + IBasicBlock tryBody = createSubGraph(tryBodyNode, body.getTryBody()); + addJump(tryBody, mergeNode); ICPPASTCatchHandler[] catchHandlers = body.getCatchHandlers(); for (int i = 0; i < catchHandlers.length; i++) { ICPPASTCatchHandler handler = catchHandlers[i]; - IBranchNode handlerNode = factory.createBranchNode(handler.getDeclaration()); + IBranchNode handlerNode; + IASTDeclaration declaration = handler.getDeclaration(); + if (declaration != null) { + handlerNode = factory.createBranchNode(declaration); + } else { + handlerNode = factory.createBranchNode(IBranchNode.CATCH_ANY); + } addOutgoing(ifNode, handlerNode); IBasicBlock els = createSubGraph(handlerNode, handler.getCatchBody()); addJump(els, mergeNode); diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java index 63d226ae0ca..dd6c6d20592 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2012 Alena Laskavaia * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -363,7 +363,7 @@ public class ControlFlowGraphTest extends CodanFastCxxAstTestCase { IPlainNode decl = (IPlainNode) startNode.getOutgoing(); IDecisionNode des = (IDecisionNode) decl.getOutgoing(); //assertEquals("", data(des)); - IPlainNode bThen = (IPlainNode) branchEnd(des, IBranchNode.THEN); + IPlainNode bThen = (IPlainNode) branchEnd(des, IBranchNode.TRY_BODY); assertEquals("*p = 1;", data(bThen)); IBasicBlock bElse = null; IBasicBlock[] outgoingNodes = des.getOutgoingNodes(); diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java index 75584462eb4..a3507569211 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 Alena Laskavaia + * Copyright (c) 2009, 2012 Alena Laskavaia * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Alena Laskavaia - initial API and implementation * Felipe Martinez - ReturnCheckerTest implementation + * Tomasz Wesolowski - Bug 348387 *******************************************************************************/ package org.eclipse.cdt.codan.core.internal.checkers; @@ -310,4 +311,39 @@ public class ReturnCheckerTest extends CheckerTestCase { loadCodeAndRun(getAboveComment()); checkNoErrors(); } + + // int try1() { + // try { + // return 5; + // } catch (...) { + // return 5; + // } + // } + public void testTryBlock1() throws Exception { + // bug 348387 + loadCodeAndRunCpp(getAboveComment()); + checkNoErrors(); + } + + // int try2() { + // try { + // return 5; + // } catch (int) { + // } + // } + public void testTryBlock2() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(1); + } + + // int try3() { + // try { + // } catch (int a) { + // return 5; + // } + // } + public void testTryBlock3() throws Exception { + loadCodeAndRunCpp(getAboveComment()); + checkErrorLine(1); + } }
\ No newline at end of file diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/cfg/IBranchNode.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/cfg/IBranchNode.java index ec0005df95c..a4e78202081 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/cfg/IBranchNode.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/cfg/IBranchNode.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2012 Alena Laskavaia and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alena Laskavaia - initial API and implementation + * Alena Laskavaia - initial API and implementation + * Tomasz Wesolowski - Bug 348387 *******************************************************************************/ package org.eclipse.cdt.codan.core.model.cfg; @@ -29,6 +30,14 @@ public interface IBranchNode extends IBasicBlock, ISingleIncoming, ISingleOutgoi * Default branch of "switch" statement */ public static String DEFAULT = "default"; //$NON-NLS-1$ + /** + * Try branch of "try" block statement + */ + public static String TRY_BODY = "try"; //$NON-NLS-1$ + /** + * Catch "..." branch of "try" block statement + */ + public static String CATCH_ANY = "..."; //$NON-NLS-1$ /** * @return label of a branch |