🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #5964

Bug in V2.7.2.1 Compiler with -O2 for x86

#5964
From: horst
Date: Wed, 15 Jan 1997 00:00
177 lines
5419 bytes
This is a multi-part message in MIME format.

--------------582546C4F0E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi there,

the attached example will generate errnoneous code within the loop.
At the beginning of the loop, the variable "parameter" is loaded into
register EDX which is clobbered during the call of function "sprintf".
Only with -O2 the code generator seems to forget that EDX had 
been clobbered, whereas with -O the EDX value is pushed on the stack
and popped back after the function call.

What be nice to have a fix.

Thanks in advance

Horst

Compiler Version	2.7.2.1
generated for x86 with ELF-Format

int serprintf(const char *format, ...);
#define lengthof(x) (sizeof(x)/sizeof(x[0]))

typedef  unsigned char   U8;
typedef  signed   char   I8;
typedef  unsigned short  U16;
typedef  signed   short  I16;
typedef  unsigned int    U32;
typedef  signed   int    I32;
typedef  float           R32;

typedef struct 
{
    U16   tab_kennung    __attribute__((packed));
    U16   tab_index      __attribute__((packed));
    U16   struc_kennung  __attribute__((packed));
    U16   struc_index    __attribute__((packed));
    union 
        { 
          U8  b              __attribute__((packed));
          U16 w              __attribute__((packed));
          U32 d              __attribute__((packed));
          R32 r              __attribute__((packed));
    } wert;
} S_EINZEL_PAR, *P_EINZEL_PAR;

typedef struct 
{
        S_EINZEL_PAR start;
        S_EINZEL_PAR stop;
        char         s[16];
} S_EINZEL_PAR_STR16, *P_EINZEL_PAR_STR16;

typedef struct
{
        S_EINZEL_PAR darstellung;
        S_EINZEL_PAR aktiv      ;
        S_EINZEL_PAR soll       ;
        S_EINZEL_PAR tol        ;
        S_EINZEL_PAR_STR16 bez  ;
} S_PARAMETER, *P_PARAMETER;
static S_PARAMETER parameter[20];

void test_ep(void)
{
        /*
------------------------------------------------------------------*/
        /* Parameter
schreiben                                               */ 
        /*
------------------------------------------------------------------*/
/*
  !!! Hier wird %edx als konstant angenommen, aber vermutlich durch
Call's
  !!! veraendert 
*/
        int i;
        for (i=0; i<(lengthof(parameter)); i++)
        {
                char s[16];
                parameter[i].darstellung.wert.d = i & 7;
                parameter[i].aktiv.wert.d       = 1;
                parameter[i].soll.wert.r        = 1.1*i;
                parameter[i].tol.wert.r         = 0.1*i;
                sprintf(s,"AQC-Param. %d",i);
                strcpy(parameter[i].bez.s,s);
        }
}


        .file   "t.cc"
        .version        "01.01"
gcc2_compiled.:
.section        .rodata
.LC0:
.byte 0x41,0x51,0x43,0x2d,0x50,0x61,0x72,0x61,0x6d,0x2e
.byte 0x20,0x25,0x64,0x0
        .align 4
.LC1:
        .long 0x9999999a,0x3ff19999
        .align 4
.LC2:
        .long 0x9999999a,0x3fb99999
.text
        .align 4
.globl test_ep
        .type    test_ep,@function
test_ep:
        pushl %ebp
        movl %esp,%ebp
        subl $28,%esp
        pushl %edi
        pushl %esi
        pushl %ebx
        xorl %esi,%esi
        movl $parameter,%edx            # parameter to EDX
        leal -16(%ebp),%ecx
        movl %ecx,-24(%ebp)
        movl $parameter+72,%edi
        xorl %ebx,%ebx
        .align 4
.L5:
        movl %esi,%ecx
        andl $7,%ecx
        movl %ecx,8(%edx,%ebx)
        movl $1,20(%edx,%ebx)
        fldl .LC1
        pushl %esi
        fimull (%esp)
        addl $4,%esp
        fstps 32(%edx,%ebx)
        fldl .LC2
        pushl %esi
        fimull (%esp)
        addl $4,%esp
        fstps 44(%edx,%ebx)
        pushl %esi
        pushl $.LC0
        pushl -24(%ebp)
        call sprintf            # call sprintf without saving EDX
        pushl -24(%ebp)
        pushl %edi
        call strcpy
        addl $20,%esp
        addl $88,%edi
        addl $88,%ebx
        incl %esi
        cmpl $19,%esi
        jbe .L5
        leal -40(%ebp),%esp
        popl %ebx
        popl %esi
        popl %edi
        leave
        ret
.Lfe1:
        .size    test_ep,.Lfe1-test_ep
        .local  parameter
        .comm   parameter,1760,1
        .ident  "GCC: (GNU) 2.7.2.1"

--------------582546C4F0E
Content-Type: text/plain; charset=us-ascii; name="footnote"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="footnote"

HighTec EDV-Systeme GmbH, Feldmannstr. 98, 66119 Saarbruecken, Germany
Tel:	0049/681-9261314
Fax:	0049/681-9261326
E-mail:	hl@hightec.saarlink.de

--------------582546C4F0E--
Technical Details
Message-ID: <32DCC7B3.59E2@hightec.saarlink.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,7ed0fdc95c29a45e,start
X-Google-Attributes: gid113d02,public
From: hl@hightec.saarlink.de (horst)
Subject: Bug in V2.7.2.1 Compiler with -O2 for x86
Date: 1997/01/15
Message-ID: <32DCC7B3.59E2@hightec.saarlink.de>
X-Deja-AN: 209977078
sender: bug-gcc-request@prep.ai.mit.edu
content-type: multipart/mixed; boundary="------------582546C4F0E"
organization: HighTec EDV Systeme GmbH
x-gateway: relay3.UU.NET from bug-gcc to gnu.gcc.bug; Wed, 15 Jan 1997 07:03:20 EST
mime-version: 1.0
reply-to: hl@hightec.saarlink.de
newsgroups: gnu.gcc.bug
x-mailer: Mozilla 3.01 (WinNT; I)