https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80680
Bug ID: 80680 Summary: dead code elimination fails to remove unreferenced function Product: gcc Version: 6.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zmahler at openmailbox dot org Target Milestone: --- With the following code, gcc will produce code for yes() even though it is not referenced anymore after optimization. Less problematic but probably related is that the call to no() is surprisingly not inlined, and the size of the code in the optimized away branch seems to have an influence on that. #include <stdio.h> static inline void yes(void) { puts("yes"); } static inline void no(void) { puts("no"); } static inline void test(int v) { if (v & 1) { printf("%d%d%d%d%d%d%d%d%d%d", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } (v ? yes : no)(); } int main(void) { test(0); } 0000000000400430 <main>: 400430: 48 83 ec 08 sub rsp,0x8 400434: e8 07 01 00 00 call 400540 <no> 400439: 31 c0 xor eax,eax 40043b: 48 83 c4 08 add rsp,0x8 40043f: c3 ret 0000000000400540 <no>: 400540: bf e4 05 40 00 mov edi,0x4005e4 400545: e9 d6 fe ff ff jmp 400420 <puts@plt> 40054a: 66 0f 1f 44 00 00 nop WORD PTR [rax+rax*1+0x0] 0000000000400550 <yes>: 400550: bf e7 05 40 00 mov edi,0x4005e7 400555: e9 c6 fe ff ff jmp 400420 <puts@plt> 40055a: 66 0f 1f 44 00 00 nop WORD PTR [rax+rax*1+0x0] $ gcc --version gcc (SUSE Linux) 6.3.1 20170202 [gcc-6-branch revision 245119]