[fpc-devel] Wrong debug info when using clang backend

Martin Frb lazarus at mfriebe.de
Wed Dec 6 21:58:37 CET 2023


On 06/12/2023 21:05, Jonas Maebe via fpc-devel wrote:
> On 06/12/2023 17:37, Martin Frb via fpc-devel wrote:
>> Not suer if the issue is within Fpc or clang...
>>
>> Should this be reported against Fpc?
>
> FPC defines the variables' debug info at the start of the function and 
> defines their lifetime as starting at the beginning of the function 
> and continuing until the end. But LLVM is free to modify these if it 
> notices these are too pessimistic
>
> My guess is that even without optimisations, LLVM notices these 
> variables' values are not really used later on and reduces the 
> variables' live range.

Strange, then clang has a serious issue.

I changed the code, so they are used. Still clang only defines the 
location list for the "end" keyword.
(I also removed the nested aspect)

Which in this case is
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:17  end;
000000000040143A 4883C448                 add rsp,$48
000000000040143E C3                       ret

And the location list covers those 2 statements.

Maybe it's the version of clang (if anyone has a newer one setup...)

Is there a way to see what fpc tells clang? (in human readable form)


program clang_nested_proc_1;
{$mode objfpc}

   procedure Bar(a, b: integer);
   var
     c,d: integer;
   begin
     c:=Random(99);
     d:=Random(99);
     writeln(a,b,c,d);
     d:=d+a;
     c:=c+b;
     writeln(a,b,c,d);
   end;

procedure Foo;
begin
   Bar(1,2);
end;

begin
   Foo;
end.



More information about the fpc-devel mailing list