Page MenuHomePhabricator

MISRA: Bare usage of __builtin_offsetof() should be avoided
Open, Needs TriagePublic

Description

Many files in TF-A codebase (examples: include/drivers/console_assertions.h, include/common/ep_info.h, etc.) contain code patterns like:

/* verify assembler offsets match data structures */
   157 CASSERT(CPU_DATA_CRASH_BUF_OFFSET == __builtin_offsetof
   158         (cpu_data_t, crash_buf),
   159         assert_cpu_data_crash_stack_offset_mismatch);

With ECLAIR MISRA checking took, this leads to:

`__builtin_offsetof' is a non-standard token (an extension to the C99 standard, ISO/IEC 9899:1999 Section 6.4: "A non-standard token."

Instead, there should be a macro like ASSERT_OFFSETOF(), which would wrap usage of __builtin_offsetof(), which will allow to easily record a deviation for this macro (and reduce number of reported MISRA violations).

Event Timeline

pfalcon created this task.Aug 15 2022, 8:08 PM