Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2012-04-16 21:56:57 -0400
committerAlena Laskavaia2012-04-16 21:56:57 -0400
commit77a06573a9ac854ef0e75b021f39625a7a6dc3ff (patch)
tree7cb1d70cfc839eb78c1a3a9cf284929e7f476af1
parent751d4a45f034e8174df9cd27adbc0c1d9192f871 (diff)
downloadorg.eclipse.cdt-77a06573a9ac854ef0e75b021f39625a7a6dc3ff.tar.gz
org.eclipse.cdt-77a06573a9ac854ef0e75b021f39625a7a6dc3ff.tar.xz
org.eclipse.cdt-77a06573a9ac854ef0e75b021f39625a7a6dc3ff.zip
Bug 316076 - fixed f.p. when using gcc annotation about no return
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java8
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java33
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java12
3 files changed, 53 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
index 4f4dc1560f..6bb0baf624 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
@@ -406,6 +406,14 @@ public final class CxxAstUtils {
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!=null && 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.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java
index 7e4c036ca0..9d44246b2b 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java
@@ -100,4 +100,37 @@ public class CxxAstUtilsTest extends CodanFastCxxAstTestCase {
assertTrue((Boolean) result[0]);
assertFalse((Boolean) result[1]);
}
+
+ //void f() __attribute__((noreturn));
+ //
+ //int test() {
+ // a();
+ // f();
+ // exit(0);
+ //}
+ public void testExitStatement() throws IOException {
+ String code = getAboveComment();
+ IASTTranslationUnit tu = parse(code);
+ final Object result[] = new Object[4];
+ ASTVisitor astVisitor = new ASTVisitor() {
+ int i;
+ {
+ shouldVisitStatements = true;
+ }
+
+ @Override
+ public int visit(IASTStatement stmt) {
+ boolean check = CxxAstUtils.isExitStatement(stmt);
+ result[i] = check;
+ i++;
+ return PROCESS_CONTINUE;
+ }
+ };
+ tu.accept(astVisitor);
+ assertNotNull("Stmt not found", result[0]); //$NON-NLS-1$
+ assertFalse((Boolean) result[0]); // compound body
+ assertFalse((Boolean) result[1]);
+ assertTrue((Boolean) result[2]);
+ assertTrue((Boolean) result[3]);
+ }
}
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 95519bf9fb..75584462eb 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
@@ -298,4 +298,16 @@ public class ReturnCheckerTest extends CheckerTestCase {
loadCodeAndRunCpp(getAboveComment());
checkNoErrors();
}
+
+
+//void f() __attribute__((noreturn));
+//
+//int test() {
+// f();
+//}
+
+ public void testNoReturn() {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
} \ No newline at end of file

Back to the top