-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix #12861 Hang in valueFlowCondition() with huge array #7757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Please add a test in |
The test already exists and it is the one failing with this change applied. So somehow this actually makes things worse. |
Yes, I will check it again. If I can't fix it, I will ignore this PR. |
I updated the commit. For the test case submitted by the ticket #12861, the performance is improved a lot, at least the consumed time can be reduced to less than 2 seconds. For other test cases, I don't have the exact testing data, but I think this can be helpful for the performance. |
Is there a reason not to implement caching in the regular |
Hi CHR, the process of creating the AST tree is a little complicated for me currently, and I can't figure out the details, that is also why I didn't modify the createAst(). As I understand, during TokenList::createAst(), the astTop() is used. But at that time, the createAst() has not been finished, so the top is a temporary one, which can not be cached as the final top. So we need two versions of the function, one is for creating ast, and another with the cache function is for the usage after the ast is created. |
I think this sounds reasonable: |
7032692
to
ca60f59
Compare
lib/token.h
Outdated
@@ -27,6 +27,7 @@ | |||
#include "templatesimplifier.h" | |||
#include "utils.h" | |||
#include "vfvalue.h" | |||
#include "tokenlist.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary.
@@ -1531,17 +1532,31 @@ class CPPCHECKLIB Token { | |||
return nullptr; | |||
|
|||
} | |||
RET_NONNULL Token *astTop() { | |||
/** If the ast tree has not been created, pls make sure to use cache=false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the "pls" :-)
|
I tested the fix based on 4617bc2.
Use the cppcheck to check the below code which is submitted on the ticket #12861.
With the fix, the overall time is 1.52582s.
Without the fix, the time is 25.9674s.
I also tested the testrunner for running the whole of the unit tests. There is some performance improment with the fix, but not remarkable.