[XEN PATCH v2] automation/eclair: add deviations for MISRA C:2012 Rule 16.4

Federico Serafini posted 1 patch 1 week, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/310e1dac8ecf2a85f1c552dbdad9093b1cfdcb98.1713946892.git.federico.serafini@bugseng.com
automation/eclair_analysis/ECLAIR/deviations.ecl |  8 ++++++++
docs/misra/deviations.rst                        | 13 +++++++++++++
2 files changed, 21 insertions(+)
[XEN PATCH v2] automation/eclair: add deviations for MISRA C:2012 Rule 16.4
Posted by Federico Serafini 1 week, 4 days ago
Update ECLAIR configuration to take into account the deviations
agreed during MISRA meetings for Rule 16.4.

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
Re: [XEN PATCH v2] automation/eclair: add deviations for MISRA C:2012 Rule 16.4
Posted by Jan Beulich 1 week, 4 days ago
On 24.04.2024 10:25, Federico Serafini wrote:
> Update ECLAIR configuration to take into account the deviations
> agreed during MISRA meetings for Rule 16.4.
> 
> 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(+)
> 

So what has changed here from v1? It looks all the same to me, with it still
remaining unclear what exactly ...

> --- 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

... a "switch clause" is.

Jan
Re: [XEN PATCH v2] automation/eclair: add deviations for MISRA C:2012 Rule 16.4
Posted by Federico Serafini 1 week, 4 days ago
On 24/04/24 10:30, Jan Beulich wrote:
> On 24.04.2024 10:25, Federico Serafini wrote:
>> Update ECLAIR configuration to take into account the deviations
>> agreed during MISRA meetings for Rule 16.4.
>>
>> 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(+)
>>
> 
> So what has changed here from v1? It looks all the same to me, with it still
> remaining unclear what exactly ...
> 
>> --- 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
> 
> ... a "switch clause" is.

I would define a switch clause as:
"the non-empy list of statements which follows a non-empty list of
case/default labels".
If you agree, I will place it near the occurrences of the term
"switch clause".

-- 
Federico Serafini, M.Sc.

Software Engineer, BUGSENG (http://bugseng.com)
Re: [XEN PATCH v2] automation/eclair: add deviations for MISRA C:2012 Rule 16.4
Posted by Jan Beulich 1 week, 4 days ago
On 24.04.2024 11:00, Federico Serafini wrote:
> On 24/04/24 10:30, Jan Beulich wrote:
>> On 24.04.2024 10:25, Federico Serafini wrote:
>>> Update ECLAIR configuration to take into account the deviations
>>> agreed during MISRA meetings for Rule 16.4.
>>>
>>> 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(+)
>>>
>>
>> So what has changed here from v1? It looks all the same to me, with it still
>> remaining unclear what exactly ...
>>
>>> --- 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
>>
>> ... a "switch clause" is.
> 
> I would define a switch clause as:
> "the non-empy list of statements which follows a non-empty list of
> case/default labels".
> If you agree, I will place it near the occurrences of the term
> "switch clause".

I'm afraid I don't (quite) agree, and I had hoped that I would have got my
point across that such a definition wants to be in terms used by the C spec.
"statement" is too broad here, as that in particular includes
"labeled-statement" as well. Ordinary labels are (aiui) okay to have in
there, so entirely excluding "labeled-statement" wouldn't be quite right
either.

Jan