Author Topic: Simple argument bug  (Read 649 times)

Tom

• Member
• Posts: 2
Simple argument bug
« on: May 15, 2020, 06:11:51 pm »
This is so elementary, that I'm sure someone must have reported it at some point...
However, could not find a matching report at a quick glance, so might as well push it here, even if it ends up being a duplicate and wasting everyones time.

Here is a tiny program that demonstrates the issue:

Code: [Select]
` #include <stdio.h> struct Two_Floats { float hi; float lo; }; struct Two_Floats broken_Function( struct  Two_Floats clips ,  struct Two_Floats values ) { if( values.hi <= clips.hi ) values.hi = clips.hi; if( values.lo >= clips.lo ) values.lo = clips.lo; return values; } struct Two_Floats working_Function( struct  Two_Floats clips ,  struct Two_Floats values ) { struct Two_Floats temporary = values; if( temporary.hi <= clips.hi ) temporary.hi = clips.hi; if( temporary.lo >= clips.lo ) temporary.lo = clips.lo; return temporary; } int main( void ) { struct Two_Floats  values = { -50.0f , 25.0f  }; struct Two_Floats  limits = {   0.0f , 600.0f }; struct Two_Floats  broken =  broken_Function( limits , values ); struct Two_Floats working = working_Function( limits , values ); printf("And here we go: < %f , %f > \n", broken.hi  , broken.lo  ); printf("This was to be: < %f , %f > \n", working.hi , working.lo ); return 0; }`
Output:
Code: [Select]
`And here we go: < -50.000000 , 25.000000 >This was to be: < 0.000000 , 25.000000 >Press any key to continue...`
Modifying the the pass-by-value argument and returning it gives a wrong result.
Taking a temporary copy and returning it, won't.

Using version 9.009 at windows 10.
Same behavior occurs on both default debug and release configuration, with fast and strict floating point settings.

Peculiar.

frankie

• Global Moderator
• Member
• Posts: 1789
Re: Simple argument bug
« Reply #1 on: May 16, 2020, 03:54:23 pm »
Bug verified.
The problem doesn't seem related to arguments pass, but to code generation bug. This suspect is enforced due to the problem persistence even when compiling with different optimizations, include no optimization at all.
As showed in the image attached the whole swapping code for the first element is not emitted.
Indeed the reverse works. I.e. reversing the structure element to swap as in:
Code: [Select]
`int main(void){ struct Two_Floats values = { -50.0f, 25.0f };// struct Two_Floats values = { 50.0f, 625.0f }; struct Two_Floats limits = { 0.0f, 600.0f }; struct Two_Floats broken = broken_Function(limits, values); struct Two_Floats working = working_Function(limits, values); printf("And here we go: < %f , %f > \n", broken.hi, broken.lo); printf("This was to be: < %f , %f > \n", working.hi, working.lo); return 0;}`Demonstrating that the code for the second element swap is correctly emitted and the parameter passage and return value works correctly.
As a consequence the code generator is buggy steady to not emit due code.
« Last Edit: May 16, 2020, 04:04:53 pm by frankie »

Pelle

• Member
• Posts: 2091
Re: Simple argument bug
« Reply #2 on: May 17, 2020, 11:33:03 pm »
It works with the upcoming version, so I''m not going to dig into this any further...
/Pelle

gjacc

• Member
• Posts: 4
Re: Simple argument bug
« Reply #3 on: May 22, 2020, 10:20:46 am »
On my PC (Win 10) the ouput is :

And here we go: < 0.000000 , 25.000000 >
This was to be: < 0.000000 , 25.000000 >
Press any key to continue...