Page 1 of 1

Guard error

Posted: Tue Jul 11, 2017 2:31 am
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

Re: Guard error

Posted: Tue Jul 11, 2017 7:23 am
by Josef Templ
is there also a bug fix provided?

- Josef

Re: Guard error

Posted: Tue Jul 11, 2017 8:33 am
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;

Re: Guard error

Posted: Tue Jul 11, 2017 10:17 am
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

Re: Guard error

Posted: Wed Oct 11, 2017 11:45 am
by Josef Templ
This topic can be closed, I think.
It has been solved in issue-#165.

- Josef