Knowledge (XXG)

Unreachable code

Source 📝

932:
Dead code – Executable Object Code (or data) which exists as a result of a software development error but cannot be executed (code) or used (data) in any operational configuration of the target computer environment. It is not traceable to a system or software requirement. The following exceptions are
148:
An example of such a conditionally unreachable code may be the implementation of a general string formatting function in a compiler's runtime library, which contains complex code to process all possible arguments, of which only a small subset is actually used. Compilers will typically not be able to
957:
The combination of requirements traceability with coverage analysis can also turn up areas of "dead code," or code that's never executed. This code can mostly be an inconvenience, but it can also be a security threat if a hacker can gain access and from there gain control. It's code that can't be
144:
Legacy code is that which was once useful but is no longer used or required. But unreachable code may also be part of a complex library, module or routine where it is useful to others or under conditions which are not met in a particular scenario.
933:
often mistakenly categorized as dead code but are necessary for implementation of the requirements/design: embedded identifiers, defensive programming structures to improve robustness, and deactivated code such as unused library functions.
98:. This is particularly useful for examining and pretty-printing the internal state of the program. It may make sense to have such code in the shipped product, so that a developer can attach a debugger to a client's running instance. 815:
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.
920: 673:
In practice the sophistication of the analysis has a significant impact on the amount of unreachable code that is detected. For example,
848:– the general problem of determining whether a piece of code is unreachable is at least as hard as the halting problem and hence 1047: 732:
However, a great deal more sophistication is needed to work out that the corresponding block is unreachable in the following code:
639:. A compiler is free to implement any behavior or none, and typically an optimizing compiler will assume the code is unreachable. 667: 1118: 149:
remove the unused code sections at compile time, as the behavior is largely determined by the values of arguments at run time.
90:
Unreachable code can have some legitimate uses, like providing a library of functions for calling or jumping to manually via a
1074:
Because compilers are not obligated to generate code for undefined behavior, these behaviors are candidates for optimization.
1061: 869:
Debray, Saumya K.; Evans, William; Muth, Robert; De Sutter, Bjorn (1 March 2000). "Compiler techniques for code compaction".
946: 655:) some forms of unreachable code are explicitly disallowed. The optimization that removes unreachable code is known as 1123: 804: 652: 250: 1086: 878: 677:
and simple flow analysis shows that the inside of the if-statement in the following code is unreachable:
803:
In some cases, a practical approach may be a combination of simple unreachability criteria and use of a
788: 656: 648: 1128: 31: 971: 883: 849: 663: 114: 129:
Unreachable code that a programmer decided not to delete because it is mingled with reachable code
993:. Any operation that is executed but whose removal would not affect program behavior constitutes 896: 636: 651:
to find code that can never be reached in any possible program state. In some languages (e.g.
68: 888: 674: 254: 81:
Time and effort may be spent testing, maintaining and documenting code which is never used
1013: 845: 914: 1033: 830: 792: 1099:
Appel, A. W. 1998 Modern Compiler Implementation in Java. Cambridge University Press.
57:
may also refer to code that is executed but has no effect on the output of a program.
1112: 1048:"sslKeyExchange.c - Source code for support for key exchange and server key exchange" 825: 74: 916:
RTCA/DO-178C Software Considerations in Airborne Systems and Equipment Certification
592:
statements. In the syntax of the C language, the second is unconditional, and hence
900: 604:
will hold the status of the SHA1 update operation, and signature verification will
43: 1104:
Muchnick S. S. 1997 Advanced Compiler Design and Implementation. Morgan Kaufmann.
258: 787:
Unreachable code elimination technique is in the same class of optimizations as
662:
Code may become unreachable as a consequence of transformations performed by an
623:
includes unreachable code analysis, which would trigger an alarm for this code.
39: 947:"Requirements Traceability Forms the Foundation for Thorough Software Testing" 840: 95: 977: 835: 812: 54: 892: 237:
is never reached as the function always returns before it. Therefore, the
60:
Unreachable code is generally considered undesirable for several reasons:
91: 17: 811:
anything about the unreachability of a piece of code, but may be a good
261:
and informally as the "goto fail bug". The relevant code fragment is:
973:
MISRA C:2012 Guidelines for the used of C language in critical systems
253:
from February 2014 contained a major security flaw known formally as
632: 616: 135:
Dormant code that is kept intentionally in case it is needed later
42:
of a program which can never be executed because there exists no
807:
to handle the more complex cases. Profiling in general can not
113:
a consequence of the internal transformations performed by an
84:
Sometimes an automated test is the only thing using the code.
132:
Potentially reachable code that current use cases never need
27:
Section of code in a program that can never be executed
106:
Unreachable code can exist for many reasons, such as:
871:
ACM Transactions on Programming Languages and Systems
241:need be neither allocated storage nor initialized. 1027: 1025: 1023: 110:programming errors in complex conditional branches 46:path to the code from the rest of the program. 1062:"MSC15-C. Do not depend on undefined behavior" 1034:"Learning from Apple's #gotofail Security Bug" 611:Here, the unreachable code is the call to the 8: 647:Detection of unreachable code is a form of 1007: 1005: 958:traced and should therefore be eliminated. 120:incomplete testing of new or modified code 67:It can cause unnecessary use of the CPU's 49:Unreachable code is sometimes also called 882: 126:Code superseded by another implementation 635:, some constructs are specified to have 861: 7: 94:while the program is halted after a 1064:. Carnegie Mellon University. 2020 25: 668:common subexpression elimination 272:SSLVerifySignedServerKeyExchange 970:MISRA Consortium (March 2013). 588:Here, there are two successive 945:Jay Thomas (24 January 2017). 1: 1087:"Java Language Specification" 140:Code used only for debugging. 799:Unreachability vs. profiling 157:In this fragment of C code: 64:It uses memory unnecessarily 989:Rule 2.2 there shall be no 1145: 1032:Arie van Deursen (2014). 619:compiler with the option 734: 679: 263: 159: 615:function. Applying the 73:This can also decrease 1119:Compiler optimizations 1014:"Apple's SSL/TLS bug" 1012:Adam Langley (2014). 893:10.1145/349214.349233 789:dead code elimination 657:dead code elimination 649:control flow analysis 600:. As a consequence, 32:computer programming 664:optimizing compiler 115:optimizing compiler 1124:Software anomalies 637:undefined behavior 596:skips the call to 923:2011. p. 112 779:/* unreachable */ 724:/* unreachable */ 598:SSLHashSHA1.final 69:instruction cache 16:(Redirected from 1136: 1105: 1100: 1091: 1090: 1083: 1077: 1076: 1071: 1069: 1058: 1052: 1051: 1044: 1038: 1037: 1029: 1018: 1017: 1009: 1000: 999: 986: 985: 967: 961: 960: 954: 953: 942: 936: 935: 929: 928: 911: 905: 904: 886: 866: 783: 780: 777: 774: 771: 768: 765: 762: 759: 756: 753: 750: 747: 744: 741: 738: 728: 725: 722: 719: 716: 713: 710: 707: 704: 701: 698: 695: 692: 689: 686: 683: 675:constant folding 622: 614: 603: 599: 591: 584: 581: 578: 575: 572: 569: 566: 563: 560: 557: 554: 551: 548: 545: 542: 539: 536: 533: 530: 527: 524: 521: 518: 515: 512: 509: 506: 503: 500: 497: 494: 491: 488: 485: 482: 479: 476: 473: 472: 469: 466: 462: 459: 456: 453: 450: 447: 444: 441: 438: 435: 432: 429: 426: 423: 420: 417: 414: 411: 408: 405: 402: 399: 396: 393: 390: 387: 384: 381: 378: 375: 372: 369: 366: 363: 360: 357: 354: 351: 348: 345: 342: 339: 336: 333: 330: 327: 324: 321: 318: 315: 312: 309: 306: 303: 300: 297: 294: 291: 288: 285: 282: 279: 276: 273: 270: 267: 240: 236: 229: 226: 223: 220: 217: 214: 211: 208: 205: 202: 199: 196: 193: 190: 187: 184: 181: 178: 175: 172: 169: 166: 163: 36:unreachable code 21: 1144: 1143: 1139: 1138: 1137: 1135: 1134: 1133: 1109: 1108: 1103: 1098: 1095: 1094: 1085: 1084: 1080: 1067: 1065: 1060: 1059: 1055: 1046: 1045: 1041: 1031: 1030: 1021: 1011: 1010: 1003: 983: 981: 969: 968: 964: 951: 949: 944: 943: 939: 926: 924: 913: 912: 908: 868: 867: 863: 858: 846:Halting problem 822: 801: 785: 784: 781: 778: 775: 772: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 739: 736: 730: 729: 726: 723: 720: 717: 714: 711: 708: 705: 702: 699: 696: 693: 690: 687: 684: 681: 645: 629: 620: 612: 601: 597: 589: 586: 585: 582: 579: 576: 573: 570: 567: 564: 561: 558: 555: 552: 549: 546: 543: 540: 537: 534: 531: 528: 525: 522: 519: 516: 513: 510: 507: 504: 501: 498: 495: 492: 489: 486: 483: 480: 477: 474: 470: 467: 464: 463: 460: 457: 454: 451: 448: 445: 442: 439: 436: 433: 430: 427: 424: 421: 418: 415: 412: 409: 406: 403: 400: 397: 394: 391: 388: 385: 382: 379: 376: 373: 370: 367: 364: 361: 358: 355: 352: 349: 346: 343: 340: 337: 334: 331: 328: 325: 322: 319: 316: 313: 310: 307: 304: 301: 298: 295: 292: 289: 286: 283: 280: 277: 274: 271: 268: 265: 247: 238: 234: 233:the definition 231: 230: 227: 224: 221: 218: 215: 212: 209: 206: 203: 200: 197: 194: 191: 188: 185: 182: 179: 176: 173: 170: 167: 164: 161: 155: 104: 38:is part of the 28: 23: 22: 15: 12: 11: 5: 1142: 1140: 1132: 1131: 1126: 1121: 1111: 1110: 1107: 1106: 1101: 1093: 1092: 1078: 1053: 1039: 1019: 1001: 962: 937: 906: 884:10.1.1.43.7215 877:(2): 378–415. 860: 859: 857: 854: 853: 852: 843: 838: 833: 831:Redundant code 828: 821: 818: 800: 797: 793:redundant code 735: 680: 644: 641: 628: 625: 264: 246: 243: 235:int Z = X * Y; 160: 154: 151: 142: 141: 138: 137: 136: 133: 130: 127: 121: 118: 111: 103: 100: 88: 87: 86: 85: 79: 78: 77: 65: 26: 24: 14: 13: 10: 9: 6: 4: 3: 2: 1141: 1130: 1127: 1125: 1122: 1120: 1117: 1116: 1114: 1102: 1097: 1096: 1088: 1082: 1079: 1075: 1063: 1057: 1054: 1049: 1043: 1040: 1035: 1028: 1026: 1024: 1020: 1015: 1008: 1006: 1002: 998: 996: 992: 979: 975: 974: 966: 963: 959: 948: 941: 938: 934: 922: 918: 917: 910: 907: 902: 898: 894: 890: 885: 880: 876: 872: 865: 862: 855: 851: 847: 844: 842: 839: 837: 834: 832: 829: 827: 826:Code coverage 824: 823: 819: 817: 814: 810: 806: 798: 796: 795:elimination. 794: 790: 733: 678: 676: 671: 669: 665: 660: 658: 654: 650: 642: 640: 638: 634: 626: 624: 618: 609: 607: 595: 559:SSLFreeBuffer 544:SSLFreeBuffer 262: 260: 256: 252: 245:goto fail bug 244: 242: 158: 152: 150: 146: 139: 134: 131: 128: 125: 124: 122: 119: 116: 112: 109: 108: 107: 101: 99: 97: 93: 83: 82: 80: 76: 75:data locality 72: 71: 70: 66: 63: 62: 61: 58: 56: 52: 47: 45: 41: 37: 33: 19: 1081: 1073: 1068:28 September 1066:. Retrieved 1056: 1042: 994: 990: 988: 982:. Retrieved 980:. p. 41 978:MIRA Limited 972: 965: 956: 950:. Retrieved 940: 931: 925:. Retrieved 915: 909: 874: 870: 864: 808: 802: 786: 731: 672: 661: 646: 630: 621:-Weverything 610: 605: 593: 587: 553:signedHashes 440:signedParams 380:serverRandom 323:signatureLen 302:signedParams 248: 232: 156: 147: 143: 123:Legacy code 105: 89: 59: 50: 48: 44:control flow 35: 29: 1129:Source code 850:undecidable 487:SSLHashSHA1 416:SSLHashSHA1 356:SSLHashSHA1 53:, although 40:source code 1113:Categories 984:2019-06-11 952:2019-06-11 927:2019-06-11 921:RTCA, Inc. 856:References 841:Oxbow code 278:SSLContext 96:breakpoint 995:dead code 991:dead code 879:CiteSeerX 836:Dead code 813:heuristic 590:goto fail 314:signature 299:SSLBuffer 259:2014-1266 55:dead code 51:dead code 18:Goto fail 820:See also 805:profiler 643:Analysis 332:OSStatus 269:OSStatus 249:Apple's 153:Examples 92:debugger 901:6129772 666:(e.g., 568:hashCtx 511:hashOut 502:hashCtx 431:hashCtx 371:hashCtx 308:uint8_t 251:SSL/TLS 899:  881:  737:double 608:fail. 594:always 574:return 422:update 362:update 320:UInt16 266:static 192:return 102:Causes 897:S2CID 809:prove 617:Clang 613:final 606:never 565:& 550:& 508:& 499:& 493:final 437:& 428:& 377:& 368:& 293:isRsa 1070:2020 791:and 767:> 746:sqrt 653:Java 538:fail 529:fail 526:goto 468:fail 465:goto 458:fail 455:goto 398:fail 395:goto 290:bool 889:doi 682:int 670:). 633:C++ 631:In 627:C++ 602:err 577:err 535:... 481:err 410:err 350:err 341:... 335:err 284:ctx 255:CVE 207:int 180:int 171:int 165:foo 162:int 30:In 1115:: 1072:. 1022:^ 1004:^ 987:. 976:. 955:. 930:. 919:. 895:. 887:. 875:22 873:. 758:if 755:); 712:== 703:if 659:. 571:); 556:); 517:!= 514:)) 478:(( 475:if 446:!= 443:)) 407:(( 404:if 386:!= 383:)) 347:(( 344:if 34:, 1089:. 1050:. 1036:. 1016:. 997:. 903:. 891:: 782:} 776:{ 773:) 770:5 764:X 761:( 752:2 749:( 743:= 740:X 727:} 721:{ 718:) 715:4 709:N 706:( 700:; 697:1 694:+ 691:2 688:= 685:N 583:} 580:; 562:( 547:( 541:: 532:; 523:) 520:0 505:, 496:( 490:. 484:= 471:; 461:; 452:) 449:0 434:, 425:( 419:. 413:= 401:; 392:) 389:0 374:, 365:( 359:. 353:= 338:; 329:{ 326:) 317:, 311:* 305:, 296:, 287:, 281:* 275:( 257:- 239:Z 228:} 225:; 222:Y 219:* 216:X 213:= 210:Z 204:; 201:Y 198:+ 195:X 189:{ 186:) 183:Y 177:, 174:X 168:( 117:; 20:)

Index

Goto fail
computer programming
source code
control flow
dead code
instruction cache
data locality
debugger
breakpoint
optimizing compiler
SSL/TLS
CVE
2014-1266
Clang
C++
undefined behavior
control flow analysis
Java
dead code elimination
optimizing compiler
common subexpression elimination
constant folding
dead code elimination
redundant code
profiler
heuristic
Code coverage
Redundant code
Dead code
Oxbow code

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.