Skip to content

Fix #11483 FN unusedFunction for method with inline implementation#4692

Closed
chrchr-github wants to merge 11 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix11483
Closed

Fix #11483 FN unusedFunction for method with inline implementation#4692
chrchr-github wants to merge 11 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix11483

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

@chrchr-github chrchr-github marked this pull request as draft January 8, 2023 00:30
return _next;
}

/** IntValue interprets the attribute as an integer, and returns the value.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not change external files. Put it in the suppression file.

Comment thread lib/library.h
}

/** get allocation id for function by name (deprecated, use other alloc) */
// cppcheck-suppress unusedFunction - only used in unit tests

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop the mention of unit tests for obvious helper functions like this. Same for the other methods in this file.

I will review this in more detail later on though.

Comment thread lib/symboldatabase.h
return const_cast<Scope *>(this->findScope(tok, const_cast<const Scope *>(startScope)));
}

bool isVarId(nonneg int varid) const {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this for now.

Comment thread lib/token.h
void isSigned(const bool sign) {
setFlag(fIsSigned, sign);
}
bool isPointerCompare() const {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this even if it isn't used. Same for the other methods in this file.

Comment thread .github/workflows/selfcheck.yml Outdated
if: false # TODO: fails with preprocessorErrorDirective - see #10667
run: |
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --enable=unusedFunction --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --enable=unusedFunction --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr -icmake.output.notest

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not ignore the generated files.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also lead to false positives since function declarations are missing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as suppressions don't work, this is dead in the water anyway. The problem seems to be related to the way included code is handled.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - this is causing the "false positives" in the GUI code. Please revert this.

@firewave

firewave commented Jan 9, 2023

Copy link
Copy Markdown
Collaborator

No need to close this. The change is good.

There's several issues with suppressions. Some of them also keeping me from finishing some PRs.

@chrchr-github

Copy link
Copy Markdown
Collaborator Author

Uhmm, I see no obvious way to fix this. The warning is produced for a location in the .cpp file, whereas the suppression is in the header file. All tokens from the included file are assigned the same line in the .cpp, so that their actual origin is lost.

@firewave firewave reopened this Jan 9, 2023
@firewave

Copy link
Copy Markdown
Collaborator

I added a test for this case here: firewave@2d8d48c. The location is wrong when the fix is applied. So this might be a place to start at.

@firewave

firewave commented Mar 4, 2023

Copy link
Copy Markdown
Collaborator

I want to finish up with my suppression and platform stuff first and will take a look afterwards. I have a few things to look at in simplecpp anyways and will do it along the way.

@firewave

Copy link
Copy Markdown
Collaborator

Uhmm, I see no obvious way to fix this. The warning is produced for a location in the .cpp file, whereas the suppression is in the header file. All tokens from the included file are assigned the same line in the .cpp, so that their actual origin is lost.

This is not a simplecpp issue it seems.

The line is actually correct just the filename isn't. The problem is there is no file context for the token and we just use the source filename from the TokenList without even considering the fileIndex.

We probably need to add all include files to the TokenList.mFiles (there's mOrigFiles which should indicate we did not supply that as input) and store the proper file index in the Token.

There might be a different way though as we do report other issues from headers with the proper filename.

I updated the branch with that test: https://github.com/firewave/cppcheck/commits/inc-test

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's TokenList::file() as convenience function. Didn't know about that until yesterday,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, me neither.
So just using the correct filename fixes the problem with the location. For some reason, I thought the index was also necessary.

@firewave

Copy link
Copy Markdown
Collaborator

Please add a test and look at the open conversations.

We should suppress the warning for all externals.

I think the GUI warnings with the overrides might be false positives maybe related to something I already reported. I will take a look later. The other one is related to commented code and should be commented instead of being removed - see #4688.

@chrchr-github

Copy link
Copy Markdown
Collaborator Author

Please feel free to take over. You already found the solution, and I'm kinda tired of messing with this.

@firewave

Copy link
Copy Markdown
Collaborator

I just gave a few pointers so this could advance. This is probably far from a solution as during debugging I did not see more than a single file ever being stored in the TokenList and it seems the only fileIndex every used was 0. So it appears the functionality is there but all the hookups are missing. I have no idea what kind of ripple effect this might have.

And imagine how tired I am that I have to wait weeks/months for things to be reviewed at all...and the countless conflicts I have to resolve all the time because of that. And I already stated that I am not able to look into things beyond the one I am still working on, sorry.

@chrchr-github chrchr-github deleted the chr_Fix11483 branch May 22, 2023 19:02
@firewave

Copy link
Copy Markdown
Collaborator

I think I figured out the problem - at least within the unit test. The fileIndex is correct in the simplecpp::TokenList but then we get the processed code as a whole and that lacks any information about the file and we pass that to the analysis in the test. So it could just be an issues in the unit tests. The preprocessing in the tests is also not the same as in the production code.

@firewave

Copy link
Copy Markdown
Collaborator

The tests in #5281 show that the suppressions are working as expected. The failure in the unit tests is caused by the way we preprocess code for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants