misra: deviations of Rule 16.4
cover misra: deviations of Rule 16.4
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(-)
Signature · 1 line
2.34.1
PATCH 1/2 docs/misra: add Terms & Definitions section to rules.rst
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.
---
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(-)
docs/misra/rules.rst +12 -2
@@ -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.
Signature · 1 line
2.34.1
PATCH 2/2 automation/eclair: add deviation for Rule 16.4
In reply to Federico SerafiniMISRA 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.
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 8 ++++++++ docs/misra/deviations.rst | 13 +++++++++++++ 2 files changed, 21 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +8 -0
@@ -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
docs/misra/deviations.rst +13 -0
@@ -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
Signature · 1 line
2.34.1
Re: [XEN PATCH 1/2] docs/misra: add Terms & Definitions section to rules.rst
In reply to Federico SerafiniQuoted 10 lines · Federico Serafini
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 <[email protected]>Signed-off-by Federico Serafini <[email protected]>
Quoted 39 lines
---
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(-)docs/misra/rules.rst +12
-2@@ -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.Signature · 1 line
2.34.1
Re: [XEN PATCH 2/2] automation/eclair: add deviation for Rule 16.4
In reply to Federico SerafiniQuoted 6 lines · Federico Serafini
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 <[email protected]>
Quoted 51 lines
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 8 ++++++++ docs/misra/deviations.rst | 13 +++++++++++++ 2 files changed, 21 insertions(+)automation/eclair_analysis/ECLAIR/deviations.ecl +8
-0@@ -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_enddocs/misra/deviations.rst +13
-0@@ -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 toSignature · 1 line
2.34.1