Function result problem with SSA on (solved in v5.00)

Beta Testing discussion on mikroPascal PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Function result problem with SSA on (solved in v5.00)

#1 Post by Dany » 24 May 2011 19:00

Hi, I have discovered something weird (seen in the software simulator): the routine "CompareStr" in the code below works fine in the PIC (P16/P18) development environment, but with the dsPIC compiler it returns -1 when it should return 0. :shock: (v4.80 bèta)

The "result" value of the function is OK (0) till just before the "exit" is excuted. After the "exit" the value has changed to -1, see comment in the source code. Replacing "exit" with "break" does not change the result.

Thanks in advance! :D

Source code:

Code: Select all

program TestCompareStr;

{ Declarations section }

var Str1, Str2: string[10];
    Reslt: integer;

function CompareStr(var S1,S2:string):integer;
// compares S1 to S2, with case-sensitivity. The return value is less than 0 if S1 is less than S2, 0 if S1 equals
// S2, or greater than 0 if S1 is greater than S2. The compare operation is based on the 8-bit ordinal value of
// each  character. Terminating char (0) is taken into account thus allowing to compare string lengths, if this is
// the only difference.
var Ptr1, Ptr2: ^Char;
begin
  Result := 0;
  Ptr1 := @S1;
  Ptr2 := @S2;
  while true do
  begin
    Result := Ptr1^ - Ptr2^;
    if (Result <> 0) or (Ptr1^ = 0) or (Ptr2^ = 0) then exit; // "result" is 0 before the "exit" is executed
    inc(Ptr1);
    inc(Ptr2);
  end;
end;  // here "result" has been changed to -1

begin
  { Main program }
  Str1 := '123';   
  Str2 := '123';  // 2 equal strings
  Reslt := CompareStr(Str1, Str2); // Reslt should be 0, but is -1 actually
end.
Last edited by Dany on 03 Jul 2011 12:41, edited 2 times in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: v4.80 bèta: function result problem?

#2 Post by Dany » 25 May 2011 09:00

Hi, the problem is not there if I disable the SSA optimisation. I use optimisation level 4 (the default).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: v4.80 bèta: function result problem with SSA optimisatio

#3 Post by filip » 26 May 2011 14:36

Hi,

I have managed to reproduce this issue and reported it to our developers.
I apologize for the inconvenience.

Regards,
Filip.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: v4.80 bèta: function result problem with SSA optimisatio

#4 Post by Dany » 26 May 2011 18:22

filip wrote:Hi,

I have managed to reproduce this issue and reported it to our developers.
I apologize for the inconvenience.

Regards,
Filip.
Thanks! :D :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

Re: v4.80 bèta: function result problem?

#5 Post by rajkovic » 27 May 2011 08:53

Dany wrote:Hi, the problem is not there if I disable the SSA optimisation. I use optimisation level 4 (the default).
dead code elimination after unconditional branch has caused SSA to fails,
we have tracked problem and fixed it, it will be included in next release.
thank you for your report.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: v4.80 bèta: function result problem?

#6 Post by Dany » 27 May 2011 09:59

rajkovic wrote:
Dany wrote:Hi, the problem is not there if I disable the SSA optimisation. I use optimisation level 4 (the default).
dead code elimination after unconditional branch has caused SSA to fails,
we have tracked problem and fixed it, it will be included in next release.
thank you for your report.
Thanks!!! :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: v4.80 bèta: function result problem with SSA optimisatio

#7 Post by Dany » 03 Jul 2011 12:40

Confirmed solved in mP v5.00.

Thanks! :D :D :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing”