View Issue Details

IDProjectCategoryView StatusLast Update
0037926FPCCompilerpublic2020-10-16 21:45
ReporterBenito van der Zander Assigned ToPierre Muller  
PrioritynormalSeverityminorReproducibilityhave not tried
Status feedbackResolutionopen 
Platformamd64OSlinux 
Product Version3.3.1 
Summary0037926: floating point exception leads to access violation
DescriptionAfter several floating point exceptions, I get an access violation
Steps To Reproduce
This works without error:

var s, sr: single;
  i, j, tempcode: Integer;
begin
  Val('8.077936E-28', sr, tempcode);

  for i := 1 to 5000 do begin
    s := 0;
    try
      for j := 0 to Random(5) do s += Random(2) * power(2, Random(256) - 127);
    except
      on e: EMathError do s := 0; //continue;
    end;
  end;

  Val('8.077936E-28', sr, tempcode);
end.


This prints EOverflow: Floating point overflow

var s, sr: single;
  i, j, tempcode: Integer;
begin
  for i := 1 to 5000 do begin
    s := 0;
    try
      for j := 0 to Random(5) do s += Random(2) * power(2, Random(256) - 127);
    except
      on e: EMathError do s := 0; //continue;
    end;
    Val('8.077936E-28', sr, tempcode);
  end;
end.


This prints EAccessViolation: Access violation


procedure test(const s: single);
var
  tempcode: integer;
  sr: single;
begin
  Val('8.077936E-28', sr, tempcode);
  if sr <> s then
end;

var s, sr: single;
  i, j, tempcode: Integer;
begin
  for i := 1 to 5000 do begin
    s := 0;
    try
      for j := 0 to Random(5) do s += Random(2) * power(2, Random(256) - 127);
    except
      on e: EMathError do s := 0; //continue;
    end;
    test(s)
  end;
end.
Additional InformationPerhaps it is related to 0037468 ?
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Benito van der Zander

2020-10-15 22:15

reporter   ~0126339

Actually this already happens with fpc 3.0.4

Although 3.0.4 always prints EOverflow not access violation. And ClearExceptions(false); before the Val prevents the error in 3.0.4

In trunk it can be prevented with ClearExceptions(false); and catching on e: Exception do. Perhaps that catches the access violation?

Pierre Muller

2020-10-16 08:35

developer   ~0126342

I can confirm that this bug is present in current x86_64-linux trunk:

It is caused by the fact that we have both an exception in the FPU unit
AND in the MMX unit.

  Problematic ode is in rtl/linux/x86_64/sighnd.inc

  The MMX exception is generated in test procedure call,
but it is masked, so no call to signaltorunerrror is generated,
but in the next FPU generated execption, the
code in signaltorunerror first sets error to 207 (in the fpu part)
but after changes it to 216 due to the masked MMX denormal exception:
2 problems here:
  Error 216 is a general access violation, and denormal should be mapped to a EMathError
which is not the case.
 As denormal exception is masked in the MMX unit,
I consider that it should not modify the value of error!

Florian

2020-10-16 21:45

administrator   ~0126350

Please check with trunk if it works as expected.

Issue History

Date Modified Username Field Change
2020-10-14 20:32 Benito van der Zander New Issue
2020-10-15 22:15 Benito van der Zander Note Added: 0126339
2020-10-16 08:35 Pierre Muller Assigned To => Pierre Muller
2020-10-16 08:35 Pierre Muller Status new => confirmed
2020-10-16 08:35 Pierre Muller FPCTarget => 3.2.2
2020-10-16 08:35 Pierre Muller Note Added: 0126342
2020-10-16 21:45 Florian Note Added: 0126350
2020-10-16 21:45 Florian Status confirmed => feedback