From f6b867c922a69cbe790ac584ed6e77f9eb9e01b0 Mon Sep 17 00:00:00 2001 From: swasti16 Date: Mon, 29 Jan 2024 14:56:29 +0530 Subject: [PATCH] Fix #12362: False positive: misra 8.7: taking function by address is not recognized as function usage --- addons/misra.py | 2 +- addons/test/misra/misra-ctu-1-test.c | 4 ++++ addons/test/misra/misra-ctu-2-test.c | 3 +++ addons/test/misra/misra-ctu-test.h | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index aa2ab14e0a9..a48629b986f 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1516,7 +1516,7 @@ def _save_ctu_summary_usage(self, dumpfile, cfg): for token in cfg.tokenlist: if not token.isName: continue - if token.function and token.scope.isExecutable: + if token.function and token != token.function.tokenDef: if (not token.function.isStatic) and (token.str not in names): names.append({'name': token.str, 'file': token.file}) elif token.variable: diff --git a/addons/test/misra/misra-ctu-1-test.c b/addons/test/misra/misra-ctu-1-test.c index 424b3ece97b..45c963de925 100644 --- a/addons/test/misra/misra-ctu-1-test.c +++ b/addons/test/misra/misra-ctu-1-test.c @@ -46,3 +46,7 @@ extern int misra_8_5; int32_t misra_8_6 = 1; void misra_8_7_external(void) {} + +// #12362 +void misra_8_7_compliant( void ){} +static void misra_8_7_call(void) { misra_8_7_compliant(); } \ No newline at end of file diff --git a/addons/test/misra/misra-ctu-2-test.c b/addons/test/misra/misra-ctu-2-test.c index cbb669b5016..8b7255bbf0a 100644 --- a/addons/test/misra/misra-ctu-2-test.c +++ b/addons/test/misra/misra-ctu-2-test.c @@ -56,3 +56,6 @@ static void misra_8_7_caller(void) { misra_8_7_external(); } +// #12362 +typedef void(*misra_8_7_func_ptr)( void ); +static const misra_8_7_func_ptr ptrs[] = { misra_8_7_compliant, NULL }; \ No newline at end of file diff --git a/addons/test/misra/misra-ctu-test.h b/addons/test/misra/misra-ctu-test.h index c9d2a7ba8a0..f9a3f680945 100644 --- a/addons/test/misra/misra-ctu-test.h +++ b/addons/test/misra/misra-ctu-test.h @@ -18,4 +18,6 @@ void misra_8_7_external(void); // cppcheck-suppress misra-c2012-2.5 #define MISRA_2_5_VIOLATION 0 +// #12362 +extern void misra_8_7_compliant( void );