After fixing PR 39545, I got

[...@gnu-34 pr39545]$ cat f-1.i
struct line {
int length;
char contents[];
};

void foo (struct line);

struct line
bar ()
{
 struct line x;
 x.length = sizeof (struct line);
 foo (x);
 return x;
}
[...@gnu-34 pr39545]$ make f-1.s
/export/build/gnu/gcc-avx/build-x86_64-linux/stage1-gcc/xgcc
-B/export/build/gnu/gcc-avx/build-x86_64-linux/stage1-gcc/ -O2
-fno-asynchronous-unwind-tables -S -o f-1.s f-1.i
f-1.i: In function ‘bar’:
f-1.i:10: note: The ABI of passing struct with a flexible array member has
changed in GCC 4.4
[...@gnu-34 pr39545]$ cat f-1.s
        .file   "f-1.i"
        .text
        .p2align 4,,15
.globl bar
        .type   bar, @function
bar:
        subq    $40, %rsp
        movl    $4, 16(%rsp)
        movq    16(%rsp), %rdi
        call    foo
        movl    $4, %eax
        addq    $40, %rsp
        ret
        .size   bar, .-bar
[...@gnu-34 pr39545]$ cat f-3.i
struct line {
int length;
char contents[0];
};

void foo (struct line);

struct line
bar ()
{
 struct line x;
 x.length = sizeof (struct line);
 foo (x);
 return x;
}
[...@gnu-34 pr39545]$ make f-3.s
/export/build/gnu/gcc-avx/build-x86_64-linux/stage1-gcc/xgcc
-B/export/build/gnu/gcc-avx/build-x86_64-linux/stage1-gcc/ -O2
-fno-asynchronous-unwind-tables -S -o f-3.s f-3.i
[...@gnu-34 pr39545]$ cat f-3.s
        .file   "f-3.i"
        .text
        .p2align 4,,15
.globl bar
        .type   bar, @function
bar:
        subq    $8, %rsp
        movl    $4, %edi
        call    foo
        movl    $4, %eax
        addq    $8, %rsp
        ret
        .size   bar, .-bar
[...@gnu-34 pr39545]$ 

With char contents[0], gcc doesn't touch stack. With char contents[],
we put value on stack even if it is passed in register.


-- 
           Summary: Unnecessary stack usage with flexible array member
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hjl dot tools at gmail dot com
 BugsThisDependsOn: 39545


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

Reply via email to