Questions tagged [dead-code]

Dead code is code in the source code of a program which is executed but whose result is never used or a code that can never be reached or used.

Dead code is code in the source code of a program which is executed but whose result is never used or a code that can never be reached or used.

Dead code is waste of computing power and might result of unexpected behavior to the program.

Examples:

int foo (int a, int b)
{
    int c = a + b;  // dead code - executes and result never used 
    return a - b;
}

void foo ()
{
     bool a = true;
     if (!a)
     {
         // dead code - never called
     }
}
238 questions
3
votes
7 answers

How to keep unreachable code?

I'd like to write a function that would have some optional code to be executed or not depending on user settings. The function is cpu-intensive and having ifs in it would be slow since the branch predictor is not that good. My idea is making a copy…
Gabriel
  • 2,841
  • 4
  • 33
  • 43
3
votes
2 answers

Visual Studio - plugin finding/removing dead code?

Anyone knows any free Visual Studio add-in that would find and/or delete dead (unused) code? I saw such possibility in MZ-Tools, but it's a little expensive as for private use ;)
brovar
  • 811
  • 4
  • 10
  • 25
3
votes
2 answers

Find dead code in f# program

Is there a tool that detects unused code in F# programs? Tools for F# have been discussed from time to time, but it has been a while since this question: Are there any support tools like coderush or resharper for F#?
citykid
  • 9,916
  • 10
  • 55
  • 91
3
votes
1 answer

Finding dead code in Android apk

I'm trying to find dead code in .apk file for some analysis. For this, I'm using dex2jar on classes.dex file and then trying to use Proguard to detect dead code. But Proguard fails to run giving error that it can't find some dynamically referenced…
user401445
  • 1,014
  • 1
  • 16
  • 41
3
votes
1 answer

GLSL: Removal of dead code causes visual errors

I've been having a lot of strange problem's while trying to write a raytracer in an opengl shader. I try to determine if the source of the error is myself, and often this is the case, but I've come to the conclusion that some of these problems may…
user2345397
  • 301
  • 1
  • 11
3
votes
2 answers

Does GCC LTO perform cross-file dead code elimination?

Say I have a function void do_something() { //.... #ifdef FEATURE_X feature_x(); #endif //.... } I can compile and run this with no problems; if I want the feature I can pass -D FEATURE_X and it works. However, what if I…
zebediah49
  • 7,467
  • 1
  • 33
  • 50
2
votes
2 answers

Disabling specific optimization(Dead code elimination) in gcc compiler

I would like to disable dead code elimination optimization in c++ compilation. Is there a way to disable this particular optimization by keeping all other -O optimization. I tried with -fnodce but its not working. Update (copied from a comment): I…
user1167158
  • 31
  • 1
  • 2
2
votes
1 answer

SuppressWarnings "all" complaint from Eclipse

What is wrong with the SuppressWarnings annotation above the if statement? Eclipse with Sun JDK 6 provides two syntax error descriptions, both unhelpful and hard to understand, shown in comments. class TestDeadCode { //@SuppressWarnings("all") …
H2ONaCl
  • 10,644
  • 14
  • 70
  • 114
2
votes
2 answers

React is not being used, yet is still pulled in into a bundle

tldr; what is preventing React from being dead-code eliminated in my project? It is not being used, apart in an unused utility in a library I am consuming. I recently created a little library for retrying failing dynamic imports. I made a…
oligofren
  • 20,744
  • 16
  • 93
  • 180
2
votes
2 answers

How to understand a line of dead code in a python function?

The following code comes from Ply, python’s lexer and parser. I understand the first line is a raw string but I also feel that the first line of the code looks like dead code and will be discarded in execution. How could I understand that line of…
zell
  • 9,830
  • 10
  • 62
  • 115
2
votes
2 answers

Resolve undefined reference by stripping unused code

Assume we have the following C code: void undefined_reference(void); void bad(void) { undefined_reference(); } int main(void) {} In function bad we fall into the linker error undefined reference to 'undefined_reference', as expected. This…
Post Self
  • 1,471
  • 2
  • 14
  • 34
2
votes
1 answer

My Simpler Dead-code Remover

I am doing a stimulation of dead-code remover in a very simpler manner. For that my Idea is to, Step 1: Read the input C-Program line by line and store it in a doubly linked-list or Array.(Since deletion and insertion will be easier than in file…
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77
2
votes
2 answers

Android studio code inspection shell script for integration in CI pipeline

I am trying to integrate dead code analysis for my android app to improve code quality. I found out the code inspection option that android studio provides out of the box which is giving me an extensive report of unused code and suggested…
Gurunath Sripad
  • 1,308
  • 2
  • 14
  • 24
2
votes
2 answers

Finding unused code in Java with AspectJ

I have an idea for finding unused ('dead') methods in a large Java project but I need help deriving an implementation. Use AspectJ to add a 'before' aspect to ALL methods in project packages. The aspect will simply record (?) that the method has…
hoipolloi
  • 7,984
  • 2
  • 27
  • 28
2
votes
0 answers

How -dead_strip work on Objective-C code?

In https://opensource.apple.com/source/cctools/cctools-836/RelNotes/CompilerTools.html The static linker has an option to do dead code stripping The static link editor now can do dead code stripping. The new ld(1) option to do this is -dead_strip.…
userhua
  • 21
  • 1