Structure Alignment Bug in Sparc.

Nitin Gupta ngupta@GlobespanVirata.com
Tue Aug 19 17:02:00 GMT 2003


> 	A structure assignment statement of a struct
> > 	containing a 8 byte member causes a ldd assembly
> > 	instruction to be generated.
> 
> Ok...  Why do you think this is a bug?

What causes compiler to assume that if a structure contains
"long long" (64 bit) member any where (and not as the first member)
then the start of the sturct will also be aligned a 8 byte boundary.

Err.. I think the assumption is that malloc will allign all allocation
>= 8 bytes to 8 byte boundary. Then what prevents compiler to
generate a ldd for the copy of a struct member at the start of a 
large struct (>=8byte) that does not contain a 8 byte member?
i.e. In the test programm if st1 contains 2 longs instead of a long long
compiler would generate ld instead.


Thanks and Regards,
Nitin
PS: The Test program of previous mail.
	struct _st2 {
		int * a;
		int c;
		int * b;
		int d;
	};
	typedef struct _st2 _st2;

	typedef _st2 st2;

	typedef struct st1{
		st2 a;
		int l;
		long long b;
	}st1;

	extern void print(st2 v);
	void func_test(st1 * var)
	{
		st2 v = var->a;
		print(v);
	}
Assembly
_func_test:
	!#PROLOGUE# 0
	save	%sp, -136, %sp
	!#PROLOGUE# 1
	ldd	[%i0+8], %o4	<--- This should have
	ldd	[%i0], %o2		<--- been 4 ld 
	add	%fp, -40, %o0
	std	%o4, [%fp-32]
	std	%o2, [%fp-40]
	std	%o2, [%fp-24]
	call	_print, 0
	...
	...


> r~
> 



More information about the Gcc mailing list