[gnu.gcc.bug] Structure access bug in GCC 1.36

bruce@heather.pooh.com (Bruce Robertson) (01/17/90)

I've come across a way of accessing a structure that causes incorrect
code to be generated.  The bug only appears when the optimizer is used.

Configuration:  GCC 1.36, tm-sun3.h, and m68k.md.
Command line:   gcc -S -O -g bug.c

First, here's some code that tickles the bug:
----------------------------------------------------------------------
typedef struct
{
	short	fh;
	char	*buf;
	short	count;
}
	read_args;

short
_read(read_args arg)
{
	return read(arg.fh, arg.buf, arg.count);
}
----------------------------------------------------------------------


Next, here's the incorrect assembly code:
----------------------------------------------------------------------
#NO_APP
gcc_compiled.:
	.stabs "glue.c",100,0,0,Ltext
Ltext:
.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
.stabs "char:t2=r2;0;127;",128,0,0,0
.stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
.stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
.stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
.stabs "short int:t6=r1;-32768;32767;",128,0,0,0
.stabs "long long int:t7=r1;0;-1;",128,0,0,0
.stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
.stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
.stabs "signed char:t10=r1;-128;127;",128,0,0,0
.stabs "unsigned char:t11=r1;0;255;",128,0,0,0
.stabs "float:t12=r1;4;0;",128,0,0,0
.stabs "double:t13=r1;8;0;",128,0,0,0
.stabs "long double:t14=r1;8;0;",128,0,0,0
.stabs "void:t15=15",128,0,0,0
.stabs "read_args:t16=s8fh:6,0,16;buf:17=*2,16,32;\\",128,0,0,0
.stabs "count:6,48,16;;",128,0,0,0
.text
	.even
.globl __read
__read:
	.stabd 68,0,11
	link a6,#0
	movel d2,sp@-
	movel a6@(8),d0
	movel a6@(12),d1
	.stabd 68,0,12
	movew d1,a0
	movel a0,sp@-

	movel d0,sp@-		<= this is pushing "arg.fh", and the high
				   order 16 bits of "arg.buf".

	bfexts d0{#0:#16},d2
	movel d2,sp@-
	jbsr _read
	extl d0
	.stabd 68,0,13
	movel a6@(-4),d2
	unlk a6
	rts
.stabs "_read:F6",36,0,0,__read
.stabs "arg:p16",160,0,0,8
.stabs "arg:r16",64,0,0,0


--
	Bruce Robertson
	Hundred Acre Software, Reno, NV
	Domain: bruce@pooh.com
	UUCP:   ...!uunet!tahoe.unr.edu!heather!bruce