Bug 75514 - gcc produces incorrect code with -Os
gcc produces incorrect code with -Os
Status: CLOSED WONTFIX
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.3
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-10-09 09:27 EDT by Need Real Name
Modified: 2007-04-18 12:47 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-01 16:21:24 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2002-10-09 09:27:03 EDT
Description of Problem:
Disassembled executable shows register %esi is never initializated, its
value is moved into %ecx which is used in the address for writing to memory
(the original application segv'd, the test code writes ... somewhere).

 8048523:       56                      push   %esi

 804852a:       89 f6                   mov    %esi,%esi

   for (i = 31; i <= 37; i++)
 804856d:       89 f1                   mov    %esi,%ecx
 804856f:       b8 9c 00 00 00          mov    $0x9c,%eax
 8048574:       ba 06 00 00 00          mov    $0x6,%edx
 8048579:       8d 76 00                lea    0x0(%esi),%esi
      setup->xyzzy.bar[i] = 0;
 804857c:       c7 04 08 00 00 00 00    movl   $0x0,(%eax,%ecx,1)
 8048583:       83 c0 04                add    $0x4,%eax
 8048586:       4a                      dec    %edx
 8048587:       79 f3                   jns    804857c <init_setup+0x5c>


Version-Release number of selected component (if applicable):
% gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-112)


How Reproducible:
Every time.

Steps to Reproduce:
See test code and Results.  The 3's in the Actual Results should have
been overwritten.

Actual Results:
% gcc -Wall -g -Os test_bugs.c
% ./a.out
% hexdump setup.bin
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000020 0000 0000 0001 0000 0001 0000 0001 0000
0000030 0001 0000 0001 0000 0001 0000 0001 0000
*
0000090 0001 0000 0001 0000 0001 0000 0303 0303
00000a0 0303 0303 0303 0303 0303 0303 0303 0303
*
00000b0


Expected Results:
% gcc -Wall -g -O test_bugs.c
% ./a.out
% hexdump setup.bin
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000020 0000 0000 0001 0000 0001 0000 0001 0000
0000030 0001 0000 0001 0000 0001 0000 0001 0000
*
0000090 0001 0000 0001 0000 0001 0000 0000 0000
00000a0 0000 0000 0000 0000 0000 0000 0000 0000
*
00000b0

Additional Information:
===test_bugs.c===

typedef struct
{
   struct {
      char	foo[16][2];
      long	bar[38];
   }			xyzzy;
} SETUP;

void other_stuff(void);
extern SETUP	*setup;

void
init_setup(void)
{
   int		i;
   int		x, y;

   for (x = 0; x < 16; x++)
      for (y = 0; y < 2; y++)
	 setup->xyzzy.foo[x][y] = 0;

   other_stuff();

   setup->xyzzy.bar[0] = 0;
   for (i = 1; i <= 30; i++)
      setup->xyzzy.bar[i] = 1;
   for (i = 31; i <= 37; i++)
      setup->xyzzy.bar[i] = 0;

   return;
}

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

int main(int argc, char **argv)
{
   FILE		*f;

   setup = malloc(sizeof(SETUP));
   memset(setup, 3, sizeof(SETUP));
   init_setup();
   f = fopen("setup.bin", "wb");
   fwrite(setup, sizeof(SETUP), 1, f);
   fclose(f);
   exit(0);
}

SETUP *setup;
void other_stuff(void) { }

===test_bugs.c===
Comment 1 Vladimir Makarov 2004-10-01 16:21:24 EDT
gcc-2.96 is too old now.  Its release cycle was finished long ago. 
Therefore we are closing the bug.  If it is still important, the
customer could reopen the case.

Note You need to log in before you can comment on or make changes to this bug.