Mail Archives: djgpp/1997/03/03/16:34:25
From: | s5muma AT rz DOT uni-jena DOT de (Marc Mueller)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | GCC optimization option "-O3" buggy ?
|
Date: | 3 Mar 1997 20:03:56 GMT
|
Organization: | Friedrich-Schiller-University Jena, Germany
|
Lines: | 124
|
Message-ID: | <5ffarc$l0t@fsuj19.rz.uni-jena.de>
|
NNTP-Posting-Host: | fsuj80.rz.uni-jena.de
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hi,
I wrote a small program to test o2c, a converter for TASM-like .OBJ files.
Compiling the C-source with optimization flag "-O3" causes general
protection faults in runtime, otherwise all runs quite right.
First the source :
--------------------------------------ASMTEST.ASM
(written for TASM, convert .OBJ file using o2c)
.386
.MODEL USE32 FLAT, C
.CODE
PUBLIC _asmtst
_asmtst PROC // should fill a array of int's
ARG intarray : PTR DWORD, arraysize : DWORD
cld
push ds
pop es
mov edi, [intarray]
mov ecx, [arraysize]
xor eax,eax
@@LP: stosd
inc eax
loop @@LP
ret
_asmtst ENDP
END
----------------------------------------End of ASMTEST.ASM
----------------------------------------ASMTEST.C
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
extern void _asmtst( int *intarray, int arraysize );
int main( void )
{
int *p1, *p0, h, arsize = 15000000;
// ----- Allocate array
if ( !( p1 = p0 = malloc( arsize * sizeof(int) ) ) )
{ exit( -1 ); }
// ----- Fill array asm
printf( "fill array asm\n" );
_asmtst( p0, arsize );
// ----- Fill array C
printf( "fill array C\n" );
for ( h=0; ( h<arsize ); )
*(p1++) = h++;
// ----- display array
printf( "output\n" );
p1 = p0;
for ( h=0; ( h<arsize ); h++)
{
if ( !( h % (arsize / 100) ) ) // show only 100 int's
printf( "%x\n", *p1 );
p1++;
}
}
----------------------------------------End of ASMTEST.C
As described above, compiling it with "-O3" causes "general protection
faults" ("SIGSEGV") in runtime (before printf( "output\n" ); ). Without
the option "-O3" all runs perfectly.
If I delete output of the array, it runs even with "-O3" well.
So the following source works (optimization enabled) :
---------------------------------------ASMTEST2.C
[...]
// ----- Fill array C
printf( "fill array c\n" );
for ( h=0; ( h<arsize ); )
*(p1++) = h++;
// ----- display array
printf( "output\n" );
}
--------------------------------------End of ASMTEST2.C
And the following doesn't work (optimization enabled):
--------------------------------------ASMTEST3.C
[...]
// ----- Fill array C
printf( "fill array c\n" );
for ( h=0; ( h<arsize ); )
*(p1++) = h++;
// ----- display array
printf( "output\n" );
p1 = p0;
}
------------------------------------End of ASMTEST3.C
So, only a simple "p1 = p0;" more let's occure an protection fault DURING
filling the array.
Is it a bug or my fault ? (I'm using GCC 2.7.2., I used only the options
"-Wall -O3")
TIA,
Marc
- Raw text -