POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Postby Zorko » Tue May 28, 2019 11:00 pm

My colleague faced this problem in CPfront.

Code: Select all
MODULE Test;
  IMPORT SYSTEM;

  VAR
    s: POINTER TO ARRAY [untagged] OF SHORTCHAR;

  PROCEDURE Call (IN s: ARRAY OF SHORTCHAR);
  END Call;

BEGIN
  Call(s)
END Test.

CPfront allows this code and even generates some representation in C language, which of course will not work correctly.

BlackBox compiler found the error in the correct place, although the marker is at the beginning of the line, not where the parameter is. But that's not the problem.

The fact is that this check performs at the back-end level (in procedures Index & VarParDynArr of the module DevCPC486), although it would be best to do this check at the level of the front-end too. If that check was done in front-end, the error would not appear in CPfront.

I propose such a correction.
Attachments
DynArrParCheck.png
Last edited by Zorko on Tue May 28, 2019 11:07 pm, edited 2 times in total.
Zorko
 
Posts: 15
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Postby Zorko » Tue May 28, 2019 11:02 pm

P.S. I foresee disputes that any fix should introduce new functionality or fix existing problems. But it's a really existing problem that the validation that needs to be done at the foreground level, since it involves type checking, takes it to the background. It's like trying to plug a crack.

I am a big supporter of the approach that every problem should be solved in the place of its occurrence, and nowhere else.

Thank you for your work!
Zorko
 
Posts: 15
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Postby Zorko » Wed May 29, 2019 1:53 am

Note: an untagged array with an explicitly specified length is equal to a tagged:

Code: Select all
VAR
  s: POINTER TO ARRAY [untagged] 10 OF SHORTCHAR;

PROCEDURE Call (a: ARRAY OF SHORTCHAR);
END Call;

BEGIN
  Call(s);  (* <- compatible *)

I didn't know that, and my correction above doesn't take that into account.
Zorko
 
Posts: 15
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Postby luowy » Wed May 29, 2019 5:37 pm

Hi Oleg,
As you pointed out, the first one can be patched at the front end;I have done it some time ago; I post it to your github;

but I don't think the second one is a bug:
for the untagged array have provided the enough info:the addr of array and the length of array, same as a tagged array;
if you dasm the code you will find the truth; Although it looks a bit weird;

luowy
luowy
 
Posts: 42
Joined: Thu Dec 17, 2015 1:32 pm

Re: POINTER TO ARRAY [untagged] accepted as the tagged ARRAY

Postby Zorko » Wed May 29, 2019 11:46 pm

Very nice patch, Wening Luo! I tested it and it works fine.

Since the module DevCPB is not included in CPfront, I can't use your patch directly, so I have to make a fix in back-end too, as in BlackBox now. In this case, BlackBox can be a host system for CPfront with your patch, and without it. Everything will work. I am truly grateful to you for your help.
Zorko
 
Posts: 15
Joined: Tue Sep 17, 2013 10:13 pm
Location: Ukraine


Return to Bug

Who is online

Users browsing this forum: No registered users and 1 guest

cron