🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2455

GCC 1.34 optimizer bug

#2455
From: Mats Carlsson
Date: Thu, 23 Mar 1989 10:37
46 lines
1583 bytes
Enclosed is a typescript of a program giving incorrect results when
compiled with -O.  The problem has to do with Boolean operations and
seems to be machine-independent; it manifests itself on Sun-3 (SunOS
4.0), Sun-4 (SunOS 4.0), Sequent Symmetry (DYNIX(R) V3.0.12 NFS).


skarabe>gcc -version
gcc version 1.34
skarabe>gcc -o bug bug.c
skarabe>bug
expected = 0x12, result = 0x12
expected = 0x7, result = 0x7
skarabe>gcc -O -o bug bug.c
expected = 0x12, result = 0x2
expected = 0x7, result = 0x17
skarabe>cat bug.c

#include <stdio.h>

/* AND all bits but 0x10, which is OR:ed */
orand(x,y)
     unsigned long x,y;
{
  return ((x^0x10)&(y^0x10))^0x10;
}

/* OR all bits but 0x10, which is AND:ed */
andor(x,y)
     unsigned long x,y;
{
  return ((x^0x10)|(y^0x10))^0x10;
}

main()
{
  unsigned long x = 0x13;
  unsigned long y = 0x06;

  printf("expected = 0x%x, result = 0x%x\n", 0x12, orand(x,y));
  printf("expected = 0x%x, result = 0x%x\n", 0x07, andor(x,y));
}
--
Mats Carlsson
SICS, PO Box 1263, S-164 28  KISTA, Sweden
Internet: matsc@sics.se      			EAN: matsc@sics.sunet
Phone: +46 8 7521543				Fax: +46 8 7517230
Technical Details
Message-ID: <MATSC.89Mar23113702@skarabe.sics.se>
Path: arc1-ca.pugleaf.net!utzoo!telly!lethe!dptcdc!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!mcvax!kth!osiris!sics.se!matsc

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!lethe!dptcdc!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!mcvax!kth!osiris!sics.se!matsc
From: matsc@sics.se (Mats Carlsson)
Newsgroups: gnu.gcc.bug
Subject: GCC 1.34 optimizer bug
Message-ID: <MATSC.89Mar23113702@skarabe.sics.se>
Date: 23 Mar 89 10:37:02 GMT
Sender: news@osiris.sics.se
Distribution: gnu
Organization: Swedish Institute of Computer Science, Kista
Lines: 46