mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 18:25:40 +02:00
Bug 316076 - fixed f.p. when using gcc annotation about no return
This commit is contained in:
parent
751d4a45f0
commit
77a06573a9
3 changed files with 53 additions and 0 deletions
|
@ -406,6 +406,14 @@ public final class CxxAstUtils {
|
||||||
if (!(expression instanceof IASTFunctionCallExpression))
|
if (!(expression instanceof IASTFunctionCallExpression))
|
||||||
return false;
|
return false;
|
||||||
IASTExpression functionNameExpression = ((IASTFunctionCallExpression) expression).getFunctionNameExpression();
|
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$
|
return functionNameExpression.getRawSignature().equals("exit"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,4 +100,37 @@ public class CxxAstUtilsTest extends CodanFastCxxAstTestCase {
|
||||||
assertTrue((Boolean) result[0]);
|
assertTrue((Boolean) result[0]);
|
||||||
assertFalse((Boolean) result[1]);
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,4 +298,16 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
loadCodeAndRunCpp(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//void f() __attribute__((noreturn));
|
||||||
|
//
|
||||||
|
//int test() {
|
||||||
|
// f();
|
||||||
|
//}
|
||||||
|
|
||||||
|
public void testNoReturn() {
|
||||||
|
loadCodeAndRun(getAboveComment());
|
||||||
|
checkNoErrors();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue