Page 1 of 1

Compiler TRAP 0

Posted: Thu Jun 14, 2018 10:14 am
by Robert
I am in the middle of editting this, so I know it is nonsense, but it still shouldn't TRAP the compiler.

Code: Select all

MODULE  Fred;

IMPORT  SYSTEM;

PROCEDURE  IsNaN* (s : SHORTREAL) : BOOLEAN;	(*  Detects non-signalling NaNs  *)
  CONST
     nanS  =  {22 .. 30};
  BEGIN
    RETURN  nanS - BITS (SYSTEM.VAL (INTEGER, s))  =  {}
  END  IsNaN;

PROCEDURE  Mantissa* (s : SHORTREAL) : SHORTREAL;
  CONST
    mask     =  {0 .. 19, 31};
    zeroExp  =  {20 .. 29};
  VAR
    a            :  REAL;
    exp, k, msh  :  INTEGER;
  BEGIN
    IF  IsNaN (s)      THEN  RETURN   1.5
    ELSIF  s  =   0.   THEN  RETURN   0.
    ELSIF  s  =   INF  THEN  RETURN   1.
    ELSIF  s  =  -INF  THEN  RETURN  -1.
    ELSE
      a    :=  ABS (s);
      exp  :=  ASH (SYSTEM.VAL (INTEGER, a), -23);
      WHILE  exp  =  0  DO
        s    :=  s + s; a  :=  ABS (s);
        exp  :=  SHORT (ASH (SYSTEM.VAL (INTEGER, a), -23))
      END;

      k    :=  SYSTEM.VAL (INTEGER, s);
      msh  :=  ORD (BITS (SHORT (ASH (k, -32))) * mask  +  zeroExp);
      RETURN  SYSTEM.VAL (SHORTREAL, k)
    END
  END  Mantissa;

END  Fred.
The line that causes the problem is

Code: Select all

      exp  :=  ASH (SYSTEM.VAL (INTEGER, a), -23);
a should be declared to be of type SHORTREAL, but this programming error should not cause a TRAP.

Re: Compiler TRAP 0

Posted: Thu Jun 14, 2018 12:31 pm
by cfbsoftware
What version of the compiler are you using?

I tested your example with the latest Oberon microsystems version (v1.6 11.10.2013) and it doesn't trap with that version. Instead it reports the error "illegal value of parameter"

Re: Compiler TRAP 0

Posted: Thu Jun 14, 2018 3:17 pm
by Robert
cfbsoftware wrote:What version of the compiler are you using?

I tested your example with the latest Oberon microsystems version (v1.6 11.10.2013) and it doesn't trap with that version. Instead it reports the error "illegal value of parameter"
Interesting.
I get the same sensible error message with 1.6, but a TRAP with 1.7.1 build 1014 (11-Dec-2017).

1.6 also reports, to the Log, "new symbol file"; surely that should not happen after a source code bug is detected?

Clarification: I don't actually have the Oms version immediately to hand; the version I just tested is "CPC Edition built on 12.12.2013".

Re: Compiler TRAP 0

Posted: Thu Jun 14, 2018 5:28 pm
by Josef Templ
Expressions containing an illegal SYSTEM.VAL have a potential for trapping after detecting the error.
We fixed some cases in 1.7, but obviously not all of them.
Just recently I received a report regarding a similar case.
There is already an issue addressing that.
See https://redmine.blackboxframework.org/issues/188.

- Josef

Re: Compiler TRAP 0

Posted: Fri Jun 15, 2018 8:22 am
by Robert
The proposed solution to issue 188 solves this problem.