[11231] in Athena Bugs
decmips 7.6G: cygnus gcc
daemon@ATHENA.MIT.EDU (Marc Horowitz)
Wed Oct 20 00:56:59 1993
To: bugs@MIT.EDU
Cc: reidmp@MIT.EDU, eichin@MIT.EDU
Date: Wed, 20 Oct 93 00:56:36 EDT
From: Marc Horowitz <marc@MIT.EDU>
System name: hodge
Type and version: KN01 7.6G (1 update(s) to same version)
Display type: PMAX-MFB
What were you trying to do?
Not lose
What's wrong:
The following C program demonstrates a bug in the gcc optimizer:
#include <stdio.h>
#include <memory.h>
/*
I think this is a compiler bug, but I'm not sure.
If you compile this program -g -O on a dec, you get a few unaligned
accesses. On a sun, this gives you a bus error.
The problem appears to be that the compiler things that copying four
bytes from a long * to a long *, even when casted to a char *, is the
same as assigning a long to another long. This program demonstrates
that this is an invalid assumption.
Compiling -g, or -g -O -DWIN, results in a functional executeable.
It is worth noting that this bug was discovered while working with
the des implementation in krb5, particularly src/lib/des/enc_dec.c.
*/
#ifdef WIN
#define dmemcpy xmemcpy
#else
#define dmemcpy memcpy
#endif
char *xmemcpy(char *s1,char *s2,int n) { return(memcpy(s1,s2,n)); }
int main()
{
char *buf;
unsigned long *foo;
unsigned long l[2];
buf = (char *) malloc(100);
buf++;
foo = (unsigned long *) buf;
if ((long) foo & 3) {
printf("unaligned: %x\n", foo);
dmemcpy((char *)&l[0],(char *)foo++,sizeof(l[0]));
dmemcpy((char *)&l[1],(char *)foo++,sizeof(l[1]));
} else {
printf(" aligned: %x\n", foo);
l[0] = *foo++;
l[1] = *foo++;
}
return(0);
}
What should have happened:
See above.
Please describe any relevant documentation references: