Skip to content

fixes #11104 (avoid C++-only parsing when processing C code in parsedecl()) / also avoid remaining Library::detect*() calls#5346

Merged
chrchr-github merged 4 commits into
cppcheck-opensource:mainfrom
firewave:parsedecl-cpp
Aug 18, 2023
Merged

fixes #11104 (avoid C++-only parsing when processing C code in parsedecl()) / also avoid remaining Library::detect*() calls#5346
chrchr-github merged 4 commits into
cppcheck-opensource:mainfrom
firewave:parsedecl-cpp

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

@firewave firewave commented Aug 18, 2023

No description provided.

@firewave firewave changed the title fixed #11104 (avoid C++-only parsing when processing C code in parsedecl()) - retrieve C++ flag from given token refs #11104 (avoid C++-only parsing when processing C code in parsedecl()) - retrieve C++ flag from given token Aug 18, 2023
@firewave firewave marked this pull request as draft August 18, 2023 16:00
@firewave firewave changed the title refs #11104 (avoid C++-only parsing when processing C code in parsedecl()) - retrieve C++ flag from given token fixes #11104 (avoid C++-only parsing when processing C code in parsedecl()) / also avoid remaining Library::detect*() calls Aug 18, 2023
@firewave firewave marked this pull request as ready for review August 18, 2023 16:37
Comment thread lib/symboldatabase.cpp Outdated
}
}
if (tok->astParent() && Token::Match(tok->astOperand1(), "%name%|::")) {
if (tok->astParent() && tok->astOperand1() && tok->astOperand1()->isCpp() && Token::Match(tok->astOperand1(), "%name%|::")) {
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.

Is it possible to use tok->astParent()->isCpp()?

Copy link
Copy Markdown
Collaborator Author

@firewave firewave Aug 18, 2023

Choose a reason for hiding this comment

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

It could just be tok->isCpp() as it is global for all tokens from the same list.

I chose that since it was the underlying token we work from for the detection.

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.

I will adjust that. I missed some unnecessary calls.

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.

Done. There was an even cleaner solution.

@firewave firewave marked this pull request as draft August 18, 2023 16:51
@firewave
Copy link
Copy Markdown
Collaborator Author

With all the underlying improvements to the culprit the impact has severely lessened (at least for this project) but here's some numbers scanning mame_regtest with --enable=all --inconclusive:

Clang 15 4,739,448,715 -> 4,728,480,149

@firewave
Copy link
Copy Markdown
Collaborator Author

Okay so fIsClass also indicates if it is a struct in the dump. That was unexpected.

@firewave firewave marked this pull request as ready for review August 18, 2023 17:35
@chrchr-github
Copy link
Copy Markdown
Collaborator

Okay so fIsClass also indicates if it is a struct in the dump. That was unexpected.

Sorry, I don't follow. Different PR?

@firewave
Copy link
Copy Markdown
Collaborator Author

Sorry, I don't follow. Different PR?

No, I made the whole following block with flags in Variable::evaluate() C++-only but that lead to MISRA addon test failures (an indicator we are lacking unit tests) because fIsClass wasn't set:

    if (mTypeStartToken) {
        std::string strtype = mTypeStartToken->str();
        for (const Token *typeToken = mTypeStartToken; Token::Match(typeToken, "%type% :: %type%"); typeToken = typeToken->tokAt(2))
            strtype += "::" + typeToken->strAt(2);
        setFlag(fIsClass, !lib->podtype(strtype) && !mTypeStartToken->isStandardType() && !isEnumType() && !isPointer() && !isReference() && strtype != "...");
        setFlag(fIsStlType, Token::simpleMatch(mTypeStartToken, "std ::"));
        setFlag(fIsStlString, ::isStlStringType(mTypeStartToken));
        setFlag(fIsSmartPointer, lib->isSmartPointer(mTypeStartToken));
    }

@chrchr-github chrchr-github merged commit a92b10c into cppcheck-opensource:main Aug 18, 2023
@firewave firewave deleted the parsedecl-cpp branch August 18, 2023 20:56
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