Article View: gnu.gcc.bug
Article #361GCC 2.1 Optimizer Bug
From: Brian Donnell [PT4]
Date: Fri, 10 Apr 1992 19:20
Date: Fri, 10 Apr 1992 19:20
64 lines
1796 bytes
1796 bytes
The program below when compiled with the command:
gcc -o foo -O foo.c
generates the following output on a Sun/Sparc with SunOS 4.1.1
(I am using GCC 2.1)
8941 837 1013
1903521977 768 1013
1903521766 557 1013
1886547925 544 1013
When compiled without the -O option, it generates the correct output:
1903521977 768 1013
1903521977 768 1013
1903521766 557 1013
1886547925 544 1013
Brian Donnell
NASA/JSC
File foo.c contents:
#include <stdio.h>
void main(void);
static int HashSymbol(char *,int);
void main()
{
HashSymbol("quoxnar",1013);
HashSymbol("quoxnar",1013);
HashSymbol("progn",1013);
HashSymbol("progn",1013);
}
static int HashSymbol(word,range)
char *word;
int range;
{
register int k,j,i;
register int length;
int tally;
unsigned long count = 0L,tmpLong;
char *tmpPtr;
tmpPtr = (char *) &tmpLong;
for (length = 0; word[length]; length++);
length = length / sizeof(unsigned long);
for (i = 0 , j = 0 ; i < length; i++)
{
for (k = 0 ; k < sizeof(unsigned long) ; k++ , j++)
tmpPtr[k] = word[j];
count += tmpLong;
}
for (word = (char *) &word[j]; *word; word++) count += (unsigned long) *word;
tally = (int) (count % range);
printf("%lu %d %d\n",count,tally,range);
if (tally < 0) return(-tally);
return(tally);
}
Technical Details
Message-ID:
<9204101920.AA28537@gothamcity.jsc.nasa.gov>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!gothamcity.jsc.nasa.gov!brianShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!gothamcity.jsc.nasa.gov!brian From: brian@gothamcity.jsc.nasa.gov (Brian Donnell [PT4]) Subject: GCC 2.1 Optimizer Bug Message-ID: <9204101920.AA28537@gothamcity.jsc.nasa.gov> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 10 Apr 1992 19:20:02 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 65