Recent

Author Topic: FPC v3.2.2 internal error  (Read 849 times)

440bx

  • Hero Member
  • *****
  • Posts: 6025
FPC v3.2.2 internal error
« on: November 08, 2025, 01:18:09 pm »
Hello,

Consider the following sample program:
Code: Pascal  [Select][+][-]
  1. program const_internal_error;
  2.  
  3. const
  4.   ACONSTANT = 3;
  5.  
  6.   b         = 5;
  7.  
  8.   { can do this: }
  9.  
  10.   {$if ACONSTANT <> b}
  11.     {$MESSAGE 'ACONSTANT is not equal to b'}
  12.   {$endif}
  13.  
  14.  
  15. type
  16.   PRECORD = ^TRECORD;
  17.   TRECORD = record
  18.     FirstField  : integer;
  19.     SecondField : DWORD;
  20.   end;
  21.  
  22.  
  23. const
  24.   { can define constants that represent the field offsets                     }
  25.  
  26.   RECORD_FIRSTFIELD_OFFSET  = @PRECORD(nil)^.FirstField;
  27.   RECORD_SECONDFIELD_OFFSET = @PRECORD(nil)^.SecondField;
  28.  
  29.   { CAN NOT do this: }
  30.  
  31.   {$if RECORD_FIRSTFIELD_OFFSET <> 5}
  32.     {$MESSAGE 'RECORD_FIRSTFIELD_OFFSET is not equal to 5'}
  33.   {$endif}
  34.  
  35.   { NOR this:        }
  36.  
  37.   {$if RECORD_FIRSTFIELD_OFFSET <> RECORD_SECONDFIELD_OFFSET}
  38.     {$MESSAGE 'RECORD_FIRSTFIELD_OFFSET is not equal to RECORD_SECONDFIELD_OFFSET'}
  39.   {$endif}
  40.  
  41.  
  42. begin
  43.  
  44.   readln;
  45. end.                  
  46.  
In line 10, the preprocessor is comparing two constants without any problems.

In lines 31 and 37, constants are being compared and in both cases the compiler emits an internal error.

Refer to the attachment to see a snapshot of the compiler messages including the internal error.

To see the error produced by the second comparison (the "NOR this:" one), comment out the first comparison. 

It would  be very nice if this problem did not occur in the upcoming v3.2.4


FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

bytebites

  • Hero Member
  • *****
  • Posts: 776
Re: FPC v3.2.2 internal error
« Reply #1 on: November 08, 2025, 02:31:02 pm »
What do you expect; You can't compare pointer to integer
Code: Pascal  [Select][+][-]
  1. var x:pointer;
  2. begin
  3.  if x=5 then  
  4. end;
  5.  
Quote
Error: Operator is not overloaded: "^untyped" = "ShortInt"

Code: Pascal  [Select][+][-]
  1.   RECORD_FIRSTFIELD_OFFSET  = int64(@PRECORD(nil)^.FirstField);
  2.   RECORD_SECONDFIELD_OFFSET = int64(@PRECORD(nil)^.SecondField);
  3.  
  4.  

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 332
  • I use FPC [main] 💪🐯💪
Re: FPC v3.2.2 internal error
« Reply #2 on: November 08, 2025, 02:31:55 pm »
FPC [main] https://gitlab.com/freepascal.org/fpc/source/-/commit/c2b8089bf4d890729f7d9e6c8d9330a92324e79b
the same

Error: Internal error 2013112802

Code: Pascal  [Select][+][-]
  1. program const_internal_error;
  2.  
  3. const
  4.   ptr = nil;
  5.  
  6. {$if ptr <> 5}
  7. {$endif}
  8.  
  9. begin
  10. end.

Related:

https://gitlab.com/freepascal.org/fpc/source/-/issues/25573

https://gitlab.com/freepascal.org/fpc/source/-/issues/25296
« Last Edit: November 08, 2025, 03:22:44 pm by ALLIGATOR »
I may seem rude - please don't take it personally

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12019
  • Debugger - SynEdit - and more
    • wiki
Re: FPC v3.2.2 internal error
« Reply #3 on: November 08, 2025, 03:05:55 pm »
As indicated there is an issue comparing pointers. I had similar issues recently. Casting to PtrUInt or PtrInt **should** solve it.

Of course "internal error" still is a bug.

Maybe related to https://gitlab.com/freepascal.org/fpc/source/-/issues/41460 (I had tried the subtraction in a "const" section first... / but apparently any "pointer - pointer")

PascalDragon

  • Hero Member
  • *****
  • Posts: 6283
  • Compiler Developer
Re: FPC v3.2.2 internal error
« Reply #4 on: November 08, 2025, 06:14:07 pm »
It would  be very nice if this problem did not occur in the upcoming v3.2.4

Considering that according to ALLIGATOR that's not even fixed in main, very unlikely. Please report a bug.

440bx

  • Hero Member
  • *****
  • Posts: 6025
Re: FPC v3.2.2 internal error
« Reply #5 on: November 08, 2025, 07:51:39 pm »
What do you expect; You can't compare pointer to integer
those constants are _not_ typed, therefore the expression result should be a plain integer, for that reason, I expect the comparison to work.

IOW, there is no type associated with the constant identifier, therefore the constant should be an integer constant, not a pointer constant.



Please report a bug.
Done.

Ticket: 41487
Link: https://gitlab.com/freepascal.org/fpc/source/-/issues/41487



ETA:

forgot to mention that even casting the resulting constant to longint still causes the compiler to emit an internal error.


typecasting to longint does work (eliminate the internal error.)
« Last Edit: November 08, 2025, 10:04:44 pm by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12019
  • Debugger - SynEdit - and more
    • wiki
Re: FPC v3.2.2 internal error
« Reply #6 on: November 08, 2025, 08:28:16 pm »
IOW, there is no type associated with the constant identifier, therefore the constant should be an integer constant, not a pointer constant.

The "@" returns a pointer, so the value is typed.

Quote
forgot to mention that even casting the resulting constant to longint still causes the compiler to emit an internal error.

With the following, I can compile it without error (fpc 3.2.3)
Code: Pascal  [Select][+][-]
  1.       RECORD_FIRSTFIELD_OFFSET  = ptruint(@PRECORD(nil)^.FirstField);
  2.       RECORD_SECONDFIELD_OFFSET = ptruint(@PRECORD(nil)^.SecondField);
  3.  

440bx

  • Hero Member
  • *****
  • Posts: 6025
Re: FPC v3.2.2 internal error
« Reply #7 on: November 08, 2025, 09:15:48 pm »
The "@" returns a pointer, so the value is typed.
That sounds reasonable but the type assigned to constants does not seem to be very consistent but, you're right, in that case it is a pointer.

With the following, I can compile it without error (fpc 3.2.3)
Code: Pascal  [Select][+][-]
  1.       RECORD_FIRSTFIELD_OFFSET  = ptruint(@PRECORD(nil)^.FirstField);
  2.       RECORD_SECONDFIELD_OFFSET = ptruint(@PRECORD(nil)^.SecondField);
  3.  
Yes, that works.  It does compile without errors.  Thank you Martin, I can use that.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6283
  • Compiler Developer
Re: FPC v3.2.2 internal error
« Reply #8 on: November 10, 2025, 09:52:00 pm »

 

TinyPortal © 2005-2018