C and C++ Binaries


LANG.STRUCT.UC : Unreachable Code: 5 warning classes

Summary

Some of the code in a function is not reachable from the function entry point under any circumstances.

The following table lists the available unreachable code warning classes in order of severity, with the most severe ("Unreachable Call") first. The warning class associated with a block of unreachable code will be the most severe class that is applicable to the statements in the block.

Warning Class Name Most Serious Statement Type in Unreachable Set
Unreachable Call A call site.
Unreachable Computation A statement that performs computation (such as addition) on data.
Unreachable Conditional A branch statement, such as if, while, switch, ?, &&,||.
Unreachable Data Flow A simple assignment, or a return statement with a value.
Unreachable Control Flow A non-branching statement that influences control flow, such as break, goto, continue, or return with no value.

Properties

Multiple warning classes share this mnemonic.

To enable or disable them all at once, add one of the following WARNING_FILTER rules to the project configuration file.

WARNING_FILTER += allow categories:LANG.STRUCT.UC
WARNING_FILTER += discard categories:LANG.STRUCT.UC
Class Name Unreachable Call
Significance redundancy
Mnemonic LANG.STRUCT.UC
Categories
MisraC2023 MisraC2023:2.1 A project shall not contain unreachable code
Misra2012 Misra2012:2.1 A project shall not contain unreachable code
Misra2004 Misra2004:14.1 There shall be no unreachable code
AUTOSARC++14 AUTOSARC++14:M0-1-1 A project shall not contain unreachable code.
  AUTOSARC++14:M0-1-2 A project shall not contain infeasible paths.
MisraC++2008 MisraC++2008:0-1-1 A project shall not contain unreachable code.
  MisraC++2008:0-1-2 A project shall not contain infeasible paths.
MisraC++2023 MisraC++2023:0.0.1 A function shall not contain unreachable statements
CWE CWE:561 Dead Code
CERT-C CERT-C:MSC07-C Detect and remove dead code
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
JSF++ JSF++:186 There shall be no unreachable code.
DISA-3r10 DISA-3r10:V-6149 The designer will ensure the application does not contain source code that is never invoked during operation, except for software components and libraries from approved third-party products.
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Unreachable Call"
Class Name Unreachable Computation
Significance redundancy
Mnemonic LANG.STRUCT.UC
Categories
MisraC2023 MisraC2023:2.1 A project shall not contain unreachable code
Misra2012 Misra2012:2.1 A project shall not contain unreachable code
Misra2004 Misra2004:14.1 There shall be no unreachable code
AUTOSARC++14 AUTOSARC++14:M0-1-1 A project shall not contain unreachable code.
  AUTOSARC++14:M0-1-2 A project shall not contain infeasible paths.
MisraC++2008 MisraC++2008:0-1-1 A project shall not contain unreachable code.
  MisraC++2008:0-1-2 A project shall not contain infeasible paths.
CWE CWE:561 Dead Code
CERT-C CERT-C:MSC07-C Detect and remove dead code
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
JSF++ JSF++:186 There shall be no unreachable code.
DISA-3r10 DISA-3r10:V-6149 The designer will ensure the application does not contain source code that is never invoked during operation, except for software components and libraries from approved third-party products.
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Unreachable Computation"
Class Name Unreachable Conditional
Significance redundancy
Mnemonic LANG.STRUCT.UC
Categories
MisraC2023 MisraC2023:2.1 A project shall not contain unreachable code
Misra2012 Misra2012:2.1 A project shall not contain unreachable code
Misra2004 Misra2004:14.1 There shall be no unreachable code
AUTOSARC++14 AUTOSARC++14:M0-1-1 A project shall not contain unreachable code.
  AUTOSARC++14:M0-1-2 A project shall not contain infeasible paths.
MisraC++2008 MisraC++2008:0-1-1 A project shall not contain unreachable code.
  MisraC++2008:0-1-2 A project shall not contain infeasible paths.
