View Issue Details

IDProjectCategoryView StatusLast Update
0036402FPCCompilerpublic2019-12-05 21:58
ReporterUgochukwu Mmaduekwe Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx86_64OSWindows 10 
Product Version3.3.1 
Summary0036402: Inline produces incorrect code which causes app to crash
DescriptionI discovered the bug when I tried compiling and running my CryptoLib4Pascal UnitTests with FPC Trunk version 3.3.1-r43642 for x86_64. In my case, it caused random access violations.

When certain methods are inlined, the compiler tends to produce incorrect code which tends to crash when run.
Steps To ReproduceTo reproduce the crash, compile the demo project attached (InliningBug.lpr) with the affected FPC version (FPC Trunk version 3.3.1-r43642 for x86_64) making sure Inlining is enabled.
Disabling optimizations does not seem to resolve the issue in my case.
the only workaround is disabling Inlining using {$INLINE OFF}
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Ugochukwu Mmaduekwe

2019-12-05 20:34

reporter  

InliningBug.lpr (1,200 bytes)   
program InliningBug;

{$MODE DELPHI}
{$INLINE ON}

type
  TInt32Array = array of Int32;
type
  { TBugger }

  TBugger = record
    FX: TInt32Array;
    FY: Int32;
    constructor Create(AIdx: Int32; const AData: TInt32Array);
  end;

type
  TBuggerArray = array of TBugger;

  function DoBuggerTwo(const A, B: TInt32Array): TInt32Array; inline;
  var
    Idx: Int32;
  begin
    for  Idx := Low(A) to High(A) do
    begin
      B[Idx] := A[Idx];
    end;
    Result := B;
  end;

  function DoBugger(const A, B: TInt32Array): TInt32Array; inline;
  var
    res: TInt32Array;
  begin
    res := System.Copy(A);
    Result := DoBuggerTwo(res, B);
  end;

  { TBugger }

  constructor TBugger.Create(AIdx: Int32; const AData: TInt32Array);
  begin
    FX := AData;
    FY := AIdx;
  end;

var
  A, B: TInt32Array;
  Idx, Count: Int32;
  BuggerArray: TBuggerArray;
begin
  A := TInt32Array.Create(1);
  B := TInt32Array.Create(2);

  Count := 5;
  SetLength(BuggerArray, Count);

  for  Idx := 0 to Count do
  begin
    BuggerArray[Idx] := TBugger.Create(Idx, DoBugger(A, B));
    WriteLn(BuggerArray[Idx].FX[0]);
  end;

  ReadLn;
end.

InliningBug.lpr (1,200 bytes)   

Ugochukwu Mmaduekwe

2019-12-05 20:36

reporter   ~0119641

Last edited: 2019-12-05 20:40

View 3 revisions

Do note that FreeBSD FPC Trunk version 3.3.1-r43642 is also affected.
I have not been able to test any i386 platform though.

Also, do note that this code works fine in FPC 3.0.4 and 3.2.0 so it's clearly a regression.

Issue History

Date Modified Username Field Change
2019-12-05 20:34 Ugochukwu Mmaduekwe New Issue
2019-12-05 20:34 Ugochukwu Mmaduekwe File Added: InliningBug.lpr
2019-12-05 20:36 Ugochukwu Mmaduekwe Note Added: 0119641
2019-12-05 20:37 Ugochukwu Mmaduekwe Note Edited: 0119641 View Revisions
2019-12-05 20:40 Ugochukwu Mmaduekwe Note Edited: 0119641 View Revisions