gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

for loops and multidimensional arrays lead to internal compiler errors


From: Jack Perry
Subject: for loops and multidimensional arrays lead to internal compiler errors
Date: Fri, 27 Sep 2024 06:47:49 +0000 (UTC)

Hi

I'm pretty sure these count as bugs, and it's not clear to me that they've been reported already. My apologies if they have. Further apologies if this doesn't format properly.

I'm using gm2 (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3) on Fedora 40.

My impression is that while Items 1 and 3 are programmer errors, Item 2 is valid code. Something very much like it appeared as an example on at least one Modula-2 tutorial I was looking at.

### Item 1: FOR loops sometimes crash the compiler when given an undeclared counter variable
Inner.def:
```
DEFINITION MODULE Inner;

PROCEDURE P;

END Inner.
```
Inner.mod:
```
IMPLEMENTATION MODULE Inner;

IMPORT InOut;

PROCEDURE P (Num: CARDINAL);
VAR J: CARDINAL;
BEGIN
   InOut.WriteString("Whoops"); InOut.WriteLn;
   FOR I := 1 TO Num DO
      InOut.WriteString("Whoops"); InOut.WriteLn;
   END;
END P;

BEGIN
END Inner.
```
compile with:
```
$ gm2 -c Inner.mod
```
result:
```
cc1gm2: internal compiler error: illegal symbol
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccxmcDET.out file, please attach this to your bugreport.
```
(I looked at the bug "preprocessed source" and it didn't look like preprocessed source, so I'm not attaching it, but I can easily re-generate it if need be.)

### Item 2: invoking HIGH on a multi-dimensional array passed into a procedure
Alternate.def
```
DEFINITION MODULE Alternate;

TYPE Array2 = ARRAY CARDINAL, CARDINAL OF CHAR;

PROCEDURE P(A: Array2);

END Alternate.
```
Alternate.mod
```
IMPLEMENTATION MODULE Alternate;

IMPORT InOut;

PROCEDURE P(A: Array2);
VAR
   I, J: CARDINAL;
BEGIN
   FOR I := 0 TO HIGH(A) DO
      FOR J := 0 TO HIGH(A[I]) DO
         InOut.Write(A[I][J]);
      END;
   END;
   InOut.WriteLn;
END P;

END Alternate.
```
compile with:
```
$ gm2 -c Alternate.mod
```
result:
```
terminate called after throwing an instance of 'unsigned int'
In function ‘Alternate_P’:
cc1gm2: internal compiler error: Aborted
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/cc9FaQCm.out file, please attach this to your bugreport.
```
Item #3: passing an uninitialized array to at least some functions that expect an initialized array crashes the compiler
Stringer.mod
```
MODULE Stringer;

IMPORT FIO;

VAR A: ARRAY CARDINAL OF CHAR;
VAR Input: FIO.File;  

BEGIN  
   Input := FIO.OpenToRead("Stringer.mod");
   FIO.ReadString(Input, A);
   FIO.Close(Input);
END Stringer.
```
compile with:
```
$ gm2 Stringer.mod
```
results:
```terminate called after throwing an instance of 'unsigned int'
In function ‘_M2_Stringer_init’:
cc1gm2: internal compiler error: Aborted
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccFNGUB9.out file, please attach this to your bugreport.
```

Again, my apologies if these are known. I can submit formal bug reports if need be, but I didn't find a place to do that (maybe the gcc page?).

Jack Perry
--
I'd rather be unhappy than have a false, lying sort of happiness. -- Brave New World

reply via email to

[Prev in Thread] Current Thread [Next in Thread]