cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

LCppC backports: Refactorizations/Optimizations

Open PKEuS opened this issue 2 years ago • 4 comments

PKEuS avatar Jun 11 '22 13:06 PKEuS

I needed some time to find out what is going on here... Why does it fail only in unix builds? What is failing? testclangimport.cpp is not compiled on Windows at all...

PKEuS avatar Jun 11 '22 14:06 PKEuS

It seems like that (useless) clang import code stores Variable* that get invalidated while function arguments are being added. Fixed that, however, I would still suggest to remove that clang import parser as I do not see why cppcheck needs that.

PKEuS avatar Jun 11 '22 14:06 PKEuS

Fixed that, however, I would still suggest to remove that clang import parser as I do not see why cppcheck needs that.

I think it can be discussed. However there are people that do use it. And I have the feeling that clang can do a better job than cppcheck ever will with complex templates etc..

There are some fundamental problems with the cppcheck parser that would be very hard to solve. The template simplifier does not have the complete type information always we would need to instantiate templates and build asts and determine types together not having separated steps.

I am not interested to just remove clang import but maybe it can be provided in another way.

danmar avatar Jun 11 '22 14:06 danmar

And I have the feeling that clang can do a better job than cppcheck ever will with complex templates etc..

We dont just have a problem with complex templates, we also dont handle template functions, overload resolution(even for non-templates), concept auto, and generic lambdas. We may not throw syntax errors for these issues, but we there are FPs and FNs because of either misplaced or missing type information.

This is why having clang import is good to have, and it would be nice if it could grow into something more sustainable.

The template simplifier does not have the complete type information always we would need to instantiate templates and build asts and determine types together not having separated steps.

I think I mentioned before that we could run the template simplifier after ast and symboldb so it could start taking advantage of that information. As a shortcut we could rebuild ast and symboldb from scratch, but even better would be for copyTokens to preserve the ast and symboldb information or run ast and symboldb over a partial set of tokens.

Even if we can't instantiate the template it would still be good to set the type information for template parameters, which could help some analysis. We already handle incomplete types so if we could treat templates as an incomplete type it would help as well.

I think we could improve this without needing a major rewrite, but still would be a decent amount of work to do. Either way, it still wont be as good clang's parser.

pfultz2 avatar Jun 11 '22 16:06 pfultz2

The changes look fine. I would prefer having the Visual Studio solution changes in a separate PR though.

FYI I have an idea on how to easily dmake the moving parts of the project files so these things should no longer split through in the future.

firewave avatar Aug 20 '22 20:08 firewave