This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
inline function containing static array omitted from output assembler
- From: Mark J Roberts <mjr at znex dot org>
- To: bug-gcc at gnu dot org
- Date: Tue, 2 Jul 2002 08:03:47 -0500
- Subject: inline function containing static array omitted from output assembler
- Key: 0x025D0C28
/*
Compile this source code as follows:
gcc -V 3.1 -Wall -fomit-frame-pointer -O2 -S bug.c
And look at the (lack of) output:
.file "bug.c"
.section .rodata
.align 32
.type table.0,@object
.size table.0,1024
table.0:
.zero 1024
.text
.align 2
.p2align 4,,15
globl bug
.type bug,@function
bug:
subl $44, %esp
.p2align 4,,15
L2:
jmp .L2
Lfe1:
.size bug,.Lfe1-bug
.ident "GCC: (GNU) 3.1"
Fun, huh? GCC works correctly if "table" is not declared static, or
if round() is not inlined. Also I found that it was possible to
provoke GCC into doing the right thing by tweaking code in bug().
Adding asm("# COMMENT") statements and inserting printf calls could
get it working, for example. GCC also works correctly at -O9, if
bug() itself is inlined into main().
I can reproduce this with the various 3.0.[1345] GCCs installed on
my i386 Linux 2.4 box, but not with 2.95.2.
*/
typedef unsigned int u32;
static inline void round(u32 hash[4], const u32 block[4])
{
static const u32 table[256] = {};
hash[0] = (hash[0] ^ hash[3]) + block[0];
hash[0] = hash[0] >> 8 ^ table[hash[0] & 0xff];
hash[1] = (hash[1] ^ hash[0]) + block[1];
hash[1] = hash[1] >> 8 ^ table[hash[1] & 0xff];
hash[2] = (hash[2] ^ hash[1]) + block[2];
hash[2] = hash[2] >> 8 ^ table[hash[2] & 0xff];
hash[3] = (hash[3] ^ hash[2]) + block[3];
hash[3] = hash[3] >> 8 ^ table[hash[3] & 0xff];
}
void bug(void)
{
u32 hash[4], block[4];
for (;;)
round(hash, block);
}