Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 81945 - Producing bad code with -O0 but not with -O2
Summary: Producing bad code with -O0 but not with -O2
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc3
Version: 7.3
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2003-01-15 17:01 UTC by Federico Mena-Quintero
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2003-01-15 17:17:14 UTC

Attachments (Terms of Use)
Test case program. (deleted)
2003-01-15 17:02 UTC, Federico Mena-Quintero
no flags Details
Better test case program (deleted)
2003-01-15 17:06 UTC, Federico Mena-Quintero
no flags Details

Description Federico Mena-Quintero 2003-01-15 17:01:58 UTC
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:

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:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $4, %esp
        movl    8(%ebp), %eax
        movl    8(%ebp), %edx
        movl $1, %eax
xadd %eax, (%eax)
incl %eax
        movl    %eax, -4(%ebp)
        movl    %ebp, %esp
        popl    %ebp
which of course causes a SIGSEGV, as %eax is 1 and (%eax) is evil.

But with -O2, I get this:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $4, %esp
        movl    8(%ebp), %edx
        movl $1, %eax
xadd %eax, (%edx)
incl %eax
        movl    %ebp, %esp
        popl    %ebp

Comment 1 Federico Mena-Quintero 2003-01-15 17:02:49 UTC
Created attachment 89381 [details]
Test case program.

Comment 2 Jakub Jelinek 2003-01-15 17:06:22 UTC
Can you reproduce it with gcc 3.2.1? gcc 3.0.x is totally unsupported.

Comment 3 Federico Mena-Quintero 2003-01-15 17:06:40 UTC
Created attachment 89382 [details]
Better test case program

This version also prints the return value of inc_ref.

Comment 4 Federico Mena-Quintero 2003-01-15 17:07:23 UTC
Let me get that version of gcc and I'll tell you.

Comment 5 Jakub Jelinek 2003-01-15 17:17:14 UTC
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

Comment 6 Federico Mena-Quintero 2003-01-15 19:33:02 UTC
That code came from (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!

Note You need to log in before you can comment on or make changes to this bug.