Skip to contentSkip to conversation

docs/misra: add rule 2.1 exceptions

PATCH Superseded Stefano Stabellini 3 participants 5 messages Aug 23, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs/misra: add rule 2.1 exceptions

From: Stefano Stabellini <[email protected]>

During the discussions that led to the acceptable of Rule 2.1, we decided on a few exceptions that were not properly recorded in rules.rst. Add them now.

---
 docs/misra/rules.rst | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
docs/misra/rules.rst +12 -1
index b6d87e076b..8f38227994 100644
@@ -107,7 +107,18 @@ maintainers if you want to suggest a change.
    * - `Rule 2.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_02_01_1.c>`_
      - Required
      - A project shall not contain unreachable code
-     -
+     - The following are allowed:
+         - Invariantly constant conditions, e.g. if(IS_ENABLED(CONFIG_HVM)) { S; }
+         - Switch with a controlling value statically determined not to
+           match one or more case statements
+         - Functions that are intended to be never referenced from C
+           code (e.g. 'do_trap_fiq')
+         - Unreachability caused by the certain macros/functions is
+           deliberate, e.g. BUG, assert_failed, panic, etc.
+         - asm-offsets.c, as they are not linked deliberately, because
+           they are used to generate definitions for asm modules
+         - declarations without initializer are safe, as they are not
+           executed
 
    * - `Rule 2.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_02_06.c>`_
      - Advisory
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Stefano Stabellini

From: Stefano Stabellini <[email protected]>

During the discussions that led to the acceptable of Rule 2.1, we

Nit (as before): "acceptance"?

Quoted 13 lines

decided on a few exceptions that were not properly recorded in rules.rst. Add them now.

---
 docs/misra/rules.rst | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
docs/misra/rules.rst +0 -0
index b6d87e076b..8f38227994 100644

docs/misra/rules.rst maintainers if you want to suggest a change. · line 115

Quoted 10 lines
docs/misra/rules.rst +6 -1
@@ -107,7 +107,18 @@ maintainers if you want to suggest a change.
    * - `Rule 2.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_02_01_1.c>`_
      - Required
      - A project shall not contain unreachable code
-     -
+     - The following are allowed:
+         - Invariantly constant conditions, e.g. if(IS_ENABLED(CONFIG_HVM)) { S; }
+         - Switch with a controlling value statically determined not to
+           match one or more case statements
+         - Functions that are intended to be never referenced from C
+           code (e.g. 'do_trap_fiq')

Maybe better put it the other way around, "only referenced from assembly code"? This is because "never referenced from C" also includes truly unreferenced functions/data.

docs/misra/rules.rst maintainers if you want to suggest a change. · line 117

Quoted 2 lines
docs/misra/rules.rst +2 -0
+         - Unreachability caused by the certain macros/functions is
+           deliberate, e.g. BUG, assert_failed, panic, etc.

I think the "the" here wants dropping, and even then the result doesn't read very well imo. How about "Deliberate unreachability caused by certain macros/functions, e.g. BUG, assert_failed, panic, etc"?

docs/misra/rules.rst maintainers if you want to suggest a change. · line 121

Quoted 4 lines
docs/misra/rules.rst +4 -0
+         - asm-offsets.c, as they are not linked deliberately, because
+           they are used to generate definitions for asm modules
+         - declarations without initializer are safe, as they are not
+           executed

Provided additionally this sub-sub-bullet-list then also translates correctly to the various derived formats, then:

Jan

#2 lore raw
Quoted 42 lines · Jan Beulich
Quoted 3 lines · Stefano Stabellini

From: Stefano Stabellini <[email protected]>

During the discussions that led to the acceptable of Rule 2.1, we

Nit (as before): "acceptance"?

Quoted 13 lines

decided on a few exceptions that were not properly recorded in rules.rst. Add them now.

---
 docs/misra/rules.rst | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
docs/misra/rules.rst +0 -0
index b6d87e076b..8f38227994 100644

docs/misra/rules.rst maintainers if you want to suggest a change. · line 115

Quoted 10 lines
docs/misra/rules.rst +6 -1
@@ -107,7 +107,18 @@ maintainers if you want to suggest a change.
    * - `Rule 2.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_02_01_1.c>`_
      - Required
      - A project shall not contain unreachable code
-     -
+     - The following are allowed:
+         - Invariantly constant conditions, e.g. if(IS_ENABLED(CONFIG_HVM)) { S; }
+         - Switch with a controlling value statically determined not to
+           match one or more case statements
+         - Functions that are intended to be never referenced from C
+           code (e.g. 'do_trap_fiq')

