[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] False positives with Codan using Avr-gcc toolchain
|
I've reconsidered and modified my patch - please see attached, I'll look at testing and submitting via gerrit ASAP, in the meantime, can someone look at and check my code - I'm not familiar with the API and it's very possible I've made a silly mistake or assumed too much.
I've moved the checks to the better position (lets assume that things get worse) so that there shouldn't be any impact on performance - however if we cannot feasibly garauntee that we check for this statement being the last in the a Statement-_expression_, the cheaper option is to not walking inside of it and have a single check before we go down the "hasNoEffect" branch
--- StatementHasNoEffectChecker.java Thu Apr 24 12:40:40 2014
+++ StatementHasNoEffectChecker.java Fri Apr 25 12:22:06 2014
@@ -68,6 +68,25 @@
return PROCESS_CONTINUE;
}
+ private boolean isFinalStatementExpression(IASTExpression e) {
+ // check if it is part of GNU comp stmt expression i.e. ({foo();a;})
+ IASTNode stmt = e.getParent();
+ if (stmt instanceof IASTExpressionStatement) {
+ IASTNode parentComp = stmt.getParent();
+ if (parentComp instanceof IASTCompoundStatement) {
+ IASTNode parentStmtExpr = parentComp.getParent();
+ if (parentStmtExpr instanceof IGNUASTCompoundStatementExpression) {
+ // Is it the final statement in the statement-expression?
+ // NOTE: Presumes that the array returned is in the same order as presented in the source
+ // NOTE: Presumes that the expression is the actual expression, and not a copy.
+ IASTNode childlist[] = parentComp.getChildren();
+ if (stmt == childlist[childlist.length-1])
+ return true;
+ }
+ }
+ }
+ return false;
+ }
/**
* We consider has not effect binary statements without assignment and
* unary statement which is not dec and inc. If operator is overloaded
@@ -88,7 +107,7 @@
case IASTBinaryExpression.op_logicalAnd:
return hasNoEffect(binExpr.getOperand1()) && hasNoEffect(binExpr.getOperand2());
}
- return true;
+ return isFinalStatementExpression(e) ? false : true;
}
if (e instanceof IASTUnaryExpression) {
IASTUnaryExpression unaryExpr = (IASTUnaryExpression) e;
@@ -105,22 +124,11 @@
case IASTUnaryExpression.op_bracketedPrimary:
return hasNoEffect(unaryExpr.getOperand());
}
- return true;
+ return isFinalStatementExpression(e) ? false : true;
}
// simply a;
if (e instanceof IASTIdExpression) {
- // check if it is part of GNU comp stmt expression i.e. ({foo();a;})
- IASTNode parent = e.getParent();
- if (parent instanceof IASTExpressionStatement) {
- IASTNode parent2 = parent.getParent();
- if (parent2 instanceof IASTCompoundStatement) {
- IASTNode parent3 = parent2.getParent();
- if (parent3 instanceof IGNUASTCompoundStatementExpression) {
- return false;
- }
- }
- }
- return true;
+ return isFinalStatementExpression(e) ? false : true;
}
return false;
}