View Issue Details

IDProjectCategoryView StatusLast Update
0036977FPCCompilerpublic2020-04-26 13:04
Reporter440bx Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformIntelOSWindows 
Product Version3.0.4 
Summary0036977: the compiler does not remove empty functions/procedures if they are nested
DescriptionWhen an empty function/procedure is at the "top level", i.e, not nested and the directive {$OPTIMIZATION REMOVEEMPTYPROCS} is specified the compiler successfully removes the empty functions/procedures.

if the function/procedure is empty but nested in another function/procedure, the compiler fails to remove it.
Steps To ReproduceCompile and examine the code produced by the following program:

{$OPTIMIZATION REMOVEEMPTYPROCS}

  // {$DEFINE TRACK_ERROR_LINE}

program EmptyProc;

procedure OuterProc();
  var
    NotNeeded1, NotNeeded2 : integer;
    p : pchar;

  procedure TrackErrorLine();
  begin
    {$IFDEF TRACK_ERROR_LINE} writeln('Error line : ', p); {$ENDIF}
  end;


  procedure Aprocedure(var x : integer);
  var
    a, b, c : integer;

  begin
    { give the compiler something to do }

    x := a * b + c;

    { do plenty of other stuff }

    {$IFDEF TRACK_ERROR_LINE} p := {$I %LINE%}; {$ENDIF}
    TrackErrorLine();
  end;

begin
  Aprocedure(NotNeeded1);
end;


begin
  OuterProc();


  writeln('press enter/return to end this program');
  readln;
end.

Changing the code to remove OuterProc (and include a call to Aprocedure instead of OuterProc) thereby making the TrackErrorLine() procedure not nested will yield the desired and expected results but, not otherwise.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2020-04-26 13:04 440bx New Issue