Need help eliminating dead code paths and variables from C source code

Posted by Anjum Kaiser on Programmers See other posts from Programmers or by Anjum Kaiser
Published on 2012-07-06T06:04:12Z Indexed on 2012/07/06 9:23 UTC
Read the original article Hit count: 275

Filed under:
|

I have a legacy C code on my hands, and I am given the task to filter dead/unused symbols and paths from it. Over the time there were many insertions and deletions, causing lots of unused symbols. I have identified many dead variables which were only being written to once or twice, but were never being read from.

Both blackbox/whitebox/regression testing proved that dead code removal did not affected any procedures. (We have a comprehensive test-suite).

But this removal was done only on a small part of code. Now I am looking for some way to automate this work.

We rely on GCC to do the work.

P.S. I'm interested in removing stuff like:

  1. variables which are being read just for the sake of reading from them.
  2. variables which are spread across multiple source files and only being written to.

For example:

file1.c:
int i;

file2.c:
extern int i;
....
i=x;

© Programmers or respective owner

Related posts about c

    Related posts about gcc