View Issue Details

IDProjectCategoryView StatusLast Update
0038259FPCCompilerpublic2020-12-31 16:52
ReporterJonas Maebe Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0038259: "exit" in an inlined routine is interpreted as an exit from the calling routine by DFA
DescriptionIf an inlined procedure calls "exit", the DFA interprets this as an exit from the caller of this inlined routine. Happens with both 3.2.0 and trunk.
Steps To ReproduceCompile this program with -O3 -vw

{$mode objfpc}
{$inline on}

procedure test; inline;
begin
  exit;
end;

function f: longint;
begin
  test; // tt.pp(11,3) Warning: Function result variable does not seem to be initialized
  result:=4;
end;

begin
end.
Additional InformationThis bug breaks "make cycle" with -O3 or higher on libc-based platforms, because of the following warning:

cutils.pas(1201,10) Warning: Function result variable does not seem to be initialized

(triggered by rtl/inc/cgeneric.inc:30)
TagsNo tags attached.
Fixed in Revision47894, 47926
FPCOldBugId
FPCTarget-
Attached Files

Activities

Serge Anvarov

2020-12-26 09:05

reporter   ~0127801

I think the problem is only in the wrong warning.
This code works as expected (with the same warning):
[code]
{$MODE OBJFPC}
{$APPTYPE CONSOLE}

procedure Test; inline;
begin
  Writeln('1');
  Exit;
end;

function Func: longint;
begin
  Test; // tt.pp(11,3) Warning: Function result variable does not seem to be initialized
  Result := 4;
end;

begin
  Writeln(Func);
  Readln;
end.
[/code]

Jonas Maebe

2020-12-26 09:43

manager   ~0127802

Last edited: 2020-12-26 12:34

View 2 revisions

It indeed does not exit the calling routine. However, the DFA is not used only for warnings, but also for various optimizations (although I don't know whether it only interprets it wrongly when producing the warning, or also in other analyses).

Edit: and it breaks "make cycle" on those platforms because warnings are treated as errors while building the compiler.

Jonas Maebe

2020-12-31 13:24

manager   ~0127971

Thanks for the fix, but unfortunately it seems there are still cases where it doesn't work yet.

cutils.pas(1382,10) Warning: Function result variable does not seem to be initialized
cutils.pas(1382,10) Warning: Function result variable does not seem to be initialized
cutils.pas(1382,10) Warning: Function result variable does not seem to be initialized

(yes, all warnings are for the same line)

Repro:

{$mode objfpc}
{$inline on}

procedure mymove(var src,dst; len: ptrint); inline;
  begin
    if len<=0 then
      exit;
  end;


function concatansistrings(p1,p2 : pchar;length1,length2 : longint) : pchar;
var
  p : pchar;
begin
  getmem(p,length1+length2+1);
  mymove(p1[0],p[0],length1);
  mymove(p2[0],p[length1],length2+1);
  concatansistrings:=p;
end;

begin
end.

Florian

2020-12-31 16:52

administrator   ~0127976

Next try :)

Issue History

Date Modified Username Field Change
2020-12-25 21:11 Jonas Maebe New Issue
2020-12-26 09:05 Serge Anvarov Note Added: 0127801
2020-12-26 09:43 Jonas Maebe Note Added: 0127802
2020-12-26 12:34 Jonas Maebe Note Edited: 0127802 View Revisions
2020-12-29 23:35 Florian Assigned To => Florian
2020-12-29 23:35 Florian Status new => resolved
2020-12-29 23:35 Florian Resolution open => fixed
2020-12-29 23:35 Florian Fixed in Version => 3.3.1
2020-12-29 23:35 Florian Fixed in Revision => 47894
2020-12-29 23:35 Florian FPCTarget => -
2020-12-31 13:24 Jonas Maebe Status resolved => feedback
2020-12-31 13:24 Jonas Maebe Resolution fixed => open
2020-12-31 13:24 Jonas Maebe Note Added: 0127971
2020-12-31 16:52 Florian Status feedback => resolved
2020-12-31 16:52 Florian Resolution open => fixed
2020-12-31 16:52 Florian Fixed in Revision 47894 => 47894, 47926
2020-12-31 16:52 Florian Note Added: 0127976