Two solution proposals for TRAC #7567 ("(a | 7) > 6U" is always true ...)#816
Two solution proposals for TRAC #7567 ("(a | 7) > 6U" is always true ...)#816bartlomiejgrzeskowiak wants to merge 1 commit into
Conversation
I agree. I would like if we always used the same name. |
|
I want to avoid copy paste. so basically the compact is better. I would recommend that we reorder the code: |
thanks. it would not be totally wrong. but I think I prefer that you don't do it here. those lines are not near your changes. I like that you try to see if there is an opportunity to cleanup the code. |
I agree it's strange with negative values. I would feel 99% confident about saying that (i|7>0) is always true even though i is signed. Off the top of my head I can't give a example in real code where negative values are used in bitoperations. I also agree that ">,>=,<,<=" are strange. |
I hope we don't warn about '(X | max(X)) == max(X)'. Consider: That is always true on a 16-bit platform. But I think we should assume the code is portable and might be executed on other platforms also. |
|
|
||
| for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { | ||
| if (Token::Match(tok, "==|!=|>")) { | ||
| if (Token::Match(tok, "==|!=|>|>=|<|<=")) { |
There was a problem hiding this comment.
could you please replace this with a:
if (!tok->isComparisonOp())
continue;
|
It looks pretty good now. I am thinking about splitting the tests into three test functions. the checker checks "==|!=", "&" and "|" separately. so we could have separate test functions for those. what do you think? |
| } else if (expr1->str() == "&") { | ||
| const bool or_equal = Token::Match(tok, ">=|<="); | ||
| const std::string& op(tok->str()); | ||
| if ((Token::Match(tok, ">=|<")) && |
There was a problem hiding this comment.
I would write this condition on 1 line
|
I am not sure about splitting test functions. It will brake the concept of same names for checker/test function names. Secondly comparison function is for huge in my opinion. But, you are the boss ;) I can split it by for example: |
|
Thanks! I applied this with 09a83f2. I think splitting the testfunction is optional, it's not required. |
This is a solution proposal for TRAC #7567 and all "==|!=|>|>=|<|<=" comparisons. I will appreciate your opinions especially about:
My consideration is "Expression '(X & 0x0) == 0x0' is always true", and "Expression '(X | max(X)) == max(X)' is always true for unsigned X". Is there any way to check max(X) ?
TRAC fixed #13906 -
ErrorMessage::FileLocationdid not simplify the file in all cases #7567: distinct implementationTRAC fixed #13906 -
ErrorMessage::FileLocationdid not simplify the file in all cases #7567: compact implementation