[SOLVED]Compiler throws "segmentation violatio" with -fpmode

General FreeBASIC programming questions.
Manpcnin
Posts: 23
Joined: Feb 25, 2007 1:43
Location: N.Z.

[SOLVED]Compiler throws "segmentation violatio" with -fpmode

Postby Manpcnin » Feb 04, 2015 4:26

I recently tried some compiler flags to try improve my program speed, and when compiling with: "-fpu sse -fpmode fast", my compiler aborts with "segmentation violation signal"
The code has compiled fine for years (don't ask) on versions from 0.22 with other flags (including just "-fpu sse" which was my standard option for this project)

Any clue why changing the flag should suddenly produce this? Anyone seen a similar issue? Any clues on how to narrow down the issue?
I've been fiddling with the code on and off for years now as I said and the whole thing is too big to post here, but I'll go through my old versions; compiling with the same flag, and report back here.

N.B. The .CHM note on -fpmode claims that it only affects sin(), cos() and sqr(). but I only have a handful of those calls and I can't see any problem with them.
Manpcnin

EDIT

Found the first version of the code where the compiler fails and this change stuck out to me:

Code: Select all

type p3d
    x as double
    y as double
    z as double
    'w as single
end type

was changed to:

Code: Select all

type p3d
    union
        x as single
        xi as uinteger
    end union
    union
        y as single
        yi as uinteger
    end union
    union
        z as single
        zi as uinteger
    end union
end type
is there any reason why this should cause complilation errors?

EDIT x2 combo Ignore the above. Found the offending code.
Removing the only four calls to sin() and cos() stopped the compiler abort. However, there still does not appear to be a good reason for the crash. The code should be valid. It's equivalent to:

Code: Select all

dim as single zrot,urot,cosa,sina,cosa2,sina2
'
'
'
'
cosa = cos(zrot):sina= sin(zrot)
cosa2 = cos(urot):sina2= sin(urot)
which compiles fine.
Also it is most definitely a compiler error! not a runtime error.
Last edited by Manpcnin on Feb 05, 2015 17:45, edited 1 time in total.
dkl
Site Admin
Posts: 3212
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Compiler throws "segmentation violation signal" with -fp

Postby dkl » Feb 04, 2015 10:05

Yea, the compiler should never crash. Could you post a code snippet that triggers the problem? What fbc version are you using? What system?

I've tried compiling this:

Code: Select all

dim as single zrot,urot,cosa,sina,cosa2,sina2
cosa = cos(zrot):sina= sin(zrot)
cosa2 = cos(urot):sina2= sin(urot)


with -fpu sse -fpmode fast with various fbc versions (0.24.0, 0.90.1, 1.00.0, 1.02.0) on Linux here, but I don't get a crash.
Manpcnin
Posts: 23
Joined: Feb 25, 2007 1:43
Location: N.Z.

Re: Compiler throws "segmentation violation signal" with -fp

Postby Manpcnin » Feb 04, 2015 18:49

System details:
Windows 7, 64 bit
CPU: i7-3770 (hyper-threading enabled)
FBC 1.01.0

I'll try compiling with earlier versions of FBC when I get a chance. Hopefully later today.

As to the code snippet, I have 1000+ lines of code combining to produce the error at the moment. And as you saw when I simplify the "offending" instructions down, the error goes away, so I'll have to do some more tinkering to get a reasonable reproducible error.
Manpcnin
Posts: 23
Joined: Feb 25, 2007 1:43
Location: N.Z.

Re: Compiler throws "segmentation violation signal" with -fp

Postby Manpcnin » Feb 05, 2015 7:38

Code to reproduce:
Use -fpu sse -fpmode fast
Tested on fbc Version 1.01.0

Code: Select all

const wdth = 1023:const hght = 767
const wdth1 = wdth+1:const hght1 = hght+1
const pi = 3.141592653589
const pi2 = pi*2
const pi_2 = pi/2

dim as integer mx,my ':getmouse mx,my
dim as single zrot,urot,cosa,sina,cosa2,sina2

zrot -= ((mx/wdth1)-.5)
urot += ((my/hght1)-.5)
if urot < -PI_2 then
    urot = -PI_2
elseif urot > PI_2 then
    urot = PI_2
end if

cosa = cos(zrot):sina= sin(zrot)
cosa2 = cos(urot):sina2= sin(urot)

end

Desired output: code compiles.
Actual output: compiler fails with: "Aborting due to runtime error 12 ("segmentation violation" signal)"
EDIT: even smaller repro code!

Code: Select all

const pi_2 = 1.570796326794
dim as single urot,cosa
urot = PI_2
cosa = cos(urot)


I have been unable to reproduce the abort on FBC version 0.23.0, which is the next most recent version I have.
I'd appreciate it if someone with versions 0.24 - 1.0.0 could reply with results.
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Compiler throws "segmentation violation signal" with -fp

Postby frisian » Feb 05, 2015 10:27

Tested the short version.

FBC 0.21.0, FBC 0.22.0 and FBC 0.24.0 compile correct.

FBC 0.90.0, FBC 1.00.0, FBC 1.01.0, FBC 0.25 (01-26-2013) and FBC 1.02.0 (01-17-2015) all abort with a "runtime error 12" when they are compiling.

When replacing -fpmode fast with -fpmode precise or dropping -fpmode fast then there is no error message.

I use FBedit, when compiling it start normal then displays the error message and then ends with "make done". When using the console to start FBC it displays the runtime error and then stops.

It's a problem in FBC introduced between versions 0.24 and 0.90, it's not an error in the program being compiled.
fxm
Posts: 9994
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Compiler throws "segmentation violation signal" with -fp

Postby fxm » Feb 05, 2015 12:00

Changelog.txt

Version 0.90.0 (former 0.25.0):
.....
[fixed]
.....
SSE emitter: float2int conversions using movss/movlpd could generate illegal ASM

Perhaps linked with the corresponding commit:
SSE emitter: Fix wrong movss/movlpd operand size in float2int conversions
dkl
Site Admin
Posts: 3212
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Compiler throws "segmentation violation signal" with -fp

Postby dkl » Feb 05, 2015 14:58

Thanks for the test case, it was very useful. The compiler crash should be fixed in Git now:
SSE emitter: Fix potential ICE if certain float constants exist
Manpcnin
Posts: 23
Joined: Feb 25, 2007 1:43
Location: N.Z.

Re: Compiler throws "segmentation violation signal" with -fp

Postby Manpcnin » Feb 05, 2015 17:42

Nice, Quick work!
I'm just glad to be able to help.
Marking thread as resolved.

Return to “General”

Who is online

Users browsing this forum: Richard and 10 guests