Compiler TRAP 0

Compiler TRAP 0

Postby Robert » Thu Jun 14, 2018 10:14 am

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

Re: Compiler TRAP 0

Postby cfbsoftware » Thu Jun 14, 2018 12:31 pm

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"
cfbsoftware
 
Posts: 28
Joined: Wed Sep 18, 2013 10:06 pm

Re: Compiler TRAP 0

Postby Robert » Thu Jun 14, 2018 3:17 pm

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

Re: Compiler TRAP 0

Postby Josef Templ » Thu Jun 14, 2018 5:28 pm

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

Re: Compiler TRAP 0

Postby Robert » Fri Jun 15, 2018 8:22 am

The proposed solution to issue 188 solves this problem.
User avatar
Robert
 
Posts: 109
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland


Return to Bug

Who is online

Users browsing this forum: No registered users and 1 guest

cron