From Bugzilla Helper: User-Agent: Mozilla/5.0 Galeon/1.2.6 (X11; Linux i686; U;) Gecko/20021119 Description of problem: I am using gcc 3.0.4. The attached (tiny) program gives a segmentation fault when you build it with -O0, but it runs fine if you compile it with -O2. This is on i686 Linux. How reproducible: Always Steps to Reproduce: 1. Build the attached program with -O0. 2. Run the program; watch it crash. 3. Build the program with -O2. 4. Run it again; it runs fine and displays "n = 1". Additional info: With -O0, I get this code: inc_ref: pushl %ebp movl %esp, %ebp subl $4, %esp movl 8(%ebp), %eax movl 8(%ebp), %edx #APP movl $1, %eax lock xadd %eax, (%eax) incl %eax #NO_APP movl %eax, -4(%ebp) movl %ebp, %esp popl %ebp ret which of course causes a SIGSEGV, as %eax is 1 and (%eax) is evil. But with -O2, I get this: inc_ref: pushl %ebp movl %esp, %ebp subl $4, %esp movl 8(%ebp), %edx #APP movl $1, %eax lock xadd %eax, (%edx) incl %eax #NO_APP movl %ebp, %esp popl %ebp ret
Created attachment 89381 [details] Test case program.
Can you reproduce it with gcc 3.2.1? gcc 3.0.x is totally unsupported.
Created attachment 89382 [details] Better test case program This version also prints the return value of inc_ref.
Let me get that version of gcc and I'll tell you.
Actually, looking at the testcase, the testcase is buggy. 1) you miss an earlyclobber, so gcc is allowed to use (%eax) for "m" (*ref) 2) you should use "1" not "m" in the second *ref constraint 3) you should actually return some value from the function, setting %eax and relying nobody clobbers it between the __asm and end of function is bogus
That code came from OpenOffice.org (it's from their reference-counting functions), so I assumed it was correct. Sorry to have bothered you with this. I will inform the OO.o team about this bug. Thanks, Jakub!