https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65534
Bug ID: 65534 Summary: tailcall not optimized away Product: gcc Version: 5.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: aldot at gcc dot gnu.org CC: hubicka at ucw dot cz, rguenth at gcc dot gnu.org Maybe this could be optimized by a thunk or by creating the alias automatically or the like? Or is tailcall supposed to do this already? trunk@221345 $ gcc -Os -c missed-opt.c -o missed-opt.plain.o $ gcc -Os -c missed-opt.c -o missed-opt.manual.o -DOPTIMIZE_MANUALLY $ size missed-opt.*.o text data bss dec hex filename 86 0 0 86 56 missed-opt.manual.o 104 0 0 104 68 missed-opt.plain.o $ cat missed-opt.c ; echo EOF static int fd = -1; extern void dummy0(void); extern void dummy1(int); extern void setutent(void) __attribute__ ((__nothrow__ )); extern __typeof (setutent) setutent __asm__ ("" "__GI_setutent") __attribute__ ((visibility ("hidden"))); extern void getutent(void) __attribute__ ((__nothrow__ )); extern __typeof (getutent) getutent __asm__ ("" "__GI_getutent") __attribute__ ((visibility ("hidden"))); static void __setutent_unlocked(void) { if (fd < 0) { dummy0(); if (fd < 0) { dummy0(); if (fd < 0) return; } return; } dummy1(fd); } #ifndef OPTIMIZE_MANUALLY void setutent(void) { ((void)0); __setutent_unlocked(); ((void)0); } #else extern __typeof (__setutent_unlocked) setutent __attribute__ ((alias ("__setutent_unlocked"))); #endif extern __typeof (setutent) __EI_setutent __asm__("" "setutent"); extern __typeof (setutent) __EI_setutent __attribute__((alias ("" "__GI_setutent"))); static void __getutent_unlocked(void) { if (fd < 0) __setutent_unlocked(); } #ifndef OPTIMIZE_MANUALLY void getutent(void) { ((void)0); __getutent_unlocked(); ((void)0); } #else extern __typeof (__getutent_unlocked) getutent __attribute__ ((alias ("__getutent_unlocked"))); #endif extern __typeof (getutent) __EI_getutent __asm__("" "getutent"); extern __typeof (getutent) __EI_getutent __attribute__((alias ("" "__GI_getutent"))); EOF