[Bug tree-optimization/38378] New: missed optimisation: function referenced through unused function pointer not removed

patrick at motec dot com dot au gcc-bugzilla@gcc.gnu.org
Wed Dec 3 01:38:00 GMT 2008


The following (contrived) example was compiled with -O3 -fwhole-program.

void func1() { }
void func2(void(*fn)(void)) { fn(); }
void func3() { func2(&func1); }

int main()
{
        return 0;
}


running objdump on the output results in

00000000 <func1>:
   0:   4e 80 00 20     blr

00000004 <main>:
   4:   94 21 ff f8     stwu    r1,-8(r1)
   8:   7c 08 02 a6     mflr    r0
   c:   90 01 00 0c     stw     r0,12(r1)
  10:   48 00 00 01     bl      10 <main+0xc>
  14:   80 01 00 0c     lwz     r0,12(r1)
  18:   38 60 00 00     li      r3,0
  1c:   38 21 00 08     addi    r1,r1,8
  20:   7c 08 03 a6     mtlr    r0
  24:   4e 80 00 20     blr

I don't expect any code for func1 to be emitted. It is never called, and func3
which takes it's address has been removed. This is obviously a bigger problem
if func2 were to do some real work.

compiler output:

powerpc-eabispe-gcc -O3 -fwhole-program -v -c tes
t.c
Using built-in specs.
Target: powerpc-eabispe
Configured with: /home/patrick/src/e7/toolchain/src/gcc-4.3.2/configure
--prefix=/home/patrick/src/e7/toolchain/stage2 --build=x86_64-unknown-linux-gnu
--host=x86_64-unknown-linux-gnu --target=powerpc-eabispe --enable-languages=c
--disable-nls --disable-werror --without-newlib
--with-gmp=/home/patrick/src/e7/toolchain/stage2
--with-mpfr=/home/patrick/src/e7/toolchain/stage2 --disable-shared
--disable-debug --disable-libssp
Thread model: single
gcc version 4.3.2 (GCC) 
COLLECT_GCC_OPTIONS='-O3' '-fwhole-program' '-v' '-c'
 /home/patrick/src/e7/toolchain/stage2/libexec/gcc/powerpc-eabispe/4.3.2/cc1
-quiet -v test.c -quiet -dumpbase test.c -auxbase test -O3 -version
-fwhole-program -o /tmp/ccHjWmTp.s
ignoring nonexistent directory
"/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/../../../../powerpc-eabispe/sys-include"
ignoring nonexistent directory
"/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/../../../../powerpc-eabispe/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/include

/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/include-fixed
End of search list.
GNU C (GCC) version 4.3.2 (powerpc-eabispe)
        compiled by GNU C version 4.2.3 (Ubuntu 4.2.3-2ubuntu7), GMP version
4.2.4, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c30b16423d0b6addaa52d5eb1153852d
COLLECT_GCC_OPTIONS='-O3' '-fwhole-program' '-v' '-c'

/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/../../../../powerpc-eabispe/bin/as
-mppc -mspe -me500 -many -V -Qy -o test.o /tmp/ccHjWmTp.s
GNU assembler version 2.18 (powerpc-eabispe) using BFD version (GNU Binutils)
2.18
COMPILER_PATH=/home/patrick/src/e7/toolchain/stage2/libexec/gcc/powerpc-eabispe/4.3.2/:/home/patrick/src/e7/toolchain/stage2/libexec/gcc/powerpc-eabispe/4.3.2/:/home/patrick/src/e7/toolchain/stage2/libexec/gcc/powerpc-eabispe/:/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/:/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/:/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/../../../../powerpc-eabispe/bin/
LIBRARY_PATH=/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/:/home/patrick/src/e7/toolchain/stage2/lib/gcc/powerpc-eabispe/4.3.2/../../../../powerpc-eabispe/lib/
COLLECT_GCC_OPTIONS='-O3' '-fwhole-program' '-v' '-c'


-- 
           Summary: missed optimisation: function referenced through unused
                    function pointer not removed
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: patrick at motec dot com dot au


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38378



More information about the Gcc-bugs mailing list