Recent

Author Topic: SIGSEGV on inline method from unit of package  (Read 5761 times)

Okoba

  • Full Member
  • ***
  • Posts: 247
SIGSEGV on inline method from unit of package
« on: July 26, 2021, 02:58:12 pm »
I was working on a code and found a sudden crash, in trying to find the problem, I made a project I hope someone can check and help me find the reason.
Requirements for the crash:
- A project calling an inline method from another unit that is in a package.
- The project has a static array and the method too needs assigning an array.
I copied the exact code for the unit in the project and everything is working fine. Removing inline works fine, removing one of the arrays works fine.
I checked the assembly code and there is only one line difference if I use the unit from the project:
Code: Pascal  [Select][+][-]
  1. movq    $1,-40(%rbp)
Tested with Trunk FPC and Lazarus on Win X64.

jamie

  • Hero Member
  • *****
  • Posts: 4841
Re: SIGSEGV on inline method from unit of package
« Reply #1 on: July 26, 2021, 11:32:42 pm »
I'll keep it short, try initializing the array in the TEST procedure to a known length.

The only true wisdom is knowing you know nothing

Okoba

  • Full Member
  • ***
  • Posts: 247
Re: SIGSEGV on inline method from unit of package
« Reply #2 on: July 27, 2021, 08:17:26 am »
I know a fix for it. I like to know the reason and find out if it is a bug so I can report it.
Can you check and see if it happens for you or not?

jamie

  • Hero Member
  • *****
  • Posts: 4841
Re: SIGSEGV on inline method from unit of package
« Reply #3 on: July 27, 2021, 12:46:33 pm »
I know a fix for it. I like to know the reason and find out if it is a bug so I can report it.
Can you check and see if it happens for you or not?
No, sorry.  The bug is on your side.

 You need to set the length of a dynamic array which is what you have.
Array of boolean is empty until you setlenght(the size).
Otherwise its a wild value.

Enjoys the bugs, which are many, you just haven't found one yet.
The only true wisdom is knowing you know nothing

Okoba

  • Full Member
  • ***
  • Posts: 247
Re: SIGSEGV on inline method from unit of package
« Reply #4 on: July 27, 2021, 12:48:54 pm »
FPC supports assigning an array, no need for SetLength. And the problem disappear when I use the project unit. Please recheck the first post.

PascalDragon

  • Hero Member
  • *****
  • Posts: 3329
  • Compiler Developer
Re: SIGSEGV on inline method from unit of package
« Reply #5 on: July 27, 2021, 01:33:31 pm »
I was working on a code and found a sudden crash, in trying to find the problem, I made a project I hope someone can check and help me find the reason.
Requirements for the crash:
- A project calling an inline method from another unit that is in a package.
- The project has a static array and the method too needs assigning an array.
I copied the exact code for the unit in the project and everything is working fine. Removing inline works fine, removing one of the arrays works fine.
I checked the assembly code and there is only one line difference if I use the unit from the project:
Code: Pascal  [Select][+][-]
  1. movq    $1,-40(%rbp)
Tested with Trunk FPC and Lazarus on Win X64.

Please report a bug (once the Git conversion is done and the repository on GitLab becomes available).

Though the important part is not whether the unit is from a package or not, but whether the used unit is compiled during the same compilation. If you'd do a recompile with the UnitFromProject then it would fail as well.

Okoba

  • Full Member
  • ***
  • Posts: 247
Re: SIGSEGV on inline method from unit of package
« Reply #6 on: July 27, 2021, 01:36:08 pm »
Thanks for the verification. I will.

jamie

  • Hero Member
  • *****
  • Posts: 4841
Re: SIGSEGV on inline method from unit of package
« Reply #7 on: July 27, 2021, 10:39:25 pm »
FPC supports assigning an array, no need for SetLength. And the problem disappear when I use the project unit. Please recheck the first post.

Really?

I can see where this is leading.

have fun.


 
The only true wisdom is knowing you know nothing

PascalDragon

  • Hero Member
  • *****
  • Posts: 3329
  • Compiler Developer
Re: SIGSEGV on inline method from unit of package
« Reply #8 on: July 28, 2021, 09:19:28 am »
FPC supports assigning an array, no need for SetLength. And the problem disappear when I use the project unit. Please recheck the first post.

Really?

I can see where this is leading.

This was added because Delphi supports it as well since XE4. ::)

Okoba

  • Full Member
  • ***
  • Posts: 247
Re: SIGSEGV on inline method from unit of package
« Reply #9 on: July 28, 2021, 10:11:09 am »
This was added because Delphi supports it as well since XE4. ::)
And it is a nice feature.

 

TinyPortal © 2005-2018