unusedcode some step further

Thomas Arnhold thomas-libo at arnhold.org
Mon Apr 1 06:19:27 PDT 2013


Hi,

there are several unused methods in the source which callcatcher doesn't 
catch. Two examples: 08b91c63131b7e625d2a2c489bc537dafe5c5963 and 
c12ab867f282e783507fcf74ab5c90e784681f65 which had only (virtual) 
definitions, but no calls.

The same applies to inlines like 
646daee253b69404591c006ec6e717b6660af30b. Defined, but no calls.

So the idea is to get something like a list of all methods in the 
project. First counting (virtual) definitions and second counting all calls.

Counting the calls is not as easy as it seems. So I had the idea to 
preprocess the source files with -fpreprocessed -dD -E to get source 
files without comments and much other cruft removed (which may lead to 
false-positives). Counting in those files seems easier. So it would be 
1st count definitions, 2nd count all occurrences. If they are equal 
there are no calls.

This would be a way to find possible candidates for removal (excluding 
DLLPUBLIC stuff). Pros: platform independent. Cons: No macro expansion, 
if there are several independent methods which have the same name, but 
one is unused it's not possible to identify the unused one. So it will 
only identify a fraction of all unused stuff. The question is how big is 
this fraction ;)

So my question: Is it worth doing this (because it's not the cleanest 
way)? Or did I miss something, especially the point "no calls, no users"?


Another possible way: gcc with -fdata-sections and -ffunction-sections 
[1]. Where both results could be compared and unused methods could be 
identified. But I didn't try that. Did anyone do such thing?

Thomas


[1] 
http://embeddedfreak.wordpress.com/2009/02/10/removing-unused-functionsdead-codes-with-gccgnu-ld/


More information about the LibreOffice mailing list