Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-03-19 15:43:00 -0400
committerMarco Stornelli2019-03-21 14:02:27 -0400
commite70a63a424a193df50810f497bc2365d9f8796be (patch)
treebe2920972063407c9cc40a6adcbda7e693615392
parent8220215a2e35334b16ef48c76e9c9e33ba03d07e (diff)
downloadorg.eclipse.cdt-e70a63a424a193df50810f497bc2365d9f8796be.tar.gz
org.eclipse.cdt-e70a63a424a193df50810f497bc2365d9f8796be.tar.xz
org.eclipse.cdt-e70a63a424a193df50810f497bc2365d9f8796be.zip
Bug 519105 - Return checker for functions with noreturn
Added check in control flow graph to check if a function has noreturn attribute. Change-Id: Ieaa5984a337493e3aac12c0f6fbeeb91a754358b Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/META-INF/MANIFEST.MF2
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/cfg/ControlFlowGraphBuilder.java12
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java17
3 files changed, 30 insertions, 1 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.core.cxx/META-INF/MANIFEST.MF
index 216625793a..021072d9af 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.core.cxx/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.cdt.codan.core.cxx;singleton:=true
-Bundle-Version: 3.4.1.qualifier
+Bundle-Version: 3.4.100.qualifier
Bundle-Activator: org.eclipse.cdt.codan.core.cxx.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.cdt.core,
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 1770b4e101..9b7d955f91 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
@@ -49,8 +49,10 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
+import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
+import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
@@ -59,6 +61,8 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
@@ -270,6 +274,14 @@ public class ControlFlowGraphBuilder {
if (!(expression instanceof IASTFunctionCallExpression))
return false;
IASTExpression functionNameExpression = ((IASTFunctionCallExpression) expression).getFunctionNameExpression();
+ if (functionNameExpression instanceof IASTIdExpression) {
+ IASTName name = ((IASTIdExpression) functionNameExpression).getName();
+
+ IBinding binding = name.resolveBinding();
+ if (binding instanceof IFunction && ((IFunction) binding).isNoReturn()) {
+ return true;
+ }
+ }
return functionNameExpression.getRawSignature().equals("exit"); //$NON-NLS-1$
}
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
index 4965121c29..5fbd21a5ec 100644
--- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
@@ -487,4 +487,21 @@ public class ReturnCheckerTest extends CheckerTestCase {
public void testTemplateFunctionReturn_509751b() throws Exception {
checkSampleAboveCpp();
}
+
+ // [[noreturn]] void throwMe() {
+ // throw 1;
+ // }
+ // int foo(int bar) {
+ // switch(bar) {
+ // case 0:
+ // return 1;
+ // case 1:
+ // return 0;
+ // default:
+ // throwMe();
+ // }
+ // }
+ public void testFunctionWithAttribute_519105() throws Exception {
+ checkSampleAboveCpp();
+ }
}

Back to the top