misra; add rule 17.3

This commit is contained in:
Daniel Marjamäki 2021-12-11 12:42:15 +01:00
parent f64097465f
commit d0e68e0d77
3 changed files with 28 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -371,7 +371,7 @@ const char * CppCheck::extraVersion()
return ExtraVersion;
}
static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMessage&)> reportErr)
static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMessage&)> reportErr, std::vector<ErrorMessage> *warnings)
{
std::string line;
while (std::getline(is, line)) {
@ -381,6 +381,8 @@ static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMe
std::string::size_type pos3 = line.find(": error: ");
if (pos3 == std::string::npos)
pos3 = line.find(": fatal error:");
if (warnings && pos3 == std::string::npos)
pos3 = line.find(": warning:");
if (pos3 == std::string::npos)
continue;
@ -408,6 +410,12 @@ static bool reportClangErrors(std::istream &is, std::function<void(const ErrorMe
msg,
"syntaxError",
Certainty::normal);
if (line.compare(pos3, 10, ": warning:") == 0) {
warnings->push_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<ErrorMessage> 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 << "<dump cfg=\"\">" << std::endl;
for (const ErrorMessage& errmsg: compilerWarnings)
fdump << " <clang-warning file=\"" << toxml(errmsg.callStack.front().getfile()) << "\" line=\"" << errmsg.callStack.front().line << "\" column=\"" << errmsg.callStack.front().column << "\" message=\"" << toxml(errmsg.shortMessage()) << "\"/>\n";
fdump << " <standards>" << std::endl;
fdump << " <c version=\"" << mSettings.standards.getC() << "\"/>" << std::endl;
fdump << " <cpp version=\"" << mSettings.standards.getCPP() << "\"/>" << std::endl;