1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

Bug 316076 - fixed f.p. when using gcc annotation about no return

This commit is contained in:
Alena Laskavaia 2012-04-16 21:56:57 -04:00
parent 751d4a45f0
commit 77a06573a9
3 changed files with 53 additions and 0 deletions

View file

@ -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$
}
}

View file

@ -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]);
}
}

View file

@ -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();
}
}