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]

inline function containing static array omitted from output assembler


/*

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);
}


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