MISRA C:2012 Rule 2.1
A project shall not contain unreachable code
Description
Rule Definition
A project shall not contain unreachable code1 .
Rationale
Unless a program exhibits any undefined behavior, unreachable code cannot execute. The unreachable code cannot affect the program output. The presence of unreachable code can indicate an error in the program logic. Unreachable code that the compiler does not remove wastes resources, for example:
It occupies space in the target machine memory.
Its presence can cause a compiler to select longer, slower jump instructions when transferring control around the unreachable code.
Within a loop, it can prevent the entire loop from residing in an instruction cache.
Polyspace Implementation
Polyspace® reports a defect if a statement in your code is not reachable.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Unused Code |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2014b1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.