GeezerVison is showing github.com — added lazy execution of ValueFlow via `DISABLE_VALUEFLOW=2` environme… · cppcheck-opensource/cppcheck@2b93752
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/token.h +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1162,6 +1162,8 @@ class CPPCHECKLIB Token { | 1162 | 1162 | } | 1163 | 1163 |
| 1164 | 1164 | const std::list<ValueFlow::Value>& values() const { | | 1165 | + if (mTokensFrontBack && !mTokensFrontBack->list->isValuesSet()) | | 1166 | + mTokensFrontBack->list->setValues(); | 1165 | 1167 | return mImpl->mValues ? *mImpl->mValues : TokenImpl::mEmptyValueList; | 1166 | 1168 | } | 1167 | 1169 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/tokenize.cpp +11-5Lines changed: 11 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2796,6 +2796,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration) | 2796 | 2796 | createSymbolDatabase(); | 2797 | 2797 | } | 2798 | 2798 |
| | 2799 | + // TODO: this accesses ValueFlow information before it has been generated | 2799 | 2800 | if (mTimerResults) { | 2800 | 2801 | Timer t("Tokenizer::simplifyTokens1::setValueType", mSettings->showtime, mTimerResults); | 2801 | 2802 | mSymbolDatabase->setValueTypeInTokenList(true); | @@ -2819,11 +2820,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration) | 2819 | 2820 | } | 2820 | 2821 | } | 2821 | 2822 |
| 2822 | | - // TODO: do not run valueflow if no checks are being performed at all - e.g. unusedFunctions only | 2823 | | - const char* disableValueflowEnv = std::getenv("DISABLE_VALUEFLOW"); | 2824 | | - const bool doValueFlow = !disableValueflowEnv || (std::strcmp(disableValueflowEnv, "1") != 0); | 2825 | | - | 2826 | | - if (doValueFlow) { | | 2823 | + auto setValues = [&](){ | 2827 | 2824 | if (mTimerResults) { | 2828 | 2825 | Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings->showtime, mTimerResults); | 2829 | 2826 | ValueFlow::setValues(&list, mSymbolDatabase, mErrorLogger, mSettings); | @@ -2832,6 +2829,15 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration) | 2832 | 2829 | } | 2833 | 2830 |
| 2834 | 2831 | mSymbolDatabase->setArrayDimensionsUsingValueFlow(); | | 2832 | + }; | | 2833 | + | | 2834 | + const char* disableValueflowEnv = std::getenv("DISABLE_VALUEFLOW"); | | 2835 | + const bool doLazyValueFlow = !disableValueflowEnv && (std::strcmp(disableValueflowEnv, "2") == 0); | | 2836 | + const bool doValueFlow = !disableValueflowEnv || (std::strcmp(disableValueflowEnv, "1") != 0); | | 2837 | + if (doLazyValueFlow) { | | 2838 | + list.setValuesFunc(std::move(setValues)); | | 2839 | + } else if (doValueFlow) { | | 2840 | + setValues(); | 2835 | 2841 | } | 2836 | 2842 |
| 2837 | 2843 | printDebugOutput(1); | |
Collapse file Copy file name to clipboardExpand all lines: lib/tokenlist.cpp +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,7 +49,9 @@ TokenList::TokenList(const Settings* settings) : | 49 | 49 | mTokensFrontBack(), | 50 | 50 | mSettings(settings), | 51 | 51 | mIsC(false), | 52 | | - mIsCpp(false) | | 52 | + mIsCpp(false), | | 53 | + mValuesSet(false), | | 54 | + mInSetValues(false) | 53 | 55 | { | 54 | 56 | mTokensFrontBack.list = this; | 55 | 57 | mKeywords.insert("asm"); | |
Collapse file Copy file name to clipboardExpand all lines: lib/tokenlist.h +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 |
| 26 | 26 | #include <cstddef> | 27 | 27 | #include <iosfwd> | | 28 | +#include <functional> | 28 | 29 | #include <string> | 29 | 30 | #include <unordered_set> | 30 | 31 | #include <vector> | @@ -207,6 +208,23 @@ class CPPCHECKLIB TokenList { | 207 | 208 |
| 208 | 209 | bool isKeyword(const std::string &str) const; | 209 | 210 |
| | 211 | + void setValuesFunc(std::function<void()> f) { | | 212 | + mValuesFunc = std::move(f); | | 213 | + } | | 214 | + | | 215 | + void setValues() const { | | 216 | + if (!mInSetValues && !mValuesSet && mValuesFunc) { | | 217 | + mInSetValues = true; | | 218 | + mValuesFunc(); | | 219 | + mValuesSet = true; | | 220 | + mInSetValues = false; | | 221 | + } | | 222 | + } | | 223 | + | | 224 | + bool isValuesSet() const { | | 225 | + return mValuesSet; | | 226 | + } | | 227 | + | 210 | 228 | private: | 211 | 229 | void determineCppC(); | 212 | 230 |
| @@ -227,6 +245,10 @@ class CPPCHECKLIB TokenList { | 227 | 245 | /** File is known to be C/C++ code */ | 228 | 246 | bool mIsC; | 229 | 247 | bool mIsCpp; | | 248 | + | | 249 | + std::function<void()> mValuesFunc; | | 250 | + mutable bool mValuesSet; | | 251 | + mutable bool mInSetValues; | 230 | 252 | }; | 231 | 253 |
| 232 | 254 | /// @} | |
|