Forum > FPC development

Two compiler issues detected - advise needed

<< < (2/3) > >>

AlexTP:
For such conservative users, fpcUpDeluxe program exists, it allows to install FPC 'latest' with 3 clicks. But with internet access.

Zvoni:

--- Quote from: Fibonacci on September 06, 2023, 10:06:00 am ---As for inline, here is a litte demo


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function is_int_even(i: integer): boolean; inline;begin  i := i mod 2; //here internal copy of "i" is actualy used byref instead of byval  result := i=0;end; procedure intshow; inline;var  i: integer;begin  i := 10;   if is_int_even(i) then begin    i := i*10;     writeln('i = ', i); //prints 0, expected 10*10=100  end;   readln;end; begin  intshow;end. 
The bug is reported but nothing is done about it. Actually the patch was submitted, but not merged.

--- End quote ---
I'm not even sure this is a bug. At least not how i understand inline to work:
The way i understand how inline works would result in (Aircode!!):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure intshow; inline;var  i: integer;begin  i := 10;   //if is_int_even(i) then begin  i:=i mod 2  If i=0 Then Begin    i := i*10;  // 0 times Something is still 0     writeln('i = ', i); //prints 0, expected 10*10=100  end;   readln;end;
EDIT: I finally got your point.
Yes, looks like a bug (handled as "var/out"-Parameter)

Do you get the same "result" if you change as follows:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function is_int_even(i: integer): boolean; inline;begin  result :=  (i mod 2=0);end;

MathMan:

--- Quote from: Fibonacci on September 06, 2023, 10:06:00 am ---
--- Quote from: MathMan on September 06, 2023, 09:01:05 am ---* a function declaration as inline leads to incorrect calculations - happens on all optimisation level settings
** I have not drilled down this one further, as the inlined function has ~50 LOC and following that in asm is a bit tedious
** current work-around - remove inline decoration and all computations work correct

--- End quote ---

As for inline, here is a litte demo

<snip>

--- End quote ---

Thanks Fibonacci - yes, such a byref vs byval issue could definitely happen in my case too (top-of-the-head statement - I don't have the sources with me, but if memory serves ...)

Fibonacci:

--- Quote from: Zvoni on September 06, 2023, 10:44:57 am ---I'm not even sure this is a bug. At least not how i understand inline to work:
The way i understand how inline works would result in (Aircode!!):

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure intshow; inline;var  i: integer;begin  i := 10;   //if is_int_even(i) then begin  i:=i mod 2  If i=0 Then Begin    i := i*10;  // 0 times Something is still 0     writeln('i = ', i); //prints 0, expected 10*10=100  end;   readln;end;
--- End quote ---

So you understand it wrong. Its not a "macro" that just "paste" the code where it was called.

I have my FPC patched, just 1 line added that fixes this particular issue.

@MathMan: I give 90% chances this is it. If you compile FPC with fpcupdeluxe, goto Setup+ and add FPC patch, it's in the attachment. Build 3.3.1 version.


--- Quote from: Zvoni on September 06, 2023, 10:44:57 am ---EDIT: I finally got your point.
Yes, looks like a bug (handled as "var/out"-Parameter)

Do you get the same "result" if you change as follows:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function is_int_even(i: integer): boolean; inline;begin  result :=  (i mod 2=0);end;
--- End quote ---

No, the bug doesnt exists in this case. The variable must be modified.

MathMan:

--- Quote from: AlexTP on September 06, 2023, 10:37:09 am ---For such conservative users, fpcUpDeluxe program exists, it allows to install FPC 'latest' with 3 clicks. But with internet access.

--- End quote ---

AlexTP - I'm fully aware of FpcUpDeluxe. But as said I do not have Internet access @ home, and I'm not allowed to bring my private PCs to the office. So unfortunately no option for me.

I'm just a hobby Pascal programmer - I don't do this for a living. Maybe this explains why I asked initially if this is already known - I'm willing to help, but there are limits to what I can do.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version