From 7577bdb1dfcdf449b27aac4f7d32a74819ca1d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 31 Mar 2020 11:33:22 +0200 Subject: [PATCH] DACA: Try to avoid some crashes/hangs for the most crazy code so we can focus on most serious bugs first --- cli/cmdlineparser.cpp | 1 + lib/settings.cpp | 1 + lib/settings.h | 3 +++ lib/tokenize.cpp | 14 ++++++++++++++ 4 files changed, 19 insertions(+) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 785a4f991..f517107f0 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -664,6 +664,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings->templateFormat = "{file}:{line}:{column}: warning: {message} [{id}]\\n{code}"; mSettings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}"; } else if (mSettings->templateFormat == "daca2") { + mSettings->daca = true; mSettings->templateFormat = "{file}:{line}:{column}: {severity}: {message} [{id}]"; mSettings->templateLocation = "{file}:{line}:{column}: note: {info}"; } else if (mSettings->templateFormat == "vs") diff --git a/lib/settings.cpp b/lib/settings.cpp index 589e18437..b48158771 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -36,6 +36,7 @@ Settings::Settings() checkUnusedTemplates(false), clang(false), clangTidy(false), + daca(false), debugSimplified(false), debugnormal(false), debugwarnings(false), diff --git a/lib/settings.h b/lib/settings.h index 0e5aaad0f..8cc9eafa4 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -105,6 +105,9 @@ public: /** @brief include paths excluded from checking the configuration */ std::set configExcludePaths; + /** @brief Are we running from DACA script? */ + bool daca; + /** @brief Is --debug-simplified given? */ bool debugSimplified; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c82a6c7fd..d9ee852e2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4297,6 +4297,20 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) } } + // Some special bailouts in DACA. To avoid too much hangs/crashes. + // FIXME: This is hopefully temporary. Somehow it should not be used in releases. + if (mSettings->daca) { + int numcase = 0; + for (const Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::Match(tok, "%name% [ %num% ] = {") && MathLib::toLongNumber(tok->strAt(2)) > 10000) + return false; + if (tok->str() == "case") { + if (++numcase > 10000) + return false; + } + } + } + // Is there C++ code in C file? validateC();