View Issue Details

IDProjectCategoryView StatusLast Update
0033593FPCCompilerpublic2019-05-06 15:00
ReporterJakub Klos - IceWarpAssigned ToJonas Maebe 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWindowsOSOS Version
Product Version3.0.4Product Build 
Target Version3.1.1Fixed in Version3.3.1 
Summary0033593: FPC 3.0.4 Compilation exception (fatal 1018)
DescriptionWhen I touch a file (change a timestamp) FPC compiler crashes with an access violation. If I build the whole project it works properly.

This happens almost in any other unit and forces you to permanently rebuild the whole project which is time consuming and unusable. It is 100% reproducable

$ fpc SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL
Free Pascal Compiler version 3.0.4 [2018/04/10] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
Fatal: Compilation aborted
An unhandled exception occurred at $004575E9:
EAccessViolation: Access violation
  $004575E9 line 370 of symbase.pas
  $004FBB62 line 401 of pdecl.pas
  $004FB016 line 626 of pdecl.pas
  $004FBBF3 line 876 of pdecl.pas
  $0050D967 line 2218 of psub.pas
  $00509EFF line 307 of psub.pas
  $0050CCE9 line 1808 of psub.pas
  $0050D158 line 1959 of psub.pas
  $0050DE78 line 2394 of psub.pas
  $0050DD01 line 2425 of psub.pas
  $00422D0C line 1756 of cclasses.pas
  $0050DF71 line 2434 of psub.pas
  $005544A0 line 1057 of pmodules.pas
  $005543AC line 981 of pmodules.pas
  $00438D5D line 368 of parser.pas
  $0054B4D4 line 1734 of fppu.pas
  $005532E6 line 484 of pmodules.pas

Error: C:\lazarus\fpc\3.0.4\bin\i386-win32\ppc386.exe returned an error exitcode

Steps To Reproduce1. Extract the test.zip

2. Compile it with:
fpc SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL

3. Edit the TestUnit.pas so you only modify the timestamp (or you can add a comment...)

4. Compile again with the same command as in 2)

You have the exception
Additional InformationDoes not happen in FPC 2.4.6
Must be probably related to generics implementation (changes in FPC 3.x).

I compiled a debug version of the FPC compiler so I can see the stack line numbers and units. It fails in the determine_generic_def function on line 401:
                  sym:=tsym(tprocdef(pd.genericdef).localst.findwithhash(hashedid));

I would say this is a rather critical bug.
Please, let me know how I can help to fix this issue.

Thank you
Tagsgenerics
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Jakub Klos - IceWarp

2018-04-10 10:21

reporter  

test.zip (6,285 bytes)

Thaddy de Koning

2018-04-10 12:25

reporter   ~0107731

Last edited: 2018-04-10 12:26

View 2 revisions

I fixed his mess. See the forum. Pointer mistakes. See bet attachment.

Thaddy de Koning

2018-04-10 12:25

reporter  

bet.7z (5,553 bytes)

Jakub Klos - IceWarp

2018-04-10 17:51

reporter   ~0107735

The fix by removing pointers to generic types helped indeed. I still think the compiler should display some error and do not understand why it works for building but not re-compiling.
Thank you

Thaddy de Koning

2018-04-10 17:58

reporter   ~0107736

Ask on the forum as I offered.

Jonas Maebe

2018-04-10 20:06

manager   ~0107738

A compiler crash is indeed always a bug.

Thaddy de Koning

2018-04-10 20:54

reporter   ~0107742

Last edited: 2018-04-10 21:04

View 4 revisions

Jonas I know the cause:
procedure AnyProcedure<TakeAType>(var aType:TakeAType);
type
  PTakeAType = ^aType;// a local generic type as pointer to a global generic type?
var
  aPrivateToThatPrivateType:PTakeAType;
begin
  // Does also not compile in Delphi
end;

So local type declarations as pointer to a non-local generic does not work.
If you think it should be allowed then that's the bug. And I think 1018 is correct. The original code was not good enough and the language is powerful enough.

Thaddy de Koning

2018-04-10 21:05

reporter   ~0107743

Last edited: 2018-04-10 21:08

View 2 revisions

And it is not a compiler crash? I have seen worse.. This one recovers..

Jonas Maebe

2018-04-10 21:42

manager   ~0107745

"EAccessViolation: Access violation" is a compiler crash. Please stop minimizing almost everyone's bug reports.

J. Gareth Moreton

2018-04-10 23:05

developer   ~0107746

If the compiler raises an exception or an internal error (in essence, an assertion), it is automatically a bug no matter how bad the code is. This is not the place to judge someone's code quality or the features they use. If they find a combination that causes the compiler to enter a bad state, kudos to them, since it means we can then do something about it to make the next version more stable.

Note that such code examples may be purposefully bad.

Christo Crause

2018-04-11 18:44

reporter   ~0107750

I can confirm the exception on 64 bit Linux with fpc 3.0.4 and 3.1.1 (r38524) using the supplied test.zip project:

~/fpc/test $ rm *.o *.ppu
~/fpc/test $ ls
ListUnit.pas RetainableUnit.pas SimpleObjectsTest SimpleObjectsTest.dpr TestUnit.pas
~/fpc/test $ ../3.0.4/compiler/ppcx64 SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL
Free Pascal Compiler version 3.0.4 [2017/11/30] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
Compiling RetainableUnit.pas
Compiling ListUnit.pas
SimpleObjectsTest.dpr(4,3) Hint: Unit "TestUnit" not used in SimpleObjectsTest
Linking SimpleObjectsTest
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
1262 lines compiled, 0.7 sec
1 hint(s) issued
~/fpc/test $ touch TestUnit.pas
~/fpc/test $ ../3.0.4/compiler/ppcx64 SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL
Free Pascal Compiler version 3.0.4 [2017/11/30] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
Fatal: Compilation aborted
An unhandled exception occurred at $0000000000472D9B:
EAccessViolation: Access violation
  $0000000000472D9B

The crash for 3.1.1 (2nd compile):
~/fpc/test $ ../3.1.1/compiler/ppc SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL
Free Pascal Compiler version 3.1.1 [2018/03/14] for x86_64
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
ListUnit.pas(436,11) Error: Compilation raised exception internally
Fatal: Compilation aborted
An unhandled exception occurred at $0000000000597ED2:
EAccessViolation: Access violation
  $0000000000597ED2

Clearly a compiler bug.

Thaddy de Koning

2018-04-12 13:29

reporter   ~0107755

Last edited: 2018-04-12 13:36

View 5 revisions

Well not if you use the bet.7z against it. You can see there are too many mistakes in the original test.zip. And the compiler actually recovers, because it throws 1018.
Case of monkeyfood in... monkeyshit out if you are a parrot.
That said: it may well be a bug, but this is contrived. I am sure I can crash the compiler in a proper way....

That's not minimizing bug reports. That is my tests. If it is a bug it is a bug. If it is bad code it is bad code. Combine the two and yes...

And I pointed to where to find the bug in the compiler if any. And these are the correct spots...The local type declaration of a pointer type to a global other type.

J. Gareth Moreton

2018-04-13 01:28

developer   ~0107760

Last edited: 2018-04-13 01:50

View 5 revisions

I think the correct term is garbage in, garbage out. And contrived examples are perfectly valid test cases to analyse how a program responds - they are often far more common than something completely random, because you would use deliberately designed edge cases to entice an error. Even the most malformed of files should cause a compiler error, not an exception. In this case, it should tell us what is wrong with TestCase.pas.

Imagine, if you will, that you've downloaded a free software project that you've never seen the source code for before, and you compile it and it raises an access violation like that above; what are you supposed to do?

This is the kind of program where exceptions and assertions (internal errors) should NEVER happen. It can be argued that even stream read errors, for example, should be cleanly handled, since you could be reading from a network share which loses connectivity or an external hard drive that unexpectedly loses power.

(Not to brag, but I do have industry experience in SQA, more specifically, software that tested graphics drivers that partly resided in kernel space, and in those situations, triggering an unhandled exception caused a Blue Screen of Death - I quickly learnt what the code 0xC0000005 meant!)

(Apologies... this is probably more appropriate in a forum post)

J. Gareth Moreton

2018-04-13 01:30

developer   ~0107761

Last edited: 2018-04-13 01:32

View 2 revisions

Status changed to "Confirmed", as the bug has been reproduced by a third party on a different platform.

Thaddy de Koning

2018-07-25 08:58

reporter   ~0109670

You can change the status to fixed....
Re-run test.zip..

"RetainableUnit.pas(60,17) Error: No matching implementation for interface method "QueryInterface(constref TGuid;out <Formal type>):LongInt; CDecl;" found"

Which is correct (as I pointed out before).
I tested with 3.1.1-r39471

Thaddy de Koning

2018-07-25 09:12

reporter   ~0109671

$ fpc SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL -B
Free Pascal Compiler version 3.1.1-r39471 [2018/07/19] for arm
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
Compiling RetainableUnit.pas
Compiling ListUnit.pas
SimpleObjectsTest.dpr(4,3) Hint: Unit "TestUnit" not used in SimpleObjectsTest
Linking SimpleObjectsTest
1262 lines compiled, 3.6 sec
1 hint(s) issued

You need to compile the testunit separately to obtain the error message.

Christo Crause

2018-07-25 22:26

reporter   ~0109675

With trunk #39510 the compiler still raises an exception when recompiling TestUnit.

~/fpc/test $ ../3.1.1/compiler/ppcx64 SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL
Free Pascal Compiler version 3.1.1 [2018/07/25] for x86_64
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
Compiling RetainableUnit.pas
Compiling ListUnit.pas
SimpleObjectsTest.dpr(4,3) Hint: Unit "TestUnit" not used in SimpleObjectsTest
Linking SimpleObjectsTest
1262 lines compiled, 2.0 sec
1 hint(s) issued

~/fpc/test $ touch TestUnit.pas

