Lazarus

Free Pascal => FPC development => Topic started by: engkin on October 03, 2021, 08:24:56 am

Title: internal error 2014062901
Post by: engkin on October 03, 2021, 08:24:56 am
The following code produces an internal error on Mac Big Sur M1 using trunk:
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. function bug(s: string): string;
  6. var
  7.   p:pointer=@s;//internal error 2014062901
  8. begin
  9. end;
  10.  
  11. begin
  12. end.

Can you please check different OS/FPC version before I report it?
Title: Re: internal error 2014062901
Post by: bytebites on October 03, 2021, 08:44:19 am
Same result on Linux 3.2 and trunk

Do you expect this result, which prints true
Code: Pascal  [Select][+][-]
  1. function bug(s: string): string;
  2. var
  3.   //p:pointer=@s;//internal error 2014062901
  4.   p:pointer absolute s;
  5. begin
  6.   writeln(string(p));
  7.   writeln(pchar(s)=p);
  8. end;    
Title: Re: internal error 2014062901
Post by: engkin on October 03, 2021, 08:59:34 am
Thank you for testing.

Yes, I do expect True in this case. The record holding the length, ref count, code page ... is at a negative offset of s. Or did I miss your point?
Title: Re: internal error 2014062901
Post by: bytebites on October 03, 2021, 09:32:31 am
Length like so
Code: Pascal  [Select][+][-]
  1.   writeln(PSizeInt(p-sizeof(sizeint))^=length(s));
Title: Re: internal error 2014062901
Post by: Jonas Maebe on October 03, 2021, 03:05:29 pm
While it shouldn't cause an internal error, it is an invalid expression. The reason is that @s is not constant (it's the address on the stack of the ansistring, which can be different every time the function gets called). At least FPC has no support for initialising variables with non-constant expressions.
Title: Re: internal error 2014062901
Post by: engkin on October 03, 2021, 07:52:11 pm
Yes, it is a faulty code. Just the internal error should not happen.

Reported as issue #39393 (https://gitlab.com/freepascal.org/fpc/source/-/issues/39393)
TinyPortal © 2005-2018