主要内容

hisf_0004: Protect against recursive function calls to improve code compliance

R2026b

Avoid recursive function calls to promote bounded call behavior in generated code

Usage: High-Integrity System Modeling

Guideline ID: hisf_0004

Prerequisite: hisl_0311: Configuration Parameters > Diagnostics > Stateflow, hisl_0060: Configuration parameters that improve MISRA C compliance, hisf_0011: Stateflow debugging settings

Rules

hisf_0004: Protect against recursive function calls to improve code compliance

To improve compliance of generated code, do not call functions recursively. This includes any combination of graphical functions, truth table functions, MATLAB® functions, or Simulink® functions.

Rationale

Promote bounded function call behavior.

Verification

Check usage of recursions (Simulink Check)

Example

There are multiple patterns in Stateflow® that can result in recursion.

Stateflow chart showing recursive behavior caused by event broadcasting in a state entry action

When the default state A is entered, event Evn is broadcast in the entry action of A. Evn results in a recursive call of the interpretation algorithm. Since A is active, the outgoing transition of A is tested. Since the current event Evn matches the transition event (and because of the absence of condition) the condition action is executed, broadcasting Evn again. This results in a new call of the interpretation algorithm which repeats the same sequence of steps until stack overflow.

Example

Stateflow chart showing recursive behavior caused by a graphical function calling itself

Tips

  • A recursion exists when a function calls itself directly or indirectly through another function call.

Industry Standards

  • IEC 61508-3, Table B.1 (6) 'Limited use of recursion'

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 6 (1j) 'No recursions'

  • EN 50128, Table A.12 (6) 'Limited Use of Recursion'

  • EN 50657, Table A.12 (6) 'Limited Use of Recursion'

  • DO-331, Section MB.6.3.2.g 'Algorithms are accurate'
    DO-331, Section MB.6.3.3.d 'Software architecture is verifiable'

  • MISRA C:2012, Rule 17.2

  • MISRA C:2023, Rule 17.2

Version History

Introduced in R2010a

expand all