Recent

Author Topic: internal error 2014062901  (Read 1439 times)

engkin

  • Hero Member
  • *****
  • Posts: 2979
internal error 2014062901
« 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?

bytebites

  • Sr. Member
  • ****
  • Posts: 424
Re: internal error 2014062901
« Reply #1 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;    

engkin

  • Hero Member
  • *****
  • Posts: 2979
Re: internal error 2014062901
« Reply #2 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?

bytebites

  • Sr. Member
  • ****
  • Posts: 424
Re: internal error 2014062901
« Reply #3 on: October 03, 2021, 09:32:31 am »
Length like so
Code: Pascal  [Select][+][-]
  1.   writeln(PSizeInt(p-sizeof(sizeint))^=length(s));

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 922
Re: internal error 2014062901
« Reply #4 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.

engkin

  • Hero Member
  • *****
  • Posts: 2979
Re: internal error 2014062901
« Reply #5 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

 

TinyPortal © 2005-2018