Recent

Author Topic: FPC r43582  (Read 1251 times)

avk

  • Sr. Member
  • ****
  • Posts: 309
    • my self-education project
FPC r43582
« on: November 25, 2019, 07:24:50 am »
Just updated my Linux compiler to revision 43582 and got a new problem. This code does not compile:
Code: Pascal  [Select][+][-]
  1. program overflow;
  2. {$mode objfpc}{$Q-}{$R-}{$MACRO ON}
  3.  
  4. {$DEFINE c1 := QWord($9e3779b185ebca87)}
  5. {$DEFINE c2 := QWord($c2b2ae3d27d4eb4f)}
  6.  
  7. function DoIt(aValue: QWord): QWord;
  8. begin
  9.   Result := aValue + c1 + c2;
  10. end;
  11.  
  12. begin
  13.   WriteLn(DoIt(100001));
  14. end.  
  15.  
output:
Code: Text  [Select][+][-]
  1. Hint: (11030) Start of reading config file .../fpc/bin/x86_64-linux/fpc.cfg
  2. Hint: (11031) End of reading config file .../fpc/bin/x86_64-linux/fpc.cfg
  3. Free Pascal Compiler version 3.3.1-r43582 [2019/11/25] for x86_64
  4. Copyright (c) 1993-2019 by Florian Klaempfl and others
  5. (1002) Target OS: Linux for x86-64
  6. (3104) Compiling overflow.lpr
  7. .../overflow.lpr(9,25) Error: (3213) Overflow in arithmetic operation
  8. overflow.lpr(28) Fatal: (10026) There were 1 errors compiling module, stopping
  9. Fatal: (1018) Compilation aborted
  10. Error: .../fpc/bin/x86_64-linux/ppcx64 returned an error exitcode      
  11.  
Any suggestions?

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: FPC r43582
« Reply #1 on: November 25, 2019, 09:15:06 am »
Well, the result does not fit in a qword? (Even c1+c2 > high(qword) on first glance, $9+$C =$15 = 21 > $F)
« Last Edit: November 25, 2019, 09:18:27 am by Thaddy »

avk

  • Sr. Member
  • ****
  • Posts: 309
    • my self-education project
Re: FPC r43582
« Reply #2 on: November 25, 2019, 09:56:48 am »
Of course, it does not fit, so what?
A week ago it didn't bother compiler at all.

440bx

  • Hero Member
  • *****
  • Posts: 2015
Re: FPC r43582
« Reply #3 on: November 25, 2019, 10:29:35 am »
A week ago it didn't bother compiler at all.
The compiler should not have compiled that code a week ago. 

The current version correctly determines that it cannot represent the sum of the constants c1 and c2 which in turn prevents it from generating correct code.  It only has two options, either generate code that is incorrect or refuse to compile the program.  The latter is the only correct option.

Hopefully PascalDragon or another FPC developer will read your post and either confirm what I stated or provide the actual reason otherwise.


FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: FPC r43582
« Reply #4 on: November 25, 2019, 10:31:00 am »
Yeah, but there was a fix for the limits. That said, in Q- state it should ignore the overflow, looks like a bug that the compiler should have caught - with a warning - at compile time.

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: FPC r43582
« Reply #5 on: November 25, 2019, 10:34:46 am »
The compiler should not have compiled that code a week ago. 
Well, it is "Delphi compatible" except for the macro's of course, but with direct literal values.

I suggest to simply file a bug report. The overflows should be accepted in Q- state?
« Last Edit: November 25, 2019, 10:37:29 am by Thaddy »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8793
  • FPC developer.
Re: FPC r43582
« Reply #6 on: November 25, 2019, 10:39:17 am »
I think yes. Otherwise you can't exploit two's complement features in hashing, compression and other speed dependent code.

Don't care what the default is for $mode objfpc as long as $mode delphi is compatible, but it should be ignorable.

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: FPC r43582
« Reply #7 on: November 25, 2019, 10:39:35 am »
Of course, it does not fit, so what?
A week ago it didn't bother compiler at all.
Did it bother the programmer?  :D ;D Just file a bug report. (but only against Q- )

440bx

  • Hero Member
  • *****
  • Posts: 2015
Re: FPC r43582
« Reply #8 on: November 25, 2019, 10:42:48 am »
That said, in Q- state it should ignore the overflow, looks like a bug that the compiler should have caught - with a warning - at compile time.
That's reasonable but, $Q is supposed to control runtime overflow checking code generation.  At compile time, the compiler already knows it cannot represent the constant, consequently there is no way it can generate correct code.

The compiler could calculate the sum, let it overflow and use that result as the constant.  I could see a C compiler doing such an atrocity but not Pascal.

It will be interesting to see what PascalDragon or another FPC developer says about it.

ETA:

Well, it is "Delphi compatible" except for the macro's of course, but with direct literal values.
I didn't know that nor did I think it would ever do that.

« Last Edit: November 25, 2019, 10:45:41 am by 440bx »
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: FPC r43582
« Reply #9 on: November 25, 2019, 11:03:59 am »
It will be interesting to see what PascalDragon or another FPC developer says about it.
marcov just did! With a proper explanation why.
Quote
ETA:
I didn't know that nor did I think it would ever do that.
Always have a Delphi open when something like this pops up.

avk

  • Sr. Member
  • ****
  • Posts: 309
    • my self-education project
Re: FPC r43582
« Reply #10 on: November 25, 2019, 11:31:54 am »
I filed a bug report.

The compiler should not have compiled that code a week ago. 
Of course, you can replace the terms with their sum,
but it seems to me that this is a direct and fast road to assembler.
« Last Edit: November 25, 2019, 12:11:33 pm by avk »

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: FPC r43582
« Reply #11 on: November 25, 2019, 12:39:19 pm »
Marco added a good point above. I have added that as a comment to the bug report. This is a regression.

avk

  • Sr. Member
  • ****
  • Posts: 309
    • my self-education project
Re: FPC r43582
« Reply #12 on: November 25, 2019, 12:50:25 pm »
BTW, this error line is located exactly in the body of the hash function.

Thaddy

  • Hero Member
  • *****
  • Posts: 10516
Re: FPC r43582
« Reply #13 on: November 25, 2019, 12:57:15 pm »
BTW, this error line is located exactly in the body of the hash function.
Yes, but in this case AND  instead of + works ... :P

avk

  • Sr. Member
  • ****
  • Posts: 309
    • my self-education project
Re: FPC r43582
« Reply #14 on: November 25, 2019, 01:07:23 pm »
I would like you to clarify your point...

 

TinyPortal © 2005-2018