Main Content

Review and Fix Function Not Reachable Checks

This topic describes how to systematically review the results of a Function not reachable check in Polyspace® Code Prover™.

Follow one or more of these steps until you determine a fix for the Function not reachable check. There are multiple ways to fix this check. For a description of the check and code examples, see Function not reachable.

If you determine that the check represents defensive code, add a comment and justification in your result or code explaining why you did not change your code. See Address Results in Polyspace User Interface Through Bug Fixes or Justifications or Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access).

Note

This check is not turned on by default. To turn on this check, you must specify the appropriate analysis option. For more information, see Detect uncalled functions (-uncalled-function-checks).

Step 1: Interpret Check Information

Select the check on the Results List pane. On the Source pane, you can see the function definition in gray.

Step 2: Determine Root Cause of Check

Determine where the function is called and review why all the function call sites are unreachable. You can perform the following steps in the Polyspace user interface only.

  1. Select the check on the Results List pane.

  2. On the Result Details pane, click the button.

    On the Call Hierarchy pane, you see the callers of the function denoted by .

  3. On the Call Hierarchy pane, select each caller.

    This action takes you to the function call on the Source pane.

  4. See if the caller itself is called from unreachable code. If the caller definition is entirely in gray on the Source pane, it is called from unreachable code. Follow the same investigation process, starting from step 1, for the caller.

  5. Otherwise, investigate why the section of code from which you call the function is unreachable.

    The code can be unreachable because it follows a red check or because it contains the gray Unreachable code check.

    • If a red check occurs, fix your code to remove the check.

    • If a gray Unreachable code check occurs, review the check and determine if you must fix your code. See Review and Fix Unreachable Code Checks.

Note

If you do not see a caller name on the Call Hierarchy pane, determine if you are calling the function indirectly, for example through a function pointer. Determine if a mismatch occurs between the function pointer declaration and the function call through the pointer.

Polyspace places a red or orange Correctness condition check on the indirect call if a mismatch occurs. To detect a mismatch in indirect function calls, look for the Correctness condition check on the Results List pane. For more information, see Correctness condition.