Unreachable Code - Analysis

Analysis

Detecting unreachable code is a form of static analysis and involves performing control flow analysis to find any code that will never be executed regardless of the values of variables and other conditions at run time. In some languages (e.g. Java ) some forms of unreachable code are explicitly disallowed. The optimization that removes unreachable code is known as dead code elimination.

Code may become unreachable as a consequence of the internal transformations performed by an optimizing compiler (e.g., common subexpression elimination).

In practice the sophistication of the analysis performed has a significant impact on the amount of unreachable code that is detected. For example, constant folding and simple flow analysis shows that the statement xyz in the following code is unreachable:

int iN = 2 + 1; if (iN == 4) { xyz }

However, a great deal more sophistication is needed to work out that the statement xyz is unreachable in the following code:

double dX = sqrt(2); if (dX > 5) { xyz }

The unreachable code elimination technique is in the same class of optimizations as dead code elimination and redundant code elimination.

Read more about this topic:  Unreachable Code

Famous quotes containing the word analysis:

    Whatever else American thinkers do, they psychologize, often brilliantly. The trouble is that psychology only takes us so far. The new interest in families has its merits, but it will have done us all a disservice if it turns us away from public issues to private matters. A vision of things that has no room for the inner life is bankrupt, but a psychology without social analysis or politics is both powerless and very lonely.
    Joseph Featherstone (20th century)

    Ask anyone committed to Marxist analysis how many angels on the head of a pin, and you will be asked in return to never mind the angels, tell me who controls the production of pins.
    Joan Didion (b. 1934)