Skip to content
GitLab
    • Why GitLab
    • Pricing
    • Contact Sales
    • Explore
  • Why GitLab
  • Pricing
  • Contact Sales
  • Explore
  • Sign in
  • Get free trial
  • FPC
  • FPCFPC
  • FPC SourceFPC Source
  • Issues
  • #40158

Inlined function returns wrong value

Inlined function returns wrong value.

Lazarus 2.3.0 (rev main-2_3-2863-g1d9dfb7574) FPC 3.3.1 x86_64-linux-qt

Demo program:

program Project1;
{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}
  cthreads, SysUtils,
  {$ENDIF}
  Classes
  { you can add units after this };

{$R *.res}
var G, i: LongWord;

  function GetValue(A: LongWord): LongWord; inline;
  begin
    Result:=G*A shr 32;
  end;

begin
  G:=123456789;
  i:=GetValue(1);
  writeln('i: ', i);
  Sleep(250);
end.

Output is 123456789. Expected output is 0. (which is when you comment the inline; keyword)

It seems it does not depend on optimization level.

Edited Feb 18, 2023 by Vojtěch Čihák
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking