vishapoberon/compiler

Passing two dimensional array as an argument results in incompatible pointer type error.

Opened this issue · 5 comments

Given the following program, BrokenArray.Mod:

MODULE BrokenArray;
  IMPORT Out;

  VAR
    i, j: INTEGER;
    a1: ARRAY 2, 3 OF LONGINT;

  PROCEDURE p (a: ARRAY OF ARRAY OF LONGINT);
  BEGIN
    Out.String ('LEN (a,0): '); Out.Int (LEN(a,0), 0); Out.Ln;
    Out.String ('LEN (a,1): '); Out.Int (LEN(a,1), 0); Out.Ln;
  END p;

BEGIN
  FOR i := 0 TO LEN (a1, 0) DO
    FOR j := i TO LEN (a1, 1) DO
      a1[i,j] := i * j;
    END;
  END;

  p (a1);
END BrokenArray.

I get the following results:

$ voc -f -m BrokenArray.Mod BrokenArray.Mod  Compiling BrokenArray.  Main program.  1050 chars.
BrokenArray.c: In function ‘main’:
BrokenArray.c:47:23: error: passing argument 1 of ‘BrokenArray_p’ from incompatible pointer type [-Wincompatible-pointer-types]
   47 |         BrokenArray_p(BrokenArray_a1, 2, 3);
      |                       ^~~~~~~~~~~~~~
      |                       |
      |                       INT32 (*)[3] {aka int (*)[3]}
BrokenArray.c:19:35: note: expected ‘INT32 *’ {aka ‘int *’} but argument is of type ‘INT32 (*)[3]’ {aka ‘int (*)[3]’}
   19 | static void BrokenArray_p (INT32 *a, ADDRESS a__len, ADDRESS a__len1)
      |                            ~~~~~~~^
C compile and link: gcc -fPIC -g -I "/usr/local/sw/versions/voc/git/2/include"   BrokenArray.c  -o BrokenArray -L"/usr/local/sw/versions/voc/git/lib" -lvoc-O2
-- failed: status 0, exitcode 1.
Terminated by Halt(1). 

This is on Fedora 40 with gcc (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1).

This also happens with assigning a pointer to an extension to a pointer of its base type.

Given the program BrokenTypeBound.Mod:

MODULE BrokenTypeBound;
  IMPORT Out;

  TYPE
    T0 = RECORD END;
    T1 = RECORD (T0) END;

  VAR
    t0p: POINTER TO T0;
    t1p: POINTER TO T1;
BEGIN
  NEW (t1p);
  t0p := t1p;
END BrokenTypeBound.

I get the following result:

voc -f -m BrokenTypeBound.Mod
BrokenTypeBound.Mod  Compiling BrokenTypeBound.  Main program.  1103 chars.
BrokenTypeBound.c: In function ‘main’:
BrokenTypeBound.c:48:29: error: assignment to ‘BrokenTypeBound_T0 *’ from incompatible pointer type ‘BrokenTypeBound_T1 *’ [-Wincompatible-pointer-types]
   48 |         BrokenTypeBound_t0p = BrokenTypeBound_t1p;
      |                             ^
C compile and link: gcc -fPIC -g -I "/usr/local/sw/versions/voc/git/2/include"   BrokenTypeBound.c  -o BrokenTypeBound -L"/usr/local/sw/versions/voc/git/lib" -lvoc-O2
-- failed: status 0, exitcode 1.
Terminated by Halt(1). 

oh thank you, need to take a look soon.

Both these errors were fixed in Ofront+

On BrokenArray: Oleg-N-Cher/OfrontPlus@fe43645

On BrokenTypeBound: Oleg-N-Cher/OfrontPlus@69e7660

I hope to save you some time.

Oleg, thank you so much, I was vaguely remember that there was something about arrays to fix and i saw it was fixed in Ofront+.

Thank you for pointing to the fixes and helping to improve Oberon support, independently of implementation. (:

You're welcome, Norayr.

As it turned out, T. Kurt Bond also helped me find a bug in Ofront+, too. So thanks.