The compiler doesn't {$pop} local directive value lazarus / 64-FPC development ---------------------------------------------------------------------- alpine · 2022-09-20 11:30 Here are two functions, one after another. The first one is enclosed in $push/$pop directives and have a register variables optimization. I'd expect second one not to have such, but apparently 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; {$optimization off}   {$push} {$optimization regvar}  function IntLog2Up1(A: PtrUInt): PtrUInt;  var   P: PtrUInt;  begin   P := 0;   Dec(A);   if (A and $FFFF0000) <> 0 then begin A := A shr 16; P := P or 16; end;   if (A and $FF00) <> 0 then begin A := A shr 8; P := P or 8; end;   if (A and $F0) <> 0 then begin A := A shr 4; P := P or 4; end;   if (A and $0C) <> 0 then begin A := A shr 2; P := P or 2; end;   if (A and 2) <> 0 then begin A := A shr 1; P := P or 1; end;   Result := P + 1;  end;  {$pop}   function IntLog2Up2(A: PtrUInt): PtrUInt;  var   P: PtrUInt;  begin   Result := 0;   P := 1;   while (P < A) do   begin     P := P * 2;     Inc(Result);   end;  end; begin  WriteLn(IntLog2Up1(7), IntLog2Up2(7));end. Here is the beginning of the first one: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i C:\Users\alpi\AppData\Local\Temp\project1.lpr:10  P := 0;004015A3 B900000000               mov ecx,$00000000C:\Users\alpi\AppData\Local\Temp\project1.lpr:11  Dec(A);004015A8 83E801                   sub eax,$01C:\Users\alpi\AppData\Local\Temp\project1.lpr:12  if (A and $FFFF0000) <> 0 then begin A := A shr 16; P := P or 16; end;004015AB 89C2                     mov edx,eax004015AD 81E20000FFFF             and edx,$FFFF0000004015B3 F7C2FFFFFFFF             test edx,$FFFFFFFF004015B9 7502                     jnz +$02004015BB EB0F                   jmp +$0F...And here is the beginning of the second: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i C:\Users\alpi\AppData\Local\Temp\project1.lpr:25  Result := 0;00401656 B800000000               mov eax,$00000000C:\Users\alpi\AppData\Local\Temp\project1.lpr:26  P := 1;0040165B BB01000000               mov ebx,$00000001C:\Users\alpi\AppData\Local\Temp\project1.lpr:27  while (P < A) do00401660 EB0F                     jmp +$0F00401662 8DB600000000             lea esi,[esi+$00000000]C:\Users\alpi\AppData\Local\Temp\project1.lpr:29  P := P * 2;00401668 89D9                     mov ecx,ebx0040166A D1E1                   shl ecx,10040166C 89CB                     mov ebx,ecx... Lazarus 2.2.2 (rev lazarus_2_2_2) FPC 3.2.2 i386-win32-win32/win64 ---------------------------------------------------------------------- MarkMLl · 2022-09-20 11:36 I think you need a test case: what happens if you delete the $ in the {$optimization regvar} leaving everything else the same? MarkMLl ---------------------------------------------------------------------- PascalDragon · 2022-09-20 11:44 Optimization switches are not covered by $Push and $Pop. But you can use {$Optimization Default} to return to the default settings that were active at the start of reading the unit. ---------------------------------------------------------------------- Kays · 2022-09-20 11:48 Quote from: PascalDragon on September 20, 2022, 01:44:15 pmOptimization switches are not covered by $Push and $Pop. I just wanted to say that. The documentation, the Programmer’s Guide, says {$push} saves the state of local compiler directives, but with New features 3.2.0 I learned that not everything is indeed saved. ---------------------------------------------------------------------- alpine · 2022-09-20 11:55 Quote from: MarkMLl on September 20, 2022, 01:36:23 pmI think you need a test case: what happens if you delete the $ in the {$optimization regvar} leaving everything else the same? MarkMLl Here it is without the $ Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i C:\Users\alpi\AppData\Local\Temp\project1.lpr:10  P := 0;004015AA C745F400000000           mov [ebp-$0C],$00000000C:\Users\alpi\AppData\Local\Temp\project1.lpr:11  Dec(A);004015B1 836DFC01                 sub dword ptr [ebp-$04],$01C:\Users\alpi\AppData\Local\Temp\project1.lpr:12  if (A and $FFFF0000) <> 0 then begin A := A shr 16; P := P or 16; end;004015B5 8B45FC                   mov eax,[ebp-$04]004015B8 250000FFFF               and eax,$FFFF0000004015BD A9FFFFFFFF             test eax,$FFFFFFFF004015C2 7502                     jnz +$02004015C4 EB12                     jmp +$12  I have spotted the issue in another source, my code here is just a small sample. Quote from: PascalDragon on September 20, 2022, 01:44:15 pmOptimization switches are not covered by $Push and $Pop. But you can use {$Optimization Default} to return to the default settings that were active at the start of reading the unit. I see. Maybe it is a docs issue then. But it was quite confusing, since after I did that my watches on local variables went haywire. ---------------------------------------------------------------------- PascalDragon · 2022-09-21 07:33 Quote from: Kays on September 20, 2022, 01:48:21 pmQuote from: PascalDragon on September 20, 2022, 01:44:15 pmOptimization switches are not covered by $Push and $Pop. I just wanted to say that. The documentation, the Programmer’s Guide, says {$push} saves the state of local compiler directives, but with New features 3.2.0 I learned that not everything is indeed saved. Because originally it was indeed only the local switches. Later on it turned out that other settings might be nice to save as well. So that should probably be updated... Quote from: y.ivanov on September 20, 2022, 01:55:27 pmQuote from: PascalDragon on September 20, 2022, 01:44:15 pmOptimization switches are not covered by $Push and $Pop. But you can use {$Optimization Default} to return to the default settings that were active at the start of reading the unit. I see. Maybe it is a docs issue then. But it was quite confusing, since after I did that my watches on local variables went haywire. You mean after using {$Optimization Default}? ---------------------------------------------------------------------- alpine · 2022-09-27 22:04 Quote from: PascalDragon on September 21, 2022, 09:33:00 am Quote from: y.ivanov on September 20, 2022, 01:55:27 pmQuote from: PascalDragon on September 20, 2022, 01:44:15 pmOptimization switches are not covered by $Push and $Pop. But you can use {$Optimization Default} to return to the default settings that were active at the start of reading the unit. I see. Maybe it is a docs issue then. But it was quite confusing, since after I did that my watches on local variables went haywire. You mean after using {$Optimization Default}? No, no. I was confused in the beginning, when I enclosed one of the procedures with: 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 {$push} {$optimization regvar} procedure ...{$pop}Then on the following procedures, where I had a breakpoint and some watches to monitor, all locals got trashed and I needed a little time to realize that they simply went into registers because $pop doesn't work on $optimization. ---------------------------------------------------------------------- PascalDragon · 2022-09-28 07:37 Quote from: y.ivanov on September 28, 2022, 12:04:24 amNo, no. I was confused in the beginning, when I enclosed one of the procedures with: 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 {$push} {$optimization regvar} procedure ...{$pop}Then on the following procedures, where I had a breakpoint and some watches to monitor, all locals got trashed and I needed a little time to realize that they simply went into registers because $pop doesn't work on $optimization. Ah, okay. Thank you for clarifying.