~/fpc/test $ ../3.1.1/compiler/ppcx64 SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL
Free Pascal Compiler version 3.1.1 [2018/07/25] for x86_64
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
ListUnit.pas(436,11) Error: Compilation raised exception internally
Fatal: Compilation aborted
An unhandled exception occurred at $000000000047641B:
EAccessViolation: Access violation
  $000000000047641B

Thaddy, when you use the -B option all the units are recompiled, which masks the compiler crash. So the bug (here I'm referring to the compiler crashing, not the user's code) is still present in the compiler.

rd0x

2019-03-23 17:00

reporter   ~0114991

This can be set to solved?

fpc SimpleObjectsTest.dpr -MObjFPC -gw2 -l -g -gl -gp -XMPASCALMAIN_ALIAS -dFPC_RTL
Free Pascal Compiler version 3.2.0-beta-r41756 [2019/03/21] for x86_64
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling SimpleObjectsTest.dpr
Compiling TestUnit.pas
Compiling ListUnit.pas
ListUnit.pas(93,77) Error: No matching implementation for interface method "GetRefCount:LongInt;" found
ListUnit.pas(93,77) Error: No matching implementation for interface method "GetWeakCount:LongInt;" found
ListUnit.pas(116,1) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\fpcupdeluxe\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode

Jonas Maebe

2019-03-23 17:13

manager   ~0114992

Indeed seems fixed. Even if you fix the compilation by moving the mentioned methods from the "strict private" to the "strict protected" section of TRetainable, the program can be recompiled successfully.

Issue History

Date Modified Username Field Change
2018-04-10 10:21 Jakub Klos - IceWarp New Issue
2018-04-10 10:21 Jakub Klos - IceWarp File Added: test.zip
2018-04-10 12:25 Thaddy de Koning Note Added: 0107731
2018-04-10 12:25 Thaddy de Koning File Added: bet.7z
2018-04-10 12:26 Thaddy de Koning Note Edited: 0107731 View Revisions
2018-04-10 17:51 Jakub Klos - IceWarp Note Added: 0107735
2018-04-10 17:57 Cyrax Tag Attached: generics
2018-04-10 17:58 Thaddy de Koning Note Added: 0107736
2018-04-10 20:06 Jonas Maebe Note Added: 0107738
2018-04-10 20:54 Thaddy de Koning Note Added: 0107742
2018-04-10 20:56 Thaddy de Koning Note Edited: 0107742 View Revisions
2018-04-10 20:59 Thaddy de Koning Note Edited: 0107742 View Revisions
2018-04-10 21:04 Thaddy de Koning Note Edited: 0107742 View Revisions
2018-04-10 21:05 Thaddy de Koning Note Added: 0107743
2018-04-10 21:08 Thaddy de Koning Note Edited: 0107743 View Revisions
2018-04-10 21:42 Jonas Maebe Note Added: 0107745
2018-04-10 23:05 J. Gareth Moreton Note Added: 0107746
2018-04-11 18:44 Christo Crause Note Added: 0107750
2018-04-12 13:29 Thaddy de Koning Note Added: 0107755
2018-04-12 13:32 Thaddy de Koning Note Edited: 0107755 View Revisions
2018-04-12 13:34 Thaddy de Koning Note Edited: 0107755 View Revisions
2018-04-12 13:35 Thaddy de Koning Note Edited: 0107755 View Revisions
2018-04-12 13:36 Thaddy de Koning Note Edited: 0107755 View Revisions
2018-04-13 01:28 J. Gareth Moreton Note Added: 0107760
2018-04-13 01:29 J. Gareth Moreton Note Edited: 0107760 View Revisions
2018-04-13 01:30 J. Gareth Moreton Note Added: 0107761
2018-04-13 01:30 J. Gareth Moreton Status new => confirmed
2018-04-13 01:30 J. Gareth Moreton Target Version => 3.1.1
2018-04-13 01:32 J. Gareth Moreton Severity minor => major
2018-04-13 01:32 J. Gareth Moreton Note Edited: 0107761 View Revisions
2018-04-13 01:34 J. Gareth Moreton Note Edited: 0107760 View Revisions
2018-04-13 01:49 J. Gareth Moreton Note Edited: 0107760 View Revisions
2018-04-13 01:50 J. Gareth Moreton Note Edited: 0107760 View Revisions
2018-07-25 08:58 Thaddy de Koning Note Added: 0109670
2018-07-25 09:12 Thaddy de Koning Note Added: 0109671
2018-07-25 22:26 Christo Crause Note Added: 0109675
2019-03-23 17:00 rd0x Note Added: 0114991
2019-03-23 17:13 Jonas Maebe Note Added: 0114992
2019-03-23 17:13 Jonas Maebe Status confirmed => resolved
2019-03-23 17:13 Jonas Maebe Resolution open => fixed
2019-03-23 17:13 Jonas Maebe Assigned To => Jonas Maebe
2019-03-23 17:13 Jonas Maebe Fixed in Version => 3.3.1