This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/1910: incorrect long long return value with -O2 optimization
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c/1910: incorrect long long return value with -O2 optimization
- From: djk at super dot org
- Date: 8 Feb 2001 13:14:45 -0000
- Reply-To: djk at super dot org
>Number: 1910
>Category: c
>Synopsis: incorrect long long return value with -O2 optimization
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu Feb 08 05:16:02 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: daniel kopetzky
>Release: GCC: (GNU) 2.97 20010207 (experimental)
>Organization:
>Environment:
intel
>Description:
-O2 generates incorrect code and causes the following
example routine to return a long long value from an
uninitialized stack location.
struct cl {
int one, two;
};
const char *error = "edx should get 0, eax should get ebp[4]";
long long broken (int a){
struct cl val;
val.one = a;
val.two = 0;
return *(long long *)&val;
}
--------------
the codesourcery compile server gave this answer today:
.file "@5412.7.c"
.version "01.01"
gcc2_compiled.:
.globl error
.section .rodata
.align 32
.LC0:
.string "edx should get 0, eax should get ebp[4]"
.data
.align 4
.type error,@object
.size error,4
error:
.long .LC0
.text
.align 4
.globl broken
.type broken,@function
broken:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl -8(%ebp), %eax
movl -4(%ebp), %edx
leave
ret
.Lfe1:
.size broken,.Lfe1-broken
.ident "GCC: (GNU) 2.97 20010207 (experimental)"
------------------------
Looks like the optimizer removed the two assignments to
the structure (one is a parameter, the other is a zero).
>How-To-Repeat:
gcc -O2 -S bug.c
inspect eax & edx values returned from function.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: