[gnu.gcc.bug] Gnu C compiler 1.32 -O doesn't mix with shorts

ado@NCIFCRF.GOV (Arthur David Olson) (12/27/88)

(We're running SunOS 4.0 on a Sun 3/110.)

Description:
	Using gcc 1.32's -O option with code containing shorts sometimes fails.

Repeat-By:
	In the code below, compiling without -O (at 1>>>>) yields the
	correct output 10 (at 2>>>>); compiling with -O (at 3>>>>) yields
	the incorrect output 0 (at 4>>>>).  The output of "gcc -S" has been
	appended for documentary purposes.

	Script started on Mon Dec 26 20:43:23 1988
	elsie$ cat try.c
	static void
	doit(p, x1, y1)
	short *	p;
	{
		p[0] = x1;
		p[1] = y1;
	}

	int
	main()
	{
		short	s[2];

		doit(s, 10, 20);
		(void) printf("%d\n", s[0]);
		return 0;
	}
1>>>>	elsie$ /usr/local/bin/gcc -v try.c
	gcc version 1.32
	 /usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 try.c /tmp/cca11913.cpp
	GNU CPP version 1.32
	 /usr/local/lib/gcc-cc1 /tmp/cca11913.cpp -quiet -dumpbase try.c -version -o /tmp/cca11913.s
	GNU C version 1.32 (68k, MIT syntax) compiled by GNU C version 1.32.
	 as -mc68020 /tmp/cca11913.s -o try.o
	 ld -e start -dc -dp /lib/crt0.o /lib/Mcrt1.o try.o /usr/local/lib/gcc-gnulib -lc
	elsie$ a.out
2>>>>	10
3>>>>	elsie$ /usr/local/bin/gcc -v -O try.c
	gcc version 1.32
	 /usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 try.c /tmp/cca11919.cpp
	GNU CPP version 1.32
	 /usr/local/lib/gcc-cc1 /tmp/cca11919.cpp -quiet -dumpbase try.c -O -version -o /tmp/cca11919.s
	GNU C version 1.32 (68k, MIT syntax) compiled by GNU C version 1.32.
	 as -mc68020 /tmp/cca11919.s -o try.o
	 ld -e start -dc -dp /lib/crt0.o /lib/Mcrt1.o try.o /usr/local/lib/gcc-gnulib -lc
	elsie$ a.out
4>>>>	0
	elsie$ /usr/local/bin/gcc -S try.c
	elsie$ cat try.s
	#NO_APP
	gcc_compiled.:
	.text
		.even
	_doit:
		link a6,#0
		movel a6@(8),a0
		movew a6@(14),a0@
		movel a6@(8),a0
		addqw #2,a0
		movew a6@(18),a0@
	L1:
		unlk a6
		rts
	LC0:
		.ascii "%d\12\0"
		.even
	.globl _main
	_main:
		link a6,#-4
		pea 20:w
		pea 10:w
		movel a6,d0
		subql #4,d0
		movel d0,sp@-
		jbsr _doit
		movew a6@(-4),a0
		movel a0,sp@-
		pea LC0
		jbsr _printf
		clrl d0
		jra L2
	L2:
		unlk a6
		rts
	elsie$ /usr/local/bin/gcc -S -O try.c
	elsie$ cat try.s
	#NO_APP
	gcc_compiled.:
	.text
		.even
	_doit:
		link a6,#0
		movel a6@(8),a0
		movew a6@(12),a0@
		movew a6@(18),a0@(2)
		unlk a6
		rts
	LC0:
		.ascii "%d\12\0"
		.even
	.globl _main
	_main:
		link a6,#-4
		pea 20:w
		pea 10:w
		pea a6@(-4)
		jbsr _doit
		movew a6@(-4),a0
		movel a0,sp@-
		pea LC0
		jbsr _printf
		clrl d0
		unlk a6
		rts
	elsie$ exit

	script done on Mon Dec 26 20:44:11 1988
-- 
	Arthur David Olson    ado@ncifcrf.gov    ADO is a trademark of Ampex.