* [XEN PATCH 0/2] misra: deviations of Rule 16.4
@ 2024-05-03 9:58 Federico Serafini
2024-05-03 9:58 ` [XEN PATCH 1/2] docs/misra: add Terms & Definitions section to rules.rst Federico Serafini
2024-05-03 9:58 ` [XEN PATCH 2/2] automation/eclair: add deviation for Rule 16.4 Federico Serafini
0 siblings, 2 replies; 5+ messages in thread
From: Federico Serafini @ 2024-05-03 9:58 UTC (permalink / raw)
To: xen-devel
Cc: consulting, Federico Serafini, Andrew Cooper, George Dunlap,
Jan Beulich, Julien Grall, Stefano Stabellini, Simone Ballarin,
Doug Goldstein
Define "switch-clause" in terms of the C specification.
Deviate Rule 16.4.
Federico Serafini (2):
docs/misra: add Terms & Definitions section to rules.rst
automation/eclair: add deviation for Rule 16.4
automation/eclair_analysis/ECLAIR/deviations.ecl | 8 ++++++++
docs/misra/deviations.rst | 13 +++++++++++++
docs/misra/rules.rst | 14 ++++++++++++--
3 files changed, 33 insertions(+), 2 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [XEN PATCH 1/2] docs/misra: add Terms & Definitions section to rules.rst
2024-05-03 9:58 [XEN PATCH 0/2] misra: deviations of Rule 16.4 Federico Serafini
@ 2024-05-03 9:58 ` Federico Serafini
2024-05-03 23:08 ` Stefano Stabellini
2024-05-03 9:58 ` [XEN PATCH 2/2] automation/eclair: add deviation for Rule 16.4 Federico Serafini
1 sibling, 1 reply; 5+ messages in thread
From: Federico Serafini @ 2024-05-03 9:58 UTC (permalink / raw)
To: xen-devel
Cc: consulting, Federico Serafini, Andrew Cooper, George Dunlap,
Jan Beulich, Julien Grall, Stefano Stabellini
Add a section for terms and definitions used by MISRA but expressed
in terms of the C specification.
Add a definition of "switch clause" to the newly-introduced section.
Link the first use of the term "switch clause" in the document to its
definition.
Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
---
Jan you were not completely satisfied by the definition but I didn't find
a better one.
---
docs/misra/rules.rst | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
index b7b447e152..d3b70fdf04 100644
--- a/docs/misra/rules.rst
+++ b/docs/misra/rules.rst
@@ -489,8 +489,7 @@ maintainers if you want to suggest a change.
* - `Rule 16.3 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_16_03.c>`_
- Required
- - An unconditional break statement shall terminate every
- switch-clause
+ - An unconditional break statement shall terminate every switch-clause_
- In addition to break, also other unconditional flow control statements
such as continue, return, goto are allowed.
@@ -712,3 +711,14 @@ maintainers if you want to suggest a change.
- The value of a pointer to a FILE shall not be used after the associated
stream has been closed
-
+
+Terms & Definitions
+-------------------
+
+.. _switch-clause:
+
+A *switch clause* can be defined as:
+"the non-empty list of statements which follows a non-empty list of
+case/default labels".
+A formal definition is available within the amplification of MISRA C:2012
+Rule 16.1.
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [XEN PATCH 2/2] automation/eclair: add deviation for Rule 16.4
2024-05-03 9:58 [XEN PATCH 0/2] misra: deviations of Rule 16.4 Federico Serafini
2024-05-03 9:58 ` [XEN PATCH 1/2] docs/misra: add Terms & Definitions section to rules.rst Federico Serafini
@ 2024-05-03 9:58 ` Federico Serafini
2024-05-03 23:09 ` Stefano Stabellini
1 sibling, 1 reply; 5+ messages in thread
From: Federico Serafini @ 2024-05-03 9:58 UTC (permalink / raw)
To: xen-devel
Cc: consulting, Federico Serafini, Simone Ballarin, Doug Goldstein,
Stefano Stabellini, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall
MISRA C:2012 Rule 16.4 states that "Every switch statement shall have a
default label".
Update ECLAIR configuration to take into account the deviations
agreed during MISRA meetings.
Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
---
automation/eclair_analysis/ECLAIR/deviations.ecl | 8 ++++++++
docs/misra/deviations.rst | 13 +++++++++++++
2 files changed, 21 insertions(+)
diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index d21f112a9b..f09ad71acf 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -384,6 +384,14 @@ explicit comment indicating the fallthrough intention is present."
-config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"}
-doc_end
+-doc_begin="Switch statements having a controlling expression of enum type deliberately do not have a default case: gcc -Wall enables -Wswitch which warns (and breaks the build as we use -Werror) if one of the enum labels is missing from the switch."
+-config=MC3R1.R16.4,reports+={deliberate,'any_area(kind(context)&&^.* has no `default.*$&&stmt(node(switch_stmt)&&child(cond,skip(__non_syntactic_paren_stmts,type(canonical(enum_underlying_type(any())))))))'}
+-doc_end
+
+-doc_begin="A switch statement with a single switch clause and no default label may be used in place of an equivalent if statement if it is considered to improve readability."
+-config=MC3R1.R16.4,switch_clauses+={deliberate,"switch(1)&&default(0)"}
+-doc_end
+
-doc_begin="A switch statement with a single switch clause and no default label may be used in place of an equivalent if statement if it is considered to improve readability."
-config=MC3R1.R16.6,switch_clauses+={deliberate, "default(0)"}
-doc_end
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
index ed0c1e8ed0..39cc321a27 100644
--- a/docs/misra/deviations.rst
+++ b/docs/misra/deviations.rst
@@ -334,6 +334,19 @@ Deviations related to MISRA C:2012 Rules:
- /\* Fallthrough \*/
- /\* Fallthrough. \*/
+ * - R16.4
+ - Switch statements having a controlling expression of enum type
+ deliberately do not have a default case: gcc -Wall enables -Wswitch
+ which warns (and breaks the build as we use -Werror) if one of the enum
+ labels is missing from the switch.
+ - Tagged as `deliberate` for ECLAIR.
+
+ * - R16.4
+ - A switch statement with a single switch clause and no default label may
+ be used in place of an equivalent if statement if it is considered to
+ improve readability.
+ - Tagged as `deliberate` for ECLAIR.
+
* - R16.6
- A switch statement with a single switch clause and no default label may
be used in place of an equivalent if statement if it is considered to
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [XEN PATCH 1/2] docs/misra: add Terms & Definitions section to rules.rst
2024-05-03 9:58 ` [XEN PATCH 1/2] docs/misra: add Terms & Definitions section to rules.rst Federico Serafini
@ 2024-05-03 23:08 ` Stefano Stabellini
0 siblings, 0 replies; 5+ messages in thread
From: Stefano Stabellini @ 2024-05-03 23:08 UTC (permalink / raw)
To: Federico Serafini
Cc: xen-devel, consulting, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall, Stefano Stabellini
On Fri, 3 May 2024, Federico Serafini wrote:
> Add a section for terms and definitions used by MISRA but expressed
> in terms of the C specification.
>
> Add a definition of "switch clause" to the newly-introduced section.
>
> Link the first use of the term "switch clause" in the document to its
> definition.
>
> Suggested-by: Jan Beulich <jbeulich@suse.com>
> Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> Jan you were not completely satisfied by the definition but I didn't find
> a better one.
> ---
> docs/misra/rules.rst | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
> index b7b447e152..d3b70fdf04 100644
> --- a/docs/misra/rules.rst
> +++ b/docs/misra/rules.rst
> @@ -489,8 +489,7 @@ maintainers if you want to suggest a change.
>
> * - `Rule 16.3 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_16_03.c>`_
> - Required
> - - An unconditional break statement shall terminate every
> - switch-clause
> + - An unconditional break statement shall terminate every switch-clause_
> - In addition to break, also other unconditional flow control statements
> such as continue, return, goto are allowed.
>
> @@ -712,3 +711,14 @@ maintainers if you want to suggest a change.
> - The value of a pointer to a FILE shall not be used after the associated
> stream has been closed
> -
> +
> +Terms & Definitions
> +-------------------
> +
> +.. _switch-clause:
> +
> +A *switch clause* can be defined as:
> +"the non-empty list of statements which follows a non-empty list of
> +case/default labels".
> +A formal definition is available within the amplification of MISRA C:2012
> +Rule 16.1.
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [XEN PATCH 2/2] automation/eclair: add deviation for Rule 16.4
2024-05-03 9:58 ` [XEN PATCH 2/2] automation/eclair: add deviation for Rule 16.4 Federico Serafini
@ 2024-05-03 23:09 ` Stefano Stabellini
0 siblings, 0 replies; 5+ messages in thread
From: Stefano Stabellini @ 2024-05-03 23:09 UTC (permalink / raw)
To: Federico Serafini
Cc: xen-devel, consulting, Simone Ballarin, Doug Goldstein,
Stefano Stabellini, Andrew Cooper, George Dunlap, Jan Beulich,
Julien Grall
On Fri, 3 May 2024, Federico Serafini wrote:
> MISRA C:2012 Rule 16.4 states that "Every switch statement shall have a
> default label".
> Update ECLAIR configuration to take into account the deviations
> agreed during MISRA meetings.
>
> Signed-off-by: Federico Serafini <federico.serafini@bugseng.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> automation/eclair_analysis/ECLAIR/deviations.ecl | 8 ++++++++
> docs/misra/deviations.rst | 13 +++++++++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
> index d21f112a9b..f09ad71acf 100644
> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> @@ -384,6 +384,14 @@ explicit comment indicating the fallthrough intention is present."
> -config=MC3R1.R16.3,reports+={safe, "any_area(end_loc(any_exp(text(^(?s).*/\\* [fF]all ?through.? \\*/.*$,0..1))))"}
> -doc_end
>
> +-doc_begin="Switch statements having a controlling expression of enum type deliberately do not have a default case: gcc -Wall enables -Wswitch which warns (and breaks the build as we use -Werror) if one of the enum labels is missing from the switch."
> +-config=MC3R1.R16.4,reports+={deliberate,'any_area(kind(context)&&^.* has no `default.*$&&stmt(node(switch_stmt)&&child(cond,skip(__non_syntactic_paren_stmts,type(canonical(enum_underlying_type(any())))))))'}
> +-doc_end
> +
> +-doc_begin="A switch statement with a single switch clause and no default label may be used in place of an equivalent if statement if it is considered to improve readability."
> +-config=MC3R1.R16.4,switch_clauses+={deliberate,"switch(1)&&default(0)"}
> +-doc_end
> +
> -doc_begin="A switch statement with a single switch clause and no default label may be used in place of an equivalent if statement if it is considered to improve readability."
> -config=MC3R1.R16.6,switch_clauses+={deliberate, "default(0)"}
> -doc_end
> diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
> index ed0c1e8ed0..39cc321a27 100644
> --- a/docs/misra/deviations.rst
> +++ b/docs/misra/deviations.rst
> @@ -334,6 +334,19 @@ Deviations related to MISRA C:2012 Rules:
> - /\* Fallthrough \*/
> - /\* Fallthrough. \*/
>
> + * - R16.4
> + - Switch statements having a controlling expression of enum type
> + deliberately do not have a default case: gcc -Wall enables -Wswitch
> + which warns (and breaks the build as we use -Werror) if one of the enum
> + labels is missing from the switch.
> + - Tagged as `deliberate` for ECLAIR.
> +
> + * - R16.4
> + - A switch statement with a single switch clause and no default label may
> + be used in place of an equivalent if statement if it is considered to
> + improve readability.
> + - Tagged as `deliberate` for ECLAIR.
> +
> * - R16.6
> - A switch statement with a single switch clause and no default label may
> be used in place of an equivalent if statement if it is considered to
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-03 23:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-03 9:58 [XEN PATCH 0/2] misra: deviations of Rule 16.4 Federico Serafini
2024-05-03 9:58 ` [XEN PATCH 1/2] docs/misra: add Terms & Definitions section to rules.rst Federico Serafini
2024-05-03 23:08 ` Stefano Stabellini
2024-05-03 9:58 ` [XEN PATCH 2/2] automation/eclair: add deviation for Rule 16.4 Federico Serafini
2024-05-03 23:09 ` Stefano Stabellini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.