[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#484784: gcc-4.3: -O2 -O3 - wrong arguments are passing to inlined body of function



On Fri, Jun 06, 2008 at 02:15:38PM +0200, Wojciech Muła wrote:
> Consider this simple program:

This is not simple. Inline assembler could never be simple.

> 		"	xorl %%ebx, %%ebx	\n"

Don't use explicit register names but placeholder.

> 		"	movzbl (%%eax), %%edx	\n"

eax is unclobbered, therefor the compiler is allowed to assume it
unaccessed.

> 		"	decl %%ecx		\n"

Same for ecx.

> Function inline_asm just add all values from array; all modified/input
> registers are listed in __asm__ statement.

Nope, they are not.

> When program is compiled without any optimization flag, it works ok.
> However if compiled with -O3 or -O3 --- segfaults.  I quickly analyzed
> assembly output, and it is clear, that gcc fully inlined procedure,
> however in a while loop only address is restored (%eax), but inner loop
> counter (%ecx) isn't.  Thus in a second iteration %ecx has value 0, and
> loop would execute 0xffffffff times, but segfault appear faster.

No bug. You cheated so the compiler is free to do whatever it wants.

Bastian

-- 
Beam me up, Scotty!  It ate my phaser!



Reply to: