Compiler TRAP 0

Post Reply
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Compiler TRAP 0

Post 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.
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: Compiler TRAP 0

Post 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"
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Compiler TRAP 0

Post 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".
Josef Templ
Posts: 262
Joined: Tue Sep 17, 2013 6:50 am

Re: Compiler TRAP 0

Post 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
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Compiler TRAP 0

Post by Robert »

The proposed solution to issue 188 solves this problem.
Post Reply