ARM: testsuite gcc.c-torture/execute/20020307-2.c failure

jeroen dobbelaere jeroen.dobbelaere@acunia.com
Tue Nov 12 08:46:00 GMT 2002


Richard Earnshaw wrote:
>>Looking at testcase
>>	gcc.c-torture/execute/20020307-2.c
>>
[...]
> 
> 
> When a struct is of potentially variable size (from the viewpoint of the 
> callee), then the argument has to be passed by reference (we can't put it 
> into the registers since it would mess up dereferencing everything else).  

Why is this such a problem ?

Looking at the current code (gcc-3.2) produced for the callee (with va_arg), the callee just
starts dumping r0-r3 to the stack, so that from that point,
he (it?) can access the arguments as if passed on the stack...
I guess something similar can be done (without variable arguments) when
a variable-sized array is passed...

But in that case, the caller still has to use the normal argument passing semantics
(and fill in r0-r3).


void foo (int size, ...)
{
   va_list ap;
   struct
   {
     char x[size];
   } d;
   int i;

   va_start (ap, size);
   ap=(typeof(ap)) ((unsigned long)ap );
   d = va_arg (ap, typeof (d));
   for (i = 0; i < size; i++)
     bar (d.x[i]);
   d = va_arg (ap, typeof (d));
   for (i = 0; i < size; i++)
     bar (d.x[i]);
   va_end (ap);
}


	.global	foo
	.type	foo,function
foo:
	@ args = 4, pretend = 16, frame = 0
	@ frame_needed = 1, uses_anonymous_args = 1
	mov	ip, sp
	stmfd	sp!, {r0, r1, r2, r3}
	stmfd	sp!, {r4, r5, r6, r7, r8, sl, fp, ip, lr, pc}
	sub	fp, ip, #20
	ldr	r6, [fp, #4]
	add	ip, fp, #8
	mov	sl, sp
	ands	r3, r6, #3
	movne	r3, #1
	add	r1, r3, r6, lsr #2
	sub	sp, sp, r1, asl #2
	add	r2, r3, r6, lsr #2
	mov	r2, r2, asl #2
	add	r3, r3, r6, lsr #2
	mov	r1, ip
	mov	r0, sp
	mov	r4, #0
	add	r8, ip, r3, asl #2
	bl	memcpy
	cmp	r4, r6
	sub	r7, r6, #1
	mov	r5, sp
[...]

> Whether the reference is to the original (forcing callee copy semantics) 
> or to a copy (caller-copy semantics) is something we have to decide on -- 
> I'm inclined to require caller-copy
> 
> The whole testcase is very much dependent on the GNU variable-sized array 
> extension (you just can't do this in ISO C -- even in C99) so I haven't 
> worried about it too much until now.
> 
> R.
> 

Yep. I'm just going over the different testsuite failures for ARM,
trying to tackle them down, one by one ;)

Greetings,
-- 
Jeroen Dobbelaere
Embedded Software Engineer

ACUNIA Embedded Solutions
http://www.acunia.com/aes




More information about the Gcc mailing list