From d0e68e0d777fa29bcad3bb296171ad7a4c86fa76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 11 Dec 2021 12:42:15 +0100 Subject: [PATCH] misra; add rule 17.3 --- addons/cppcheckdata.py | 8 ++++++++ addons/misra.py | 6 ++++++ lib/cppcheck.cpp | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 7f6f9fb1e..573e3b329 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -812,6 +812,7 @@ class Configuration: typedefInfo = [] valueflow = [] standards = None + clang_warnings = [] def __init__(self, name): self.name = name @@ -825,6 +826,7 @@ class Configuration: self.typedefInfo = [] self.valueflow = [] self.standards = Standards() + self.clang_warnings = [] def set_tokens_links(self): """Set next/previous links between tokens.""" @@ -1063,6 +1065,12 @@ class CppcheckData: cfg = None cfg_arguments = [] + elif node.tag == 'clang-warning' and event == 'start': + cfg.clang_warnings.append({'file': node.get('file'), + 'line': int(node.get('line')), + 'column': int(node.get('column')), + 'message': node.get('message')}) + # Parse standards elif node.tag == "standards" and event == 'start': continue diff --git a/addons/misra.py b/addons/misra.py index b0e9bb8ca..a815295aa 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -3126,6 +3126,11 @@ class MisraChecker: self.reportError(tok, 17, 2) tok = tok.next + def misra_17_3(self, cfg): + for w in cfg.clang_warnings: + if w['message'].endswith('[-Wimplicit-function-declaration]'): + self.reportError(cppcheckdata.Location(w), 17, 3) + def misra_17_6(self, rawTokens): for token in rawTokens: if simpleMatch(token, '[ static'): @@ -4339,6 +4344,7 @@ class MisraChecker: self.executeCheck(1607, self.misra_16_7, cfg) self.executeCheck(1701, self.misra_17_1, cfg) self.executeCheck(1702, self.misra_17_2, cfg) + self.executeCheck(1702, self.misra_17_3, cfg) if cfgNumber == 0: self.executeCheck(1706, self.misra_17_6, data.rawTokens) self.executeCheck(1707, self.misra_17_7, cfg) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index bb4db555b..2b99f7241 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -371,7 +371,7 @@ const char * CppCheck::extraVersion() return ExtraVersion; } -static bool reportClangErrors(std::istream &is, std::function reportErr) +static bool reportClangErrors(std::istream &is, std::function reportErr, std::vector *warnings) { std::string line; while (std::getline(is, line)) { @@ -381,6 +381,8 @@ static bool reportClangErrors(std::istream &is, std::functionpush_back(errmsg); + continue; + } + reportErr(errmsg); return true; @@ -459,19 +467,20 @@ unsigned int CppCheck::check(const std::string &path) } // Ensure there are not syntax errors... + std::vector compilerWarnings; if (!mSettings.buildDir.empty()) { std::ifstream fin(clangStderr); auto reportError = [this](const ErrorMessage& errorMessage) { reportErr(errorMessage); }; - if (reportClangErrors(fin, reportError)) + if (reportClangErrors(fin, reportError, &compilerWarnings)) return 0; } else { std::istringstream istr(output2); auto reportError = [this](const ErrorMessage& errorMessage) { reportErr(errorMessage); }; - if (reportClangErrors(istr, reportError)) + if (reportClangErrors(istr, reportError, &compilerWarnings)) return 0; } @@ -496,6 +505,8 @@ unsigned int CppCheck::check(const std::string &path) createDumpFile(mSettings, path, tokenizer.list.getFiles(), nullptr, fdump, dumpFile); if (fdump.is_open()) { fdump << "" << std::endl; + for (const ErrorMessage& errmsg: compilerWarnings) + fdump << " \n"; fdump << " " << std::endl; fdump << " " << std::endl; fdump << " " << std::endl;