Skip to main content

IAR Embedded Workbench for RX 5.20

RED-dead

In this section:
Synopsis

A part of the application is never executed.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

There are statements in the application that cannot be reached on at least some execution paths. Dead code might indicate problems with the application's branching structure. This check is identical to MISRAC2004-14.1, MISRAC++2008-0-1-1, MISRAC++2008-0-1-9, MISRAC2012-Rule-2.1_b, MISRAC++2023-0.0.1.

Coding standards
CERT MSC07-C

Detect and remove dead code

CWE 561

Dead Code

MISRA C:2004 14.1

(Required) There shall be no unreachable code.

MISRA C:2012 Rule-2.1

(Required) A project shall not contain unreachable code

MISRA C++ 2008 0-1-1

(Required) A project shall not contain unreachable code.

MISRA C++ 2008 0-1-9

(Required) There shall be no dead code.

MISRA C++ 2023 0.0.1

(Required) A function shall not contain unreachable statements

Code examples

The following code example fails the check and will give a warning:

#include <stdio.h>

int f(int mode) {
    switch (mode) {
        case 0:
            return 1;
            printf("Hello!"); // This line cannot execute.
        default:
            return -1;
    }
}

The following code example passes the check and will not give a warning about this issue:

#include <stdio.h>

int f(int mode) {
    switch (mode) {
        case 0:
            printf("Hello!"); // This line can execute.
            return 1;
        default:
            return -1;
    }
}