[gnu.gcc.bug] gcc-1.37 bug printing structure members on DECstation 3100

edelsohn@groucho.tapir.Caltech.EDU (David Edelsohn) (02/22/90)

	Now that gcc-1.37 no longer assumes that the host's native compiler
produces correct results for casts from unsigned long to double, ntp-3.4
(Network Time Protocol from the Universiy of Maryland) passes its self tests.
However, the appended program demonstrates a problem experienced when using
ntpdc:  printf() output is incorrect for elements of structures and for
functions acting on elements of structures.  The results are always incorrect
and are dependent on whether the output is sent to a terminal or to a file or
pipe but are independent of shell used.  Mips cc1.31 always produces the
correct output.  The results do not depend on whether optimization is enabled.

Machine: DECstation 3100
Operating System: Ultrix 3.1/UWS 2.2
Configuration: config.gcc decstation
Version: gcc-1.37

Appended is the output of a verbose gcc compilation, the output of the
program to the terminal, the output of the program when redirected to a file,
the verbose compilation by Mips cc1.31, the output of the Mips cc-compiled
program, and finally the program listing.
					David
===============================================================================
David Edelsohn                                    CCSF/Theoretical Astrophysics
INTERNET:  edelsohn@tapir.Caltech.EDU             130-33 Caltech
                                                  Pasadena, CA  91125
"It's only a dream away ..." -- from Time Bandits ending credits song
"... Nature cannot be fooled." -- Richard Feynman

-----appended text-----
% gcc -v gccbug.c
gcc version 1.37
 /usr/gnu/lib/gcc-cpp -v -undef -D__GNUC__ -Dultrix -Dbsd4_2 -DMIPSEL -Dhost_mips -Dmips -Dunix -DR3000 -DLANGUAGE_C -DSYSTYPE_BSD -D__ultrix__ -D__bsd4_2__ -D__MIPSEL__ -D__host_mips__ -D__mips__ -D__unix__ -D__R3000__ -D__LANGUAGE_C__ -D__SYSTYPE_BSD__ gccbug.c /usr/tmp/cca20436.cpp
GNU CPP version 1.37
 /usr/gnu/lib/gcc-cc1 /usr/tmp/cca20436.cpp -quiet -dumpbase gccbug.c -version -o /usr/tmp/cca20436.s
GNU C version 1.37 compiled by GNU C version 1.37.
default target switches: -munix -mnofixed-ovfl -mG0 -mG1
 (AL-MIPS 1.11) <Decstation>
 as -nocpp -G 8 -o gccbug.o /usr/tmp/cca20436.s
 ld -G 8 /lib/crt0.o gccbug.o /usr/gnu/lib/gcc-gnulib -lc /usr/gnu/lib/gcc-gnulib
% a.out
7.97.215.131
0x83d76107      0x761d783       0x0
25.0.0.0
131.215.97.7
% a.out > bug.file
% cat bug.file
7.97.215.131    
0x83d76107	0x761d783	0x0
15.0.0.0        
131.215.97.7
% cc -v gccbug.c
/usr/lib/cpp1.31 -v gccbug.c -DLANGUAGE_C -DMIPSEL -I/usr/include1.31 > /tmp/ctmpa20496 
0.1u 0.1s 0:00 79% 24+87k 0+2io 0pf+0w
/usr/lib/ccom1.31 -Xv -EL -Xg0 -O1 -XS/tmp/ctmsta20496 < /tmp/ctmpa20496 > /tmp/ctmfa20496 
ccom:main 0.1u 0.1s 0:00 60% 78+221k 0+4io 3pf+0w
/usr/lib/ugen1.31 -v -G 8 -EL -g0 -O1 /tmp/ctmfa20496 -o /tmp/ctmca20496 -t /tmp/ctmsta20496 -temp /tmp/ctmgta20496 
0.0u 0.0s 0:00 32% 78+59k 0+4io 3pf+0w
/usr/lib/as11.31 -v -G 8 -p0 -EL -g0 -O1 /tmp/ctmca20496 -o gccbug.o -t /tmp/ctmsta20496 
as1: main 
0.0u 0.0s 0:00 20% 79+77k 0+2io 3pf+0w
/usr/bin/ld1.31 -B1.31 -G 8 -g0 -nocount /usr/lib/crt0.o1.31 -count gccbug.o -nocount -lc 
0.0u 0.2s 0:00 48% 66+179k 1+15io 4pf+0w
% a.out
131.215.97.7    
0x83d76107	0x761d783	0x761d783
131.215.97.7    
131.215.97.7

/* program which produces incorrect printf() output when compiled using
 * gcc-1.37 on a DECstations 3100 */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>

struct sockaddr_in sin = {AF_INET};
void exit(int);

	void
main()
{
	unsigned long naddr, addr = 0x83d76107;
	sin.sin_addr.s_addr = htonl(addr);
	naddr = htonl(addr);
	printf("%-16.16s\n",
		inet_ntoa(sin.sin_addr));
	printf("0x%x\t0x%x\t0x%x\n",
		addr, naddr, sin.sin_addr);
	printf("%-16.16s\n",
		inet_ntoa(sin.sin_addr));
	printf("%-16.16s\n",
		inet_ntoa(naddr));

	exit(0);
}