Fix #14717 (FP: same exprId for different expressions leads to wrong redundantAssignment)#8520
Fix #14717 (FP: same exprId for different expressions leads to wrong redundantAssignment)#8520danmar wants to merge 2 commits intocppcheck-opensource:mainfrom
Conversation
…redundantAssignment)
|
The problem I saw was that followAllReferences() looked at ternary operator operands. The second operand was "1" for both expressions and then the parent "/" got the same exprId. I have the feeling we have tweaked some handling for ternary operators recently. But very strange that bisect was pointing at other commits.. |
As mentioned in the comment Visual Studio builds are non-deterministic and somehow Linux builds have consistent results but they might flip with each commit. So regular bisecting is completely impossible. |
|
The fix feels too intrusive for such an subtle issue. Looking at |
It wasn't that recently - the issue was introduced in the 2.19 dev cycle. |
|
And this doesn't seem to address the potentially duplicated exprId pointed out in https://trac.cppcheck.net/ticket/14717#comment:12. |
I am not sure I understand the debug output in comment:12 but doesn't it say that the operand1 for the |
That is actually an issue. correct: incorrect: |
That needs to be fixed inside |
That appears to be a non-issue. The logging was just confusing as I was printing the op the exprId was looked up from and not the actual token belonging to the exprId. |
I am not sure if the Token::index() has been assigned yet. but if it has that would be more stable. The location will not work well there are many simplifications that will not give tokens unique locations. No matter if we make the order fixed or not we need to ensure that we don't take the expression ids of the ternary operator operands.. When a ternary operator expression is |
As a first step we need to make the order stable regardless of the ternary issues. |
I don't think that suggestion would work well.
It's not clear to me why? the important thing is that we pick the proper |
My intention with my fix is that the order does not matter. My goal was to pick the expression id from the same ref token no matter if refs are order (ref1,ref2) or (ref2,ref1). |
| continue; | ||
| } | ||
|
|
||
| const auto getExprIdForOperand = [](const Token* tok) -> int { |
There was a problem hiding this comment.
This could just be a function since it does capture anything.
No description provided.