Guard error

Guard error

Postby luowy » Tue Jul 11, 2017 2:31 am

the member Ilya Ermakov of oberoncre report a compiler bug:https://forum.oberoncore.ru/viewtopic.php?f=127&t=6081
Code: Select all
MODULE Test;
   
   TYPE
      Obj = POINTER TO RECORD END;

   PROCEDURE Fun (): ANYPTR;
      VAR obj: Obj;
   BEGIN
      NEW(obj);
   RETURN obj
   END Fun;

   PROCEDURE Proc (VAR p: Obj);
   BEGIN
      p := NIL
   END Proc;

   PROCEDURE Do*;
   BEGIN
      Proc(Fun()(Obj))
   END Do;
   
END Test.

(!)Test.Do

Code: Select all
MODULE Test;
   
   TYPE
      Obj = POINTER TO RECORD END;

   PROCEDURE Fun (): [b]Obj;[/b]
      VAR obj: Obj;
   BEGIN
      NEW(obj);
   RETURN obj
   END Fun;

   PROCEDURE Proc (VAR p: Obj);
   BEGIN
      p := NIL
   END Proc;

   PROCEDURE Do*;
   BEGIN
      Proc(Fun()(Obj))
   END Do;
   
END Test.

(!)Test.Do


and Oleg report Ofront can catch such bug without problem.
Code: Select all
MODULE Test;

   IMPORT SYSTEM;
   
   TYPE
      Obj = POINTER TO RECORD END;
      
   PROCEDURE Fun(): SYSTEM.PTR;
      VAR obj: Obj;
   BEGIN
      NEW(obj); RETURN obj;
   END Fun;

   PROCEDURE Proc(VAR p: Obj);
   BEGIN
      p := NIL;
   END Proc;
   
   PROCEDURE Do* ();
   BEGIN
      Proc(Fun()(Obj));
   END Do;
   
END Test.

the bug is not easy to find, thanks Ilya Ermakov report it. the fixup is simple.

luowy
luowy
 
Posts: 226
Joined: Mon Oct 20, 2014 12:52 pm

Re: Guard error

Postby Josef Templ » Tue Jul 11, 2017 7:23 am

is there also a bug fix provided?

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: Guard error

Postby luowy » Tue Jul 11, 2017 8:33 am

the simple fixup for BB at DevCPB.NotVar,but dont know how your Ofront catch such error.
Code: Select all
   PROCEDURE NotVar (x: DevCPT.Node): BOOLEAN;
   BEGIN
      RETURN
         (x.class >= Nconst) & ((x.class # Nmop) OR (x.subcl # val) OR (x.left.class >= Nconst))
         OR (x.typ.form IN {String8, String16})
         (*>>*)OR (x.class = Nguard)&NotVar(x.left); (*<<*)
   END NotVar;
luowy
 
Posts: 226
Joined: Mon Oct 20, 2014 12:52 pm

Re: Guard error

Postby Josef Templ » Tue Jul 11, 2017 10:17 am

Looks plausible, thanks.

One aspect puzzles me, though.
Wouldn't it be required to apply a fix also for the SYSTEM.VAL case
((x.class # Nmop) OR (x.subcl # val) OR (x.left.class >= Nconst))

i.e use NotVar(x.left) instead of only checking (x.left.class >= Nconst) directly.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am

Re: Guard error

Postby Josef Templ » Wed Oct 11, 2017 11:45 am

This topic can be closed, I think.
It has been solved in issue-#165.

- Josef
User avatar
Josef Templ
 
Posts: 2038
Joined: Tue Sep 17, 2013 6:50 am


Return to Resolved (Bugs)

Who is online

Users browsing this forum: No registered users and 1 guest

cron