Changing a value in an inline routine lazarus / 64-FPC development ---------------------------------------------------------------------- Okoba · 2022-09-17 15:34 Hello, I have a case that I can not explain except it is a bug, but it should not happen at all as it seems an obvious one and I never faced anything like this even though I am using this style of code a lot. So I am unsure if this is a bug or I am missing something? As you can see Test1Inner must not change the C, but because both are inline it does! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1;   procedure Test1Inner(V: Integer); inline;  begin    V := 0;  end;   procedure Test1; inline;  var    V: Integer;  begin    V := 1;    WriteLn('Before: ', V); //1    Test1Inner(V);    WriteLn('After: ', V); //0  end;   procedure Test2Inner(V: Integer);  begin    V := 0;  end;   procedure Test2; inline;  var    V: Integer;  begin    V := 1;    WriteLn('Before: ', V); //1    Test2Inner(V);    WriteLn('After: ', V); //1  end;   procedure Test3Inner(V: Integer); inline;  begin  V := 0;  end;   procedure Test3;  var    V: Integer;  begin    V := 1;    WriteLn('Before: ', V); //1    Test3Inner(V);    WriteLn('After: ', V); //1  end; begin  Test1;  Test2;  Test3;  ReadLn;end. ---------------------------------------------------------------------- winni · 2022-09-17 15:51 Hi! Here is the error, change it to   Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Test2Inner(var V: Integer); The same for procedure Test3Inner Winni ---------------------------------------------------------------------- Martin_fr · 2022-09-17 15:59 @winni: He does NOT want to change it. @Okoba I would say it's a bug is FPC. And it is still present in FPC 3.3.1 from earlier this month. ---------------------------------------------------------------------- PascalDragon · 2022-09-17 16:05 Quote from: Okoba on September 17, 2022, 05:34:49 pmI have a case that I can not explain except it is a bug, but it should not happen at all as it seems an obvious one and I never faced anything like this even though I am using this style of code a lot. So I am unsure if this is a bug or I am missing something? That is strange... from the assembly code it looks like Test1Inner should work like Test3Inner and in both cases V from the outer procedure should stay 1, but yet it doesn't in the first case... Please report as a bug. ---------------------------------------------------------------------- Okoba · 2022-09-17 16:19 Exactly. Weird enough I didn't see this before, it does happen only in this case for me as I use this type of code a lot, meaning inline routines change the inner value. I would appreciate if you could look into it as I feel unsafe even looking at it  Reported, 39908 ---------------------------------------------------------------------- Martin_fr · 2022-09-17 16:20 Quote from: PascalDragon on September 17, 2022, 06:05:02 pmThat is strange... from the assembly code it looks like Test1Inner should work like Test3Inner and in both cases V from the outer procedure should stay 1, but yet it doesn't in the first case... TestInner1 looks good, even Test1. But the inlined form of Test1 (in PASCALMAIN) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i # [49] Test1;  That does indeed overwrite the value "V1" is at    movl   $1,-4(%rbp) But after the call to   fpc_write_text_sint "V1" from TestInner1    movl   $0,-4(%rbp) ---------------------------------------------------------------------- PascalDragon · 2022-09-18 14:14 Quote from: Martin_fr on September 17, 2022, 06:20:03 pmQuote from: PascalDragon on September 17, 2022, 06:05:02 pmThat is strange... from the assembly code it looks like Test1Inner should work like Test3Inner and in both cases V from the outer procedure should stay 1, but yet it doesn't in the first case... TestInner1 looks good, even Test1. But the inlined form of Test1 (in PASCALMAIN) Ah, I didn't notice that Test1 is inlined as well! Yes, there is the difference, though the why is the next question of course... But since Okoba already reported it... ---------------------------------------------------------------------- BobDog · 2022-09-18 15:55 I get Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Before: 1After: 1Before: 1After: 1Before: 1After: 1 But if I change to {$mode objfpc} (or delphi) I get Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Before: 1After: 0Before: 1After: 1Before: 1After: 1 (Geany ide, no default mode objfpc). So mode FPC is OK. (just an observation) ---------------------------------------------------------------------- Okoba · 2022-09-19 04:41 I tested with all three fpc, objfpc and delphi modes and problem persists. What is your version of FPC? ---------------------------------------------------------------------- Zath · 2022-09-19 08:04 Do you have the {$inline on} set ? https://www.freepascal.org/docs-html/ref/refsu77.html ---------------------------------------------------------------------- Okoba · 2022-09-19 09:15 Yes the problem is inlining. ---------------------------------------------------------------------- Okoba · 2022-10-23 13:26 Today I was struggling with a weird bug and after hours of debugging, checking assembly code and playing with inline, I found out that this bug is again the cause. For now, I fixed it with a temporary var in the function, but this bug seems more dangerous than it looks. I wished I had enough knowledge of the compiler to fix this, but for now I hope one of the members can fix this nasty one. ---------------------------------------------------------------------- PascalDragon · 2022-10-23 14:55 Quote from: Okoba on October 23, 2022, 03:26:53 pmI wished I had enough knowledge of the compiler to fix this, but for now I hope one of the members can fix this nasty one. To be fair you'd probably need in depth knowledge for this. ---------------------------------------------------------------------- Okoba · 2022-10-23 15:18 I guessed but this bug frustrated me, as it hides itself and some times in some cases, in a function it happens.