CWE CWE:561 Dead Code
CERT-C CERT-C:MSC07-C Detect and remove dead code
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
JSF++ JSF++:186 There shall be no unreachable code.
DISA-3r10 DISA-3r10:V-6149 The designer will ensure the application does not contain source code that is never invoked during operation, except for software components and libraries from approved third-party products.
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Unreachable Conditional"
Class Name Unreachable Control Flow
Significance redundancy
Mnemonic LANG.STRUCT.UC
Categories
MisraC2023 MisraC2023:2.1 A project shall not contain unreachable code
Misra2012 Misra2012:2.1 A project shall not contain unreachable code
Misra2004 Misra2004:14.1 There shall be no unreachable code
AUTOSARC++14 AUTOSARC++14:M0-1-1 A project shall not contain unreachable code.
  AUTOSARC++14:M0-1-2 A project shall not contain infeasible paths.
MisraC++2008 MisraC++2008:0-1-1 A project shall not contain unreachable code.
  MisraC++2008:0-1-2 A project shall not contain infeasible paths.
CWE CWE:561 Dead Code
CERT-C CERT-C:MSC07-C Detect and remove dead code
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
JSF++ JSF++:186 There shall be no unreachable code.
DISA-3r10 DISA-3r10:V-6149 The designer will ensure the application does not contain source code that is never invoked during operation, except for software components and libraries from approved third-party products.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Unreachable Control Flow"
Class Name Unreachable Data Flow
Significance redundancy
Mnemonic LANG.STRUCT.UC
Categories
MisraC2023 MisraC2023:2.1 A project shall not contain unreachable code
Misra2012 Misra2012:2.1 A project shall not contain unreachable code
Misra2004 Misra2004:14.1 There shall be no unreachable code
AUTOSARC++14 AUTOSARC++14:M0-1-1 A project shall not contain unreachable code.
  AUTOSARC++14:M0-1-2 A project shall not contain infeasible paths.
MisraC++2008 MisraC++2008:0-1-1 A project shall not contain unreachable code.
  MisraC++2008:0-1-2 A project shall not contain infeasible paths.
CWE CWE:561 Dead Code
CERT-C CERT-C:MSC07-C Detect and remove dead code
  CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
JSF++ JSF++:186 There shall be no unreachable code.
DISA-3r10 DISA-3r10:V-6149 The designer will ensure the application does not contain source code that is never invoked during operation, except for software components and libraries from approved third-party products.
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Unreachable Data Flow"

Example

#include <stdlib.h>
#include <stddef.h>

void g(void);

int f(int i){
    if( i ) exit( i );
    return 0;
}

/* For unreachable_computation(), unreachable_conditional(),
 * unreachable_conditional(), and unreachable_data_flow(), the first
 * statement in the function body is
 *    int rv = f(5);
 *
 * The call to f() is reachable but never returns, so the remainder of
 * the function, including the assignment of the return value to rv
 * that takes place in the same statement, is unreachable. (This
 * assignment is itself a data flow.) The warning class for each of
 * these cases will depend on the nature of the statements in the
 * unreachable block.
 */
int unreachable_call(int x){
    int p;
    int rv = f(5); /* 'Unreachable Call' warning issued here */
    g();                       /* call (highest severity) */
    rv += x;                   /* computation */
    if (x>5) {                 /* conditional */ 
      return 0;                /* data flow */
    }
    p = rv;                    /* data flow */
    return p;
}

int unreachable_computation(int x){
    int p;
    int rv = f(5); /* 'Unreachable Computation' warning issued here */
    rv += x;                   /* computation (highest severity) */   
    if (x>5) {                 /* conditional */ 
      return 0;                /* data flow */
    }
    p = rv;                    /* data flow */
    return p;
}

int unreachable_conditional(int x){
    int p;
    int rv = f(5); /* 'Unreachable Conditional' warning issued here */ 
    if (x>5) {                 /* conditional (highest severity) */ 
      return 0;                /* data flow */
    }
    p = rv;                    /* data flow */
    return p;
}

int unreachable_data_flow(){
   int p;
   int rv = f(5);  /* 'Unreachable Data Flow' warning issued here */
   p = rv;                    /* data flow */
   return p;
}


/* In unreachable_control_flow(), a return statement is unreachable
 * because it is in the TRUE branch of an IF statement whose condition
 * always evaluates to FALSE.
 */
void unreachable_control_flow(int x, int y){
    char *q = NULL;
    while (q==NULL){
       q = (char *) malloc(5 * sizeof(char));
    }
    if (q==NULL) {                       /* ('Redundant Condition' warning issued here) */
        return;    /* 'Unreachable Control Flow' warning issued here */
    }
    free(q);
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.