Maybe better put it the other way around, "only referenced from assembly code"? This is because "never referenced from C" also includes truly unreferenced functions/data.

docs/misra/rules.rst maintainers if you want to suggest a change. · line 117

Quoted 2 lines
docs/misra/rules.rst +2 -0
+         - Unreachability caused by the certain macros/functions is
+           deliberate, e.g. BUG, assert_failed, panic, etc.

I think the "the" here wants dropping, and even then the result doesn't read very well imo. How about "Deliberate unreachability caused by certain macros/functions, e.g. BUG, assert_failed, panic, etc"?

Quoted 8 lines

docs/misra/rules.rst maintainers if you want to suggest a change. · line 121

Quoted 4 lines
docs/misra/rules.rst +4 -0
+         - asm-offsets.c, as they are not linked deliberately, because
+           they are used to generate definitions for asm modules
+         - declarations without initializer are safe, as they are not
+           executed

Provided additionally this sub-sub-bullet-list then also translates correctly to the various derived formats, then:

Yes I checked. Also thanks for the good suggestions, I'll make the changes and resend.

#3 lore raw
In reply to Stefano Stabellini

Hi Stefano,

Quoted 18 lines · Stefano Stabellini

From: Stefano Stabellini <[email protected]>

During the discussions that led to the acceptable of Rule 2.1, we decided on a few exceptions that were not properly recorded in rules.rst. Add them now.

---
  docs/misra/rules.rst | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
docs/misra/rules.rst +0 -0
index b6d87e076b..8f38227994 100644
@@ -107,7 +107,18 @@ maintainers if you want to suggest a change.
     * - `Rule 2.1 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_02_01_1.c>`_
       - Required

docs/misra/rules.rst maintainers if you want to suggest a change. · line 117

Quoted 10 lines
docs/misra/rules.rst +8 -1
       - A project shall not contain unreachable code
-     -
+     - The following are allowed:
+         - Invariantly constant conditions, e.g. if(IS_ENABLED(CONFIG_HVM)) { S; }
+         - Switch with a controlling value statically determined not to
+           match one or more case statements
+         - Functions that are intended to be never referenced from C
+           code (e.g. 'do_trap_fiq')
+         - Unreachability caused by the certain macros/functions is
+           deliberate, e.g. BUG, assert_failed, panic, etc.

I find the wording quite ambiguous. How will an assessor be able to know this is deliberate? I think it would be better if this is based on a keyword in the code such as a function that has the attribute noreturn and/or there is an unreachable() statement.

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw
Quoted 30 lines · Julien Grall

Hi Stefano,

Quoted 27 lines · Stefano Stabellini

From: Stefano Stabellini <[email protected]>

During the discussions that led to the acceptable of Rule 2.1, we decided on a few exceptions that were not properly recorded in rules.rst. Add them now.

---
  docs/misra/rules.rst | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
docs/misra/rules.rst +0 -0
index b6d87e076b..8f38227994 100644
@@ -107,7 +107,18 @@ maintainers if you want to suggest a change.
     * - `Rule 2.1

<https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_02_01_1.c>`_
- Required
- A project shall not contain unreachable code

docs/misra/rules.rst +2 -1
-     -
+     - The following are allowed:
+         - Invariantly constant conditions, e.g. if(IS_ENABLED(CONFIG_HVM))

{ S; }

docs/misra/rules.rst +3 -0
+         - Switch with a controlling value statically determined not to
+           match one or more case statements
+         - Functions that are intended to be never referenced from C
Quoted 8 lines

docs/misra/rules.rst maintainers if you want to suggest a change. · line 117

Quoted 3 lines
docs/misra/rules.rst +3 -0
+           code (e.g. 'do_trap_fiq')
+         - Unreachability caused by the certain macros/functions is
+           deliberate, e.g. BUG, assert_failed, panic, etc.

I find the wording quite ambiguous. How will an assessor be able to know this is deliberate? I think it would be better if this is based on a keyword in the code such as a function that has the attribute noreturn and/or there is an unreachable() statement.

You are right that it is not precise enough. I am thinking of changing this to (also following Jan's suggestion):

Deliberate unreachability caused by certain macros/functions, e.g. BUG, assert_failed, panic, etc. See safe.json.

In particular the important part is "See safe.json". Right now there is nothing in safe.json about it, but it is should be the right place to maintain the list of deviations and tags. Then we can add the tag at the declaration site of BUG, panic, etc. Nicola is also checking if this approach works with ECLAIR.