linux-mips
[Top] [All Lists]

Re: -O2 in gcc 2.96 buggy?

To: Torsten Weber <t.weber@hhi.de>
Subject: Re: -O2 in gcc 2.96 buggy?
From: Justin Carlson <justincarlson@cmu.edu>
Date: 17 Jan 2002 12:01:29 -0500
Cc: Linux MIPS <linux-mips@oss.sgi.com>
In-reply-to: <3C46C2D5.F191DC26@hhi.de>
References: <3C46C2D5.F191DC26@hhi.de>
Sender: owner-linux-mips@oss.sgi.com
On Thu, 2002-01-17 at 07:25, Torsten Weber wrote:
> On a RedHat 7.1 installation I compiled gawk (3.1.0),  but gawk crashed
> (gawk couldn't run glibc-2.2.4/scripts/firstversions.awk, it resulted
> in:
>        > (FILENAME=- FNR=1) fatal error: internal error
>        > Aborted (core dumped)
> )
> The gawk problem disappeares if I compile without optimizing with -O2
> (i.e. optimizing with -O works).
> 
> gcc version is 2.96 20000731 (Red Hat Linux 7.1 2.96-99.1)
> 
> Is this problem already known, or where is my mistake?
> 

Often compiling with -O2 reveals actual bugs in the code of the program,
not the compiler.  For example, uninitialized variables can come out
differently depending on optimization level:

#include <stdlib.h>
#include <stdio.h>

int main()
{
        int foo;
        printf("Foo is %i\n", foo);
        return 0;
}

[justinca@gs256 ~]$ gcc -O0 foo.c -o foo
[justinca@gs256 ~]$ ./foo
Foo is -1073743180
[justinca@gs256 ~]$ gcc -O2 foo.c -o foo
[justinca@gs256 ~]$ ./foo
Foo is 1075157696


-Justin

Attachment: pgpk7sMCn7Blw.pgp
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>