Floating point parameter passing error

Question asked by Giovanni Climaco on Sep 20, 2013
Latest reply on Mar 11, 2014 by Pascal Irrle
Hi to everyone,
I'm having a strange problem with floating point parameter passing, if I write a function that use floating point parameters they are not handled correctly
This function perform the subtraction of a 3 dimensional float vector
T_3DCoordFloat Vectors_Diff(T_3DCoordFloat A, T_3DCoordFloat B)
{
X -= B.X;
Y -= B.Y;
Z -= B.Z;
return A;
}
is compiled in:
Vectors_Diff:
20       {
00002d90:   push {r0-r3}
00002d92:   vpush {s0-s2}
00002d96:   push {r4}
00002d98:   cpy r4,r0
21        A.X -= B.X;
00002d9a:   vldr.32 s1,[sp,#-8]
00002d9e:   vldr.32 s0,[sp,#-8]
00002da2:   vsub.f32 s0,s1,s0
00002da6:   vstr.32 s0,[sp,#-8]
22        A.Y -= B.Y;
00002daa:   vldr.32 s1,[sp,#-4]
00002dae:   vldr.32 s0,[sp,#-4]
00002db2:   vsub.f32 s0,s1,s0
00002db6:   vstr.32 s0,[sp,#-4]
23        A.Z -= B.Z;
00002dba:   vldr.32 s1,[sp]
00002dbe:   vldr.32 s0,[sp]
00002dc2:   vsub.f32 s0,s1,s0
00002dc6:   vstr.32 s0,[sp]
24        return A;
00002dca:   movw r2,#0xfff8
00002dce:   movt r2,#0xffff
00002dd4:   ldm r2!,{r0-r1}
00002dd6:   stm r4!,{r0-r1}
00002dd8:   ldr r0,[r2,#0]
00002dda:   str r0,[r4,#0]
25       }
but in debug window both A and B parameters have the same address and the instruction that load parameters from the stack load twice the same location
vldr.32 s1,[sp,#-8]
vldr.32 s0,[sp,#-8]
and then compute the difference that is Always zero.
To get it working I've to use a pointer to struct A and B and not passing them directly.
If I use only one float parameter it seems it works
I'm using
codewarrior 10.4
K60 CPU
K60F120M CPU board
MQX 4.0
Processor Expert
Floating point Hardware vfpv4

Regards

Giovanni