summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Wesolowski2012-11-17 01:38:45 (EST)
committer Marc-Andre Laperle2012-11-17 01:38:45 (EST)
commit660a75531a7fab3095eabb2fc8e0de5250a30916 (patch)
tree4b8407478b70885ce2e66adb3e3ac65dfa40a0e5
parent2dbe81588e6e58bd1f859dccb595fb5d76d2740b (diff)
downloadorg.eclipse.cdt-660a75531a7fab3095eabb2fc8e0de5250a30916.zip
org.eclipse.cdt-660a75531a7fab3095eabb2fc8e0de5250a30916.tar.gz
org.eclipse.cdt-660a75531a7fab3095eabb2fc8e0de5250a30916.tar.bz2
Bug 348387 - fp in ReturnChecker using try/catch
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java9
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java22
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cfg/ControlFlowGraphTest.java4
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java38
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/cfg/IBranchNode.java13
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 07825aa..26483db 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 22076c9..058ad12 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 63d226a..dd6c6d2 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 7558446..a350756 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 ec0005d..a4e7820 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