]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/119088 ICE when for loop accesses an unknown variable as the iterator
authorGaius Mulley <gaiusmod2@gmail.com>
Sun, 2 Mar 2025 19:04:37 +0000 (19:04 +0000)
committerGaius Mulley <gaiusmod2@gmail.com>
Sun, 2 Mar 2025 19:04:37 +0000 (19:04 +0000)
This patch fixes an ICE which occurs when a FOR statement attempts to
use an undeclared variable as its iterator.

gcc/m2/ChangeLog:

PR modula2/119088
* gm2-compiler/M2SymInit.mod (ConfigSymInit): Reimplement to
defensively check for NulSym type.

gcc/testsuite/ChangeLog:

PR modula2/119088
* gm2/pim/fail/tinyfor4.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/M2SymInit.mod
gcc/testsuite/gm2/pim/fail/tinyfor4.mod [new file with mode: 0644]

index ffe1f9b8da33aac13ca29f19e88ce082b4979ef4..6c8912f2c4c002885c83b42e5ceebb3a690c9b22 100644 (file)
@@ -202,16 +202,23 @@ BEGIN
       desc^.sym := sym ;
       desc^.type := GetSType (sym) ;
       desc^.initialized := FALSE ;
-      IF IsRecord (desc^.type)
+      (* An unknown symbol will have no type.  *)
+      IF desc^.type = NulSym
       THEN
-         desc^.kind := record ;
-         desc^.rec.fieldDesc := Indexing.InitIndex (1) ;
-         PopulateFields (desc, desc^.type)
-      ELSE
          desc^.kind := scalar ;
-         IF IsArray (desc^.type)
+         desc^.initialized := TRUE   (* For now we don't attempt to handle array types.  *)
+      ELSE
+         IF IsRecord (desc^.type)
          THEN
-            desc^.initialized := TRUE   (* For now we don't attempt to handle array types.  *)
+            desc^.kind := record ;
+            desc^.rec.fieldDesc := Indexing.InitIndex (1) ;
+            PopulateFields (desc, desc^.type)
+         ELSE
+            desc^.kind := scalar ;
+            IF IsArray (desc^.type)
+            THEN
+               desc^.initialized := TRUE   (* For now we don't attempt to handle array types.  *)
+            END
          END
       END
    END
diff --git a/gcc/testsuite/gm2/pim/fail/tinyfor4.mod b/gcc/testsuite/gm2/pim/fail/tinyfor4.mod
new file mode 100644 (file)
index 0000000..155b725
--- /dev/null
@@ -0,0 +1,7 @@
+MODULE tinyfor4 ;  
+
+VAR
+  v: INTEGER;
+BEGIN
+   FOR i := 0 TO v DO END
+END tinyfor4.