◐ Shell
clean mode source ↗

fixed #11342 - cache `Library::getFunctionName()` calls in `Token` by firewave · Pull Request #7573 · cppcheck-opensource/cppcheck

@firewave

cppcheck: build/token.cpp:3128: const std::string &Token::funcname(const Library &) const: Assertion `*mImpl->mFuncName == library.getFunctionName(this)' failed.
Internal error: cppcheck received signal SIGABRT - abort or assertion
Callstack:
#0  0x562da7e19d1c in Token::funcname[abi:cxx11](Library const&) const
#1  0x562da7d8cb93 in Library::returnValueType[abi:cxx11](Token const*) const
#2  0x562da7bb086e in SymbolDatabase::setValueTypeInTokenList(bool, Token*)
#3  0x562da7ba70bb in SymbolDatabase::SymbolDatabase(Tokenizer&, Settings const&, ErrorLogger&)

Library::returnValueType() checks if the given token isNotLibraryFunction(). This looks wrong to me because I would expect that the given token is supposed to be a type. Or is the wrong token passed into this?

@firewave

Library::returnValueType() checks if the given token isNotLibraryFunction(). This looks wrong to me because I would expect that the given token is supposed to be a type. Or is the wrong token passed into this?

Still that shouldn't produce different results on subsequent calls on the same token. Since the library is immutable it seems like this is caused by some tokenizing/simplification.

@firewave

The problem is that the astParent() is set on later calls.

From TestClass::memsetOnClass:

000001FE7416C2E0 astParent: 0000000000000000 previous: 000001FE7416DBA0 size
[...]
000001FE7416C2E0 astParent: 000001FE7416DBA0 previous: 000001FE7416DBA0 size std::vector::size
Assertion failed: *mImpl->mFuncName == library.getFunctionName(this), file S:\GitHub\cppcheck-fw\lib\token.cpp, line 273

danmar

if (!mImpl->mFuncName)
mImpl->mFuncName = new std::string(library.getFunctionName(this));
const std::string fname = library.getFunctionName(this);
std::cout << this << " astParent: " << astParent() << " previous: " << previous() << " " << stringify(stringifyOptions::forDebug()) << " " << fname << std::endl;

Choose a reason for hiding this comment

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

I assume that this is debug code that will be removed?

Choose a reason for hiding this comment

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

still WIP - I forgot to mark it a draft.

@danmar

I assume there is speedup but do you see it also?

@firewave

I assume there is speedup but do you see it also?

Since it is still a draft (and not working as expected) I did not provide performance data yet. It is about 2-4% of the total Ir - that is also mentioned in the ticket.