mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
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>
This commit is contained in:
parent
8220215a2e
commit
e70a63a424
3 changed files with 30 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue