Skip to content

Commit e0019f6

Browse files
Checks: Fixed: false positives in MISRA12_21.2 for reserved identifiers introduced by library macro expansion [autosync]
1 parent 54beff6 commit e0019f6

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

CodeCheck/Published Standards/MISRA C 2012/MISRA12_21.2/check.upy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,17 @@ def check(check, file):
169169
funcrefs = file.filerefs("Declare, Define", "", True)
170170
rangeMacroRegex = re.compile(r"__begin|__end|__range|__i")
171171
macBuiltInRegex = re.compile(r"^__builtin.*$")
172+
lexer = file.lexer()
172173
for ref in funcrefs:
173174
ent = ref.ent()
174175
name = ent.name()
175176

177+
# Skip identifiers from macro expansion (e.g. arm_neon.h intrinsics)
178+
if lexer:
179+
lexeme = lexer.lexeme(ref.line(), ref.column())
180+
if not lexeme or lexeme.text() != name:
181+
continue
182+
176183
# Special case to detect when a range based loop is used
177184
if re.search(rangeMacroRegex, name):
178185
define = ent.ref('Definein')

CodeCheck/Published Standards/MISRA C 2012/MISRA12_21.2/test1.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ int free(void *pArg, int len) { // UndCC_Violation: free is a standard function
88
int __test; // UndCC_Violation: starts with "__"
99
//...
1010
}
11+
12+
// Library-style macro (e.g. arm_neon.h) expands a reserved local at the call site
13+
#define GET_VALUE(x) ({ int __ret = (x); __ret; })
14+
int use_macro(void) {
15+
return GET_VALUE(5); // UndCC_Valid: __ret comes from macro expansion
16+
}
1117
#endif

0 commit comments

Comments
 (0)