[
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 dug out the codan analyser source and looked thought about it some, based on what you've said [Nathan] - it seems to me that the logic for this scenario can never flag true for a statement-_expression_, as all C operations will return either void (valid for statement-expressions according to the manual) or otherwise be valid R-values. The only other thing to check for is perhaps a void return from a statement-_expression_, being assigned to an Lvalue, but that will show up as a compile error (I believe, I may be wrong...), rather than a "statement has no effect" type bug.
Based on that, I've made some adjustments to the .java file for that checker and attached a patch file (apologies if it's not perfect, I'm on a windows machine at the moment behind a troublesome proxy, I've copied and pasted the source into a.txt file and used that to generate the patch)
Chris
--- StatementHasNoEffectChecker.java Thu Apr 24 12:40:29 2014
+++ StatementHasNoEffectChecker.java Thu Apr 24 12:44:56 2014
@@ -77,6 +77,20 @@
* @return
*/
private boolean hasNoEffect(IASTExpression e) {
+ // check if it is part of GNU comp stmt expression i.e. ({foo();a;})
+ // Based on the premise that all statements are valid R-Values in their own right,
+ // therefore if it belongs to a compound statement, it will be valid
+ // otherwise fallthrough and make other checks
+ 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;
+ }
+ }
+ }
if (e instanceof IASTBinaryExpression) {
IASTBinaryExpression binExpr = (IASTBinaryExpression) e;
if (isPossibleAssignment(binExpr))
@@ -109,17 +123,6 @@
}
// 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 false;