public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers
@ 2012-09-14 21:11 chip at pobox dot com
  2013-09-05 20:06 ` [Bug rtl-optimization/54585] " chip at pobox dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: chip at pobox dot com @ 2012-09-14 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54585
           Summary: stack space allocated but never used when calling
                    functions that return structs in registers
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: chip@pobox.com


Now that bug #44194 is fixed, and a returned structure used as a parameter is
no longer stored unnecessarily, a new bug is visible: a stack frame is being
allocated that is entirely unused.  On x86_64 target with the fix for 44194
backported to the 4.7 branch, this code:


#include <stdint.h>

struct blargh { uint32_t a, b, c; } foo();
void bar(uint32_t a, uint32_t b, uint32_t c);

void func() {
  struct blargh s = foo();
  bar(s.a, s.b, s.c);
}


no longer uses any stack memory at all, but still the function call reserves 24
bytes with "subq $24,%rsp" and promptly returns it with "addq $24,%rsp".   The
generated code looks like this:

 func:
        .cfi_startproc
        xorl    %eax, %eax
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        call    foo
        movq    %rax, %rsi
        movl    %eax, %edi
        addq    $24, %rsp
        .cfi_def_cfa_offset 8
        shrq    $32, %rsi
        jmp     bar
        .cfi_endproc


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-18 23:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-14 21:11 [Bug rtl-optimization/54585] New: stack space allocated but never used when calling functions that return structs in registers chip at pobox dot com
2013-09-05 20:06 ` [Bug rtl-optimization/54585] " chip at pobox dot com
2013-09-05 21:05 ` ebotcazou at gcc dot gnu.org
2013-09-23 20:05 ` chip at pobox dot com
2021-12-18 23:59 ` [Bug middle-end/54585] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).