cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

fixed #11342 - cache `Library::getFunctionName()` calls in `Token`

Open firewave opened this issue 6 months ago • 5 comments

firewave avatar Jun 05 '25 10:06 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 avatar Jun 05 '25 11:06 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 avatar Jun 05 '25 22:06 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

firewave avatar Jun 05 '25 22:06 firewave

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

danmar avatar Jun 09 '25 10:06 danmar

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.

firewave avatar Jun 10 '25 11:06 firewave