This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bug: variable memory allocation in gcc3


Hey everyone!

On one of the boards I frequently visit, someone asked a rather simple question about assembly.
I was very surprised with his gcc output though. Below is a full description of how to
reproduce what looks like a bug.


[ Thread where the question is asked: http://www.deny.de/phpbb2/viewtopic.php?t=9478 ]

How to reproduce it:

Take this very small C code:

void function(int a) { char buffer[1]; }
main() { function(1); }

If you compile it with gcc -S, you'll see subl $4, %esp under .function.
Change buffer[1] to buffer[3], $4 becomes $24.
But make that buffer[8], and $4 becomes $8.
Now... why would gcc allocate three times more variable space on the stack for buffer[3] than for buffer[8]?


This problem seems to be gcc3 specific, gcc 2.95 substracts the %esp with $32 for all three cases. I compiled this with 3.2.1 20020924 Debian prerelease.

Optimizing doesn't help either. If I change the code to:

void function(int a) { char buffer[1]="f"; printf("%s",buffer); }
main() { function(1); }

I get $16, $32 and $16 for buffer[i] with i = 1, 3 and 8 respectively.

Since I don't see why a buf[3] should get (two or even three times) more memory assigned than buf[8],
I assume this is a bug.


Thanks in advance for looking at this issue,
Flaym


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]