retaining unused static functions at -O1

VandeVondele Joost joost.vandevondele@mat.ethz.ch
Sat Oct 17 07:18:00 GMT 2015


I would like to run coverage tests at '-O1' (using -coverage and lcov, gaining >2x time over -O0), but unfortunately unused functions (e.g. static functions not called) are removed from the coverage report at -O1, which otherwise looks good to me.

So, the question: is there a way to compile at -O1 but keep all functions ? (i tried -fno-tree-dce but that didn't help). Bonus points if this also works for Fortran.  (I'm aware of -Wunused-functions, but this doesn't fit the requirements).

testcase: 

> cat test.c
static void foo()
{
}
void bar()
{
}

> gcc -c -O0 test.c ; nm test.
0000000000000007 T bar
0000000000000000 t foo

> gcc -c -O1 test.c ; nm test.o
0000000000000000 T bar

Thanks,

Joost


More information about the Gcc-help mailing list