misra; implement rule 8.8

This commit is contained in:
Daniel Marjamäki 2021-07-17 23:38:29 +02:00
parent f44a82856f
commit 59c797c776
2 changed files with 27 additions and 0 deletions

View File

@ -1835,6 +1835,29 @@ class MisraChecker:
def misra_8_7(self, dumpfile, cfg): def misra_8_7(self, dumpfile, cfg):
self._save_ctu_summary_usage(dumpfile, cfg) self._save_ctu_summary_usage(dumpfile, cfg)
def misra_8_8(self, cfg):
vars = {}
for var in cfg.variables:
if var.access != 'Global':
continue
if var.nameToken is None:
continue
varname = var.nameToken.str
if varname in vars:
vars[varname].append(var)
else:
vars[varname] = [var]
for varname, varlist in vars.items():
static_var = None
extern_var = None
for var in varlist:
if var.isStatic:
static_var = var
elif var.isExtern:
extern_var = var
if static_var and extern_var:
self.reportError(extern_var.nameToken, 8, 8)
def misra_8_11(self, data): def misra_8_11(self, data):
for var in data.variables: for var in data.variables:
if var.isExtern and simpleMatch(var.nameToken.next, '[ ]') and var.nameToken.scope.type == 'Global': if var.isExtern and simpleMatch(var.nameToken.next, '[ ]') and var.nameToken.scope.type == 'Global':
@ -3555,6 +3578,7 @@ class MisraChecker:
self.executeCheck(805, self.misra_8_5, dumpfile, cfg) self.executeCheck(805, self.misra_8_5, dumpfile, cfg)
self.executeCheck(806, self.misra_8_6, dumpfile, cfg) self.executeCheck(806, self.misra_8_6, dumpfile, cfg)
self.executeCheck(807, self.misra_8_7, dumpfile, cfg) self.executeCheck(807, self.misra_8_7, dumpfile, cfg)
self.executeCheck(808, self.misra_8_8, cfg)
self.executeCheck(811, self.misra_8_11, cfg) self.executeCheck(811, self.misra_8_11, cfg)
self.executeCheck(812, self.misra_8_12, cfg) self.executeCheck(812, self.misra_8_12, cfg)
if cfgNumber == 0: if cfgNumber == 0:

View File

@ -373,6 +373,9 @@ void misra_8_4_foo(void) {} // 8.4
static void misra_8_4_bar(void) {} // Declared in header static void misra_8_4_bar(void) {} // Declared in header
extern int16_t misra_8_4_count; // 8.4 extern int16_t misra_8_4_count; // 8.4
static int32_t misra_8_8 = 123;
extern int32_t misra_8_8; // 8.8 8.4
extern int a811[]; // 8.11 8.4 extern int a811[]; // 8.11 8.4
enum misra_8_12_a { misra_a1 = 1, misra_a2 = 2, misra_a3, misra_a4 = 3 }; //8.12 enum misra_8_12_a { misra_a1 = 1, misra_a2 = 2, misra_a3, misra_a4 = 3 }; //8.12