misra: implement rule 5.7

This commit is contained in:
Daniel Marjamäki 2021-07-07 21:47:17 +02:00
parent 859e541661
commit cf049cb759
4 changed files with 43 additions and 9 deletions

View File

@ -1104,6 +1104,7 @@ class MisraChecker:
self.existing_violations = set()
self._ctu_summary_typedefs = False
self._ctu_summary_tagnames = False
def __repr__(self):
attrs = ["settings", "verify_expected", "verify_actual", "violations",
@ -1132,14 +1133,12 @@ class MisraChecker:
if len(summary) > 0:
cppcheckdata.reportSummary(dumpfile, 'MisraTypedefInfo', summary)
def misra_2_3(self, data):
dumpfile = data[0]
typedefInfo = data[1]
self._save_ctu_summary_typedefs(dumpfile, typedefInfo)
def _save_ctu_summary_tagnames(self, dumpfile, cfg):
if self._ctu_summary_tagnames:
return
self._ctu_summary_tagnames = True
def misra_2_4(self, data):
dumpfile = data[0]
cfg = data[1]
summary = []
# structs/enums
for scope in cfg.scopes:
@ -1158,6 +1157,16 @@ class MisraChecker:
if len(summary) > 0:
cppcheckdata.reportSummary(dumpfile, 'MisraTagName', summary)
def misra_2_3(self, data):
dumpfile = data[0]
typedefInfo = data[1]
self._save_ctu_summary_typedefs(dumpfile, typedefInfo)
def misra_2_4(self, data):
dumpfile = data[0]
cfg = data[1]
self._save_ctu_summary_tagnames(dumpfile, cfg)
def misra_2_7(self, data):
for func in data.functions:
# Skip function with no parameter
@ -1384,6 +1393,11 @@ class MisraChecker:
typedefInfo = data[1]
self._save_ctu_summary_typedefs(dumpfile, typedefInfo)
def misra_5_7(self, data):
dumpfile = data[0]
cfg = data[1]
self._save_ctu_summary_tagnames(dumpfile, cfg)
def misra_6_1(self, data):
# Bitfield type must be bool or explicitly signed/unsigned int
@ -3307,6 +3321,7 @@ class MisraChecker:
self.executeCheck(504, self.misra_5_4, cfg)
self.executeCheck(505, self.misra_5_5, cfg)
self.executeCheck(506, self.misra_5_6, (dumpfile, cfg.typedefInfo))
self.executeCheck(507, self.misra_5_7, (dumpfile, cfg))
self.executeCheck(601, self.misra_6_1, cfg)
self.executeCheck(602, self.misra_6_2, cfg)
if cfgNumber == 0:
@ -3438,6 +3453,10 @@ class MisraChecker:
for old_tagname_info in all_tagname_info:
if old_tagname_info['name'] == new_tagname_info['name']:
found = True
if old_tagname_info['file'] != new_tagname_info['file'] or old_tagname_info['line'] != new_tagname_info['line']:
self.reportError(Location(old_tagname_info['file'], old_tagname_info['line'], old_tagname_info['column']), 5, 7)
self.reportError(Location(new_tagname_info['file'], new_tagname_info['line'], new_tagname_info['column']), 5, 7)
else:
if new_tagname_info['used']:
old_tagname_info['used'] = True
if not found:

View File

@ -9,3 +9,8 @@ MISRA_2_3_A misra_2_3_a;
// cppcheck-suppress misra-c2012-5.6
typedef int MISRA_5_6_VIOLATION;
// cppcheck-suppress misra-c2012-5.7
struct misra_5_7_violation_t {
int x;
};
static misra_5_7_violation_t misra_5_7_var;

View File

@ -9,3 +9,8 @@ MISRA_2_3_B misra_2_3_b;
typedef int MISRA_5_6_VIOLATION;
static MISRA_5_6_VIOLATION misra_5_6_x;
// cppcheck-suppress misra-c2012-5.7
struct misra_5_7_violation_t {
int x;
};
static misra_5_7_violation_t misra_5_7_var;

View File

@ -12,3 +12,8 @@ int misra_5_2_field_hides_field1_31y;//5.2
};
const char *s41_1 = "\x41g"; // 4.1
const char *s41_2 = "\x41\x42";
// cppcheck-suppress misra-c2012-5.7
struct misra_5_7_violation_t {
int x;
};