View Issue Details

IDProjectCategoryView StatusLast Update
0037482FPCCompilerpublic2020-09-26 16:40
Reporterekryukov Assigned ToFlorian  
Status resolvedResolutionunable to reproduce 
Product Version3.2.0 
Summary0037482: X64 O2 optimization breaks code after revision 39353
DescriptionStarting from revision 39353 our project stops working properly, there are random bugs which we can not localize and create simple reproducible test. After testing set of revision of FreePascal compiler we've found one particular which breaks our code. Our project is really big (more than 800K lines), but found that in asm-code generated by compiler (rev 39353) bunch of LABELs are missing. I've created few screenshots of difference. Second part of asm is compiled using FPC rev 39352.
TagsNo tags attached.
Fixed in Revision
Attached Files



2020-08-04 15:50



2020-08-04 15:55

reporter   ~0124546

In other unit i've also found missing of "movl" in code after generated by FPC rev 39353


2020-08-04 16:01

reporter   ~0124548

One screenshots with missing labels "left" side is rev 39353 and "right" side is rev 39352. On screenshot with missing "movl" vise versa. In both cases FPC 39353 produce asm with missing "label" and "movl".


2020-08-06 20:39

administrator   ~0124626

Missing labels are unlikely to cause problems, if they are needed, assembling or linking will fail. Focus on the removed mov instruction. Can you post some surrounding code? You can make it also private so only developers can see it.

J. Gareth Moreton

2020-09-06 21:46

developer   ~0125411

Last edited: 2020-09-06 21:52

View 2 revisions

Can you confirm that the bug still occurs on the trunk. I've been able to reproduce the issue on r39353 (seems that a register isn't being tracked properly), but not r46787, and some of my code in that region has been updated since then, especially regarding the labels since some alignment fields were being erroneously removed (0037420).

One change that has happened that might be disguising the bug (if it hasn't been fixed) is how the compiler handles getting the length of dynamic arrays (or calling High). Before, it used to call an internal function named fpc_dynarray_high, but it now instead inserts two direct lines of assembly language.

(I reproduced the issue based on the method offered in the source code in the ZIP file, but the buggy code doesn't appear in r46787)

jamie philbrook

2020-09-07 18:03

reporter   ~0125429

Last edited: 2020-09-07 18:05

View 2 revisions

I would like to know if possible which reversion was released with the 2.0.10 ?

I ask this because I have not been able to determine that yet but mainly for other reasons like I have a project that uses 3 DLL's in windows which work fine with 3.0.4 but with 3.2.0 they compile ok and do not crash but in some places where data is returned to the Host app via Function calls, I am getting bad data.

 I have debugged and viewed the assembler code which I have a good enough understand of and I don't see a problem to start with as far as wrong instructions etc. There could be missing code or some error in a branch/Jump somewhere that I don't know..

 But the files (3 of them) do use Arrays extensively and are rather large files .

 Thus is the reason I would like to know the revision that was used in the initial 3.2.0 release with Lazarus.

 Thank you,.

J. Gareth Moreton

2020-09-07 19:56

developer   ~0125432

I'm pretty sure 3.2.0 doesn't contain any of my recent changes that caused these problems. Do your DLL issues occur in the trunk (granted, 3.2.0 having a bug isn't very good). Still, I'm glad we have larger and more varied projects to test FPC with now!

If you can reproduce your DLL issues with a simple project, I should be able to analyse the disassembly to see what's going on.

For that internal error, it's best to open a new issue for that.

jamie philbrook

2020-09-08 02:28

reporter   ~0125433

I can try to shrink it down for a failure case.

 One question however , has the internal format of multi dem arrays changed since 3.0.4 ? Because I do have a few assembler blocks doing direct access with offsets etc speed things up.

Sven Barth

2020-09-08 09:22

manager   ~0125434

@jamie philbrook: The FPC release used in Lazarus is the official FPC release which comes from the SVN Tag release_3_2_0 (here: ).

Also please open a new bug report for your issue should you manage to shrink it down. :)

The header format of dynamic arrays was not changed.

J. Gareth Moreton

2020-09-08 12:22

developer   ~0125436

If I recall, for dynamic arrays (of any kind), offset 0 contains the address of element 0 (if null, the array is empty or otherwise uninitialised), and offset -8 (on x64... I think the offset is equal to the CPU word size) is equal to High(array), or Length(array) - 1. The negative offset is so you can typecast dynamic arrays to a pointer.

On the trunk, the internal function "fpc_dynarray_high" has since been removed, and any calls to Length or High on x64 will translate into direct assembly language.

J. Gareth Moreton

2020-09-08 13:10

developer   ~0125437

As for the original problem, it doesn't seem to occur any more, but I don't know if it's actually been fixed or is merely disguised by the change in implementation for "Length(dyn-array)". I will say though that the cause was due to the destination register of the culprit MOV instruction not being tracked properly for some reason.


2020-09-26 16:40

administrator   ~0125880

In this area, a lot of things has changed so it is very likely that it is fixed meanwhile. Please re-open if you have a reproducable case.

Issue History

Date Modified Username Field Change
2020-08-04 15:50 ekryukov New Issue
2020-08-04 15:50 ekryukov File Added: Screen Shot 2020-08-04 at 16.44.27.png
2020-08-04 15:50 ekryukov File Added: Screen Shot 2020-08-04 at 16.44.35.png
2020-08-04 15:50 ekryukov File Added: Screen Shot 2020-08-04 at 16.44.43.png
2020-08-04 15:50 ekryukov File Added: Screen Shot 2020-08-04 at 16.44.50.png
2020-08-04 15:50 ekryukov File Added: Screen Shot 2020-08-04 at 16.45.00.png
2020-08-04 15:55 ekryukov Note Added: 0124546
2020-08-04 15:55 ekryukov File Added: Screen Shot 2020-08-04 at 16.53.16.png
2020-08-04 16:01 ekryukov Note Added: 0124548
2020-08-06 20:39 Florian Note Added: 0124626
2020-09-06 21:46 J. Gareth Moreton Note Added: 0125411
2020-09-06 21:52 J. Gareth Moreton Note Edited: 0125411 View Revisions
2020-09-07 18:03 jamie philbrook Note Added: 0125429
2020-09-07 18:05 jamie philbrook Note Edited: 0125429 View Revisions
2020-09-07 19:56 J. Gareth Moreton Note Added: 0125432
2020-09-08 02:28 jamie philbrook Note Added: 0125433
2020-09-08 09:22 Sven Barth Note Added: 0125434
2020-09-08 12:22 J. Gareth Moreton Note Added: 0125436
2020-09-08 13:10 J. Gareth Moreton Note Added: 0125437
2020-09-26 16:40 Florian Assigned To => Florian
2020-09-26 16:40 Florian Status new => resolved
2020-09-26 16:40 Florian Resolution open => unable to reproduce
2020-09-26 16:40 Florian FPCTarget => -
2020-09-26 16:40 Florian Note Added: 0125880