🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6081

Bug in V2.7.2.1 Compiler with -O2

#6081
From: Frank Feller
Date: Tue, 17 Dec 1996 00:00
170 lines
4682 bytes
This is a multi-part message in MIME format.

--------------65010F8D336E01C6693862D7
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

Frank

--------------65010F8D336E01C6693862D7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="t.cc"


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);
	}
}

--------------65010F8D336E01C6693862D7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="t.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"

--------------65010F8D336E01C6693862D7--
Technical Details
Message-ID: <32B69646.2BF54BE0@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,a0e5a1f2c9021d7b,start
X-Google-Attributes: gid113d02,public
From: c166@hightec.saarlink.de (Frank Feller)
Subject: Bug in V2.7.2.1 Compiler with -O2
Date: 1996/12/17
Message-ID: <32B69646.2BF54BE0@hightec.saarlink.de>
X-Deja-AN: 204687625
sender: c166@hightec.saarlink.de
content-type: multipart/mixed; boundary="------------65010F8D336E01C6693862D7"
organization: HighTec EDV-Systeme
x-gateway: relay4.UU.NET from bug-gcc to gnu.gcc.bug; Tue, 17 Dec 1996 07:51:49 EST
mime-version: 1.0
newsgroups: gnu.gcc.bug
x-mailer: Mozilla 2.0 (X11; I; Linux 1.2.13 i586)