User account creation filtered due to spam.

Bug 39552 - Unnecessary stack usage with flexible array member
Summary: Unnecessary stack usage with flexible array member
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 39545
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-25 00:54 UTC by H.J. Lu
Modified: 2009-03-25 00:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2009-03-25 00:54:39 UTC
After fixing PR 39545, I got

[hjl@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;
}
[hjl@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
[hjl@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
[hjl@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;
}
[hjl@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
[hjl@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
[hjl@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.