View Issue Details

IDProjectCategoryView StatusLast Update
0037714FPCUtilitiespublic2020-09-20 22:22
ReporterMichal Gawrycki Assigned ToMarco van de Voort  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionno change required 
Platformi386OSWindows 
Product Version3.3.1 
Summary0037714: importtl fails with EAccessViolation exception
Descriptionimporttl fails with EAccessViolation exception.

An unhandled exception occurred at $00423718:
EAccessViolation: Access violation
  $00423718 TYPETOSTRING, line 354 of winunits-base/src/typelib.pas
  $00423D16 TYPETOSTRING, line 427 of winunits-base/src/typelib.pas
  $00424617 INTERFACEDECLARATION, line 582 of winunits-base/src/typelib.pas
  $004292BA CREATEINTERFACES, line 1437 of winunits-base/src/typelib.pas
  $0042B374 DOIMPORTTYPELIB, line 1821 of winunits-base/src/typelib.pas
  $0042BE32 EXECUTE, line 1971 of winunits-base/src/typelib.pas
  $00422B8E IMPORTTYPELIB, line 188 of winunits-base/src/typelib.pas
  $00401EA8 main, line 103 of importtl/importtl.pas
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Relationships

related to 0037780 closedJonas Maebe Wrong code generation with optimization level 2 and above (i386 win32) 

Activities

Michal Gawrycki

2020-09-07 14:52

reporter   ~0125427

This is probably a wrong code generation.

winunits-base\src\typelib.pas:353 bIsUserDefined:=false;
00421FCE 8b8574feffff mov -0x18c(%ebp),%eax
00421FD4 c6809800000000 movb $0x0,0x98(%eax)
winunits-base\src\typelib.pas:348 begin
00421FDB 668b45d0 mov -0x30(%ebp),%ax
winunits-base\src\typelib.pas:354 if (TD.vt=vt_userdefined) or ((TD.vt=VT_PTR) and (TD.lptdesc^.vt=vt_userdefined)) then
00421FDF 663d1d00 cmp $0x1d,%ax
00421FE3 7419 je 0x421ffe <TYPETOSTRING+254>
00421FE5 8b55cc mov -0x34(%ebp),%edx
00421FE8 668b5204 mov 0x4(%edx),%dx
00421FEC 6681f21d00 xor $0x1d,%dx
00421FF1 66351a00 xor $0x1a,%ax
00421FF5 6609c2 or %ax,%dx
00421FF8 0f85b2050000 jne 0x4225b0 <TYPETOSTRING+1712>
winunits-base\src\typelib.pas:358 bIsUserDefined:=true;
00421FFE 8b8574feffff mov -0x18c(%ebp),%eax
00422004 c6809800000001 movb $0x1,0x98(%eax)

The last two comparisons seem to be linked together. If I understand correctly, the last comparison (TD.lptdesc^.vt=vt_userdefined) should only be performed if the result of the second comparison (TD.vt=VT_PTR) is true. In this case, the TD.lptdesc field is null and causes an AV exception.

Michal Gawrycki

2020-09-13 20:41

reporter   ~0125528

Definitely a bug in copiler. Occurs at optimization level >= 2.
I can reproduce it in a simple test project (attached).
As I thought it was a problem with importtl, I reported it in the Utilites category. Should I submit a new issue in the Compiler category?
testbug.lpr (282 bytes)   
program testbug;

type
  PTestRec = ^TTestRec;
  TTestRec = record
    Val: Integer;
    Next: PTestRec;
  end;

var
  TR: TTestRec;

begin
  TR.Val := 6;
  TR.Next := nil;
  if (TR.Val = 10) or ((TR.Val = 5) and (TR.Next^.Val = 5)) then
    Writeln('OK');
end.

testbug.lpr (282 bytes)   

Marco van de Voort

2020-09-20 12:27

manager   ~0125659

Last edited: 2020-09-20 13:01

View 3 revisions

I can reproduce with trunk of today, so yes, please do file a bug. FPC 3.2.0 seems to be fine.

I'm no compiler dev, so my word is not final, but it seems to violate short eval rules at first glance, so I think it is definitely worthwhile to let one of the real devs comment on it.

Thanks for the isolation.

Michal Gawrycki

2020-09-20 13:50

reporter   ~0125662

Thanks.
I created a new issue 0037780.

Michal Gawrycki

2020-09-20 20:07

reporter   ~0125679

This was a compiler problem. Fixed in r46905. Importtl now works fine.

Marco van de Voort

2020-09-20 22:22

manager   ~0125683

solved as related

Issue History

Date Modified Username Field Change
2020-09-06 23:09 Michal Gawrycki New Issue
2020-09-07 14:52 Michal Gawrycki Note Added: 0125427
2020-09-13 20:41 Michal Gawrycki Note Added: 0125528
2020-09-13 20:41 Michal Gawrycki File Added: testbug.lpr
2020-09-20 12:27 Marco van de Voort Note Added: 0125659
2020-09-20 12:29 Marco van de Voort Note Edited: 0125659 View Revisions
2020-09-20 13:01 Marco van de Voort Note Edited: 0125659 View Revisions
2020-09-20 13:50 Michal Gawrycki Note Added: 0125662
2020-09-20 14:46 Jonas Maebe Relationship added related to 0037780
2020-09-20 20:07 Michal Gawrycki Note Added: 0125679
2020-09-20 22:22 Marco van de Voort Assigned To => Marco van de Voort
2020-09-20 22:22 Marco van de Voort Status new => resolved
2020-09-20 22:22 Marco van de Voort Resolution open => no change required
2020-09-20 22:22 Marco van de Voort FPCTarget => -
2020-09-20 22:22 Marco van de Voort Note Added: 0125683