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
4
votes
2 answers

dead code is not detected/reported in golang, by design?

I can take any function and throw panic("don't") right in the middle of it, not inside any branch or loop (making the remainder of the function "dead" code), and the go compiler will happily compile and run without reporting that as a…
Brad Peabody
  • 10,917
  • 9
  • 44
  • 63
4
votes
2 answers

C dead code detection while using ARM compiler

I am working on embedded systems. I use C to program and ARM compiler to compile. The code I am working on has been around for sometime an has been developed by multiple people. It uses function pointers as well. Are there any tools that may help me…
tdk
  • 342
  • 1
  • 13
4
votes
3 answers

Dead code warning in while loop with 2 if's

I can't see why Eclipse gives me a dead code warning for the code in the second if condition: boolean frameErreicht = false; while (!frameErreicht) { String line = reader.readLine(); if (line.matches("@\\d*")) { …
Big_Chair
  • 2,781
  • 3
  • 31
  • 58
4
votes
1 answer

What kind of code is a JavaScript engine likely to elide?

(This is a bit of an X-Y problem, but I decided to ask the question that interests me, rather than the one I strictly need at the moment.) I know the various modern JavaScript engines have dead code eliminators and other means to get rid of code…
kojiro
  • 74,557
  • 19
  • 143
  • 201
3
votes
1 answer

Remove dead code in JSP

I have a big project with a lot of code (most in JSP) and I like to find a tool that can remove dead code from all the JSP. Do you know or recommended me a good tool? I've looked into lots of tools that do this well for pure Java projects, but…
Noelia
  • 281
  • 1
  • 13
3
votes
3 answers

Can the gnat compiler find unused specification procedures/functions/variables?

Is there a warning option switch that will identify spec-level procedures, functions, or variables that are not called or referenced anywhere? I've tried the switches below without luck. This is what I'm currently using: -gnatwfilmopuvz -- m …
3
votes
1 answer

Rust book unit test example results in dead code warning - why?

While learning Rust and trying out the example unit test related code from the Rust book: https://doc.rust-lang.org/book/ch11-01-writing-tests.html I get a warning regarding dead code that clearly is being exercised by the unit test. Why is…
Khorkrak
  • 3,911
  • 2
  • 27
  • 37
3
votes
3 answers

Find unused functions in a C project by static analysis

I am trying to run static analysis on a C project to identify dead code i.e functions or code lines that are never ever called. I can build this project with Visual Studio .Net for Windows or using gcc for Linux. I have been trying to find some…
binW
  • 13,220
  • 11
  • 56
  • 69
3
votes
1 answer

Remove dead code before linking

In a project that consists of several statically linked object files, I am replacing one of them with a separate implementation. I would like to test my code even before I have implemented every symbol which the replaced object file provided, so I…
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
3
votes
3 answers

LLVM - Liveness Analysis to remove dead code

I'm trying to implement liveness analysis to remove dead instructions. I know that isInstructionTriviallyDead() exists, however, I want to learn how to remove code using def-use (or use-def) chains. The way I am currently doing it is I am iterating…
user3186023
3
votes
1 answer

How can I quickly determine which macros my code uses?

I have cut out a piece of code out of a larger (C) project. The code has many many macros defined, in many place - some of them are only used by the original, larger codebase, and not used by the part of the code I cut out. I want to quickly…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
3
votes
2 answers

How to check for dead java methods at runtime

I am trying to create an index of unused Java methods in the form of a json file. There are a couple different ways in which the methods can be referenced. I have already checked for all the other ways and have a relatively small list of possibly…
3
votes
0 answers

Dead virtual function elimination

Question (Can I get clang or perhaps some other optimizing tool shipped with LLVM to identify unused virtual functions in a C++ program, to mark them for dead code elimination? I guess not.) If there is no such functionality shipped with LLVM, how…
MvG
  • 57,380
  • 22
  • 148
  • 276
3
votes
1 answer

Clang removing dead code incorrectly

I think this is a bug in clang or the OSX linker, but I wanted to ask here to make sure. I have the following (simplified) setup in a C++ program. A singleton Repository class: class Repository { public: static Repository *instance(); void…
Tim
  • 4,560
  • 2
  • 40
  • 64
3
votes
1 answer

Can a java compiler optimize this code away?

Is a java compiler or runtime ( or any other language compiler ) smart enough to realize branch 3 can never happen , and optimize it away? I've seen this kind of "defensive programming" with many beginning developers, and wonder if this dead weight…
Gonen I
  • 5,576
  • 1
  • 29
  • 60