Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Unreachable code
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Analysis== Detection of unreachable code is a form of [[control flow analysis]] to find code that can never be reached in any possible program state. In some languages (e.g. [[Java (programming language)|Java]]<ref>{{cite web|title=Java Language Specification|url=http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.21}}</ref>) 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 transformations performed by an [[optimizing compiler]] (e.g., [[common subexpression elimination]]). In practice the sophistication of the analysis has a significant impact on the amount of unreachable code that is detected. For example, [[constant folding]] and simple flow analysis shows that the inside of the if-statement in the following code is unreachable: <syntaxhighlight lang="C"> int N = 2 + 1; if (N == 4) { /* unreachable */ } </syntaxhighlight> However, a great deal more sophistication is needed to work out that the corresponding block is unreachable in the following code: <syntaxhighlight lang="C"> double X = sqrt(2); if (X > 5) { /* unreachable */ } </syntaxhighlight> Unreachable code elimination technique is in the same class of optimizations as [[dead code elimination]] and [[redundant code]] elimination. ===Unreachability vs. profiling=== In some cases, a practical approach may be a combination of simple unreachability criteria and use of a [[Profiler (computer science)|profiler]] to handle the more complex cases. Profiling in general can not ''prove'' anything about the unreachability of a piece of code, but may be a good [[heuristic]] for finding potentially unreachable code. Once a suspect piece of code is found, other methods, such as a more powerful code analysis tool, or even analysis by hand, could be used to decide whether the code is truly unreachable.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)