Need help eliminating dead code paths and variables from C source code
- by Anjum Kaiser
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:
variables which are being read just for the sake of reading from them.
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;