diff mbox series

[XEN] automation/eclair: add deviations of MISRA C Rule 5.5

Message ID dbd34e37b5d757ff7ae2a7318ad12b159970604c.1718887298.git.federico.serafini@bugseng.com (mailing list archive)
State New, archived
Headers show
Series [XEN] automation/eclair: add deviations of MISRA C Rule 5.5 | expand

Commit Message

Federico Serafini June 20, 2024, 12:50 p.m. UTC
MISRA C Rule 5.5 states that "Identifiers shall be distinct from macro
names".

Update ECLAIR configuration to deviate:
- macros expanding to their own name;
- clashes between macros and non-callable entities;
- clashes related to the selection of specific implementations of string
  handling functions.

Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
---
 .../eclair_analysis/ECLAIR/deviations.ecl     | 16 ++++++++++++++
 docs/misra/deviations.rst                     | 21 +++++++++++++++++++
 2 files changed, 37 insertions(+)

Comments

Stefano Stabellini June 21, 2024, 12:22 a.m. UTC | #1
On Thu, 20 Jun 2024, Federico Serafini wrote:
> MISRA C Rule 5.5 states that "Identifiers shall be distinct from macro
> names".
> 
> Update ECLAIR configuration to deviate:
> - macros expanding to their own name;
> - clashes between macros and non-callable entities;
> - clashes related to the selection of specific implementations of string
>   handling functions.
> 
> Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Stefano Stabellini June 21, 2024, 10:07 p.m. UTC | #2
On Thu, 20 Jun 2024, Stefano Stabellini wrote:
> On Thu, 20 Jun 2024, Federico Serafini wrote:
> > MISRA C Rule 5.5 states that "Identifiers shall be distinct from macro
> > names".
> > 
> > Update ECLAIR configuration to deviate:
> > - macros expanding to their own name;
> > - clashes between macros and non-callable entities;
> > - clashes related to the selection of specific implementations of string
> >   handling functions.
> > 
> > Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
> 
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

I would like to ask for a release-ack as its effect is limited to ECLAIR
analysis results and rule 5.5 is not blocking anyway (it is allowed to
fail).
Oleksii Kurochko June 24, 2024, 7:55 a.m. UTC | #3
On Fri, 2024-06-21 at 15:07 -0700, Stefano Stabellini wrote:
> On Thu, 20 Jun 2024, Stefano Stabellini wrote:
> > On Thu, 20 Jun 2024, Federico Serafini wrote:
> > > MISRA C Rule 5.5 states that "Identifiers shall be distinct from
> > > macro
> > > names".
> > > 
> > > Update ECLAIR configuration to deviate:
> > > - macros expanding to their own name;
> > > - clashes between macros and non-callable entities;
> > > - clashes related to the selection of specific implementations of
> > > string
> > >   handling functions.
> > > 
> > > Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
> > 
> > Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> 
> I would like to ask for a release-ack as its effect is limited to
> ECLAIR
> analysis results and rule 5.5 is not blocking anyway (it is allowed
> to
> fail).

Release-Acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

~ Oleksii
diff mbox series

Patch

diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index e2653f77eb..9ad0e1f90a 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -90,6 +90,22 @@  conform to the directive."
 -config=MC3R1.R5.3,reports+={safe, "any_area(any_loc(any_exp(macro(^read_debugreg$))&&any_exp(macro(^write_debugreg$))))"}
 -doc_end
 
+-doc_begin="Macros expanding to their own identifier (e.g., \"#define x x\") are deliberate."
+-config=MC3R1.R5.5,reports+={deliberate, "all_area(macro(same_id_body())||!macro(!same_id_body()))"}
+-doc_end
+
+-doc_begin="There is no clash between function like macros and not callable objects."
+-config=MC3R1.R5.5,reports+={deliberate, "all_area(macro(function_like())||decl(any()))&&all_area(macro(any())||!decl(kind(function))&&!decl(__function_pointer_decls))"}
+-doc_end
+
+-doc_begin="Clashes between function names and macros are deliberate for string handling functions since some architectures may want to use their own arch-specific implementation."
+-config=MC3R1.R5.5,reports+={deliberate, "all_area(all_loc(file(^xen/arch/x86/string\\.c|xen/include/xen/string\\.h|xen/lib/.*$)))"}
+-doc_end
+
+-doc_begin="In libelf, clashes between macros and function names are deliberate and needed to prevent the use of undecorated versions of memcpy, memset and memmove."
+-config=MC3R1.R5.5,reports+={deliberate, "any_area(decl(kind(function))||any_loc(macro(name(memcpy||memset||memmove))))&&any_area(any_loc(file(^xen/common/libelf/libelf-private\\.h$)))"}
+-doc_end
+
 -doc_begin="The type \"ret_t\" is deliberately defined multiple times,
 depending on the guest."
 -config=MC3R1.R5.6,reports+={deliberate,"any_area(any_loc(text(^.*ret_t.*$)))"}
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
index 36959aa44a..446c758c11 100644
--- a/docs/misra/deviations.rst
+++ b/docs/misra/deviations.rst
@@ -98,6 +98,27 @@  Deviations related to MISRA C:2012 Rules:
          - __emulate_2op and __emulate_2op_nobyte
          - read_debugreg and write_debugreg
 
+   * - R5.5
+     - Macros expanding to their own name are allowed.
+     - Tagged as `deliberate` for ECLAIR.
+
+   * - R5.5
+     - Clashes between names of function-like macros and identifiers of
+       non-callable entities are allowed.
+     - Tagged as `deliberate` for ECLAIR.
+
+   * - R5.5
+     - Clashes between function names and macros are deliberate for string
+       handling functions since some architectures may want to use their own
+       arch-specific implementation.
+     - Tagged as `deliberate` for ECLAIR.
+
+   * - R5.5
+     - In libelf, clashes between macros and function names are deliberate and
+       needed to prevent the use of undecorated versions of memcpy, memset and
+       memmove.
+     - Tagged as `deliberate` for ECLAIR.
+
    * - R5.6
      - The type ret_t is deliberately defined multiple times depending on the
        type of guest to service.