Guard error

Post Reply
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Guard error

Post by luowy »

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

Re: Guard error

Post by Josef Templ »

is there also a bug fix provided?

- Josef
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Re: Guard error

Post by luowy »

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

Re: Guard error

Post by Josef Templ »

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: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Guard error

Post by Josef Templ »

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

- Josef
Post Reply