aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2025-03-02 19:04:37 +0000
committerGaius Mulley <gaiusmod2@gmail.com>2025-03-02 19:04:37 +0000
commit585aa4065f1028c2fbfab55462e5e5e6b3c208c4 (patch)
tree4d079baab86b47e9ff70464e9d13c4a18f1a7df0
parent43a9022aa0fa2fbe66bebd51e6e73759501c04cb (diff)
downloadgcc-585aa4065f1028c2fbfab55462e5e5e6b3c208c4.zip
gcc-585aa4065f1028c2fbfab55462e5e5e6b3c208c4.tar.gz
gcc-585aa4065f1028c2fbfab55462e5e5e6b3c208c4.tar.bz2
PR modula2/119088 ICE when for loop accesses an unknown variable as the iterator
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>
-rw-r--r--gcc/m2/gm2-compiler/M2SymInit.mod21
-rw-r--r--gcc/testsuite/gm2/pim/fail/tinyfor4.mod7
2 files changed, 21 insertions, 7 deletions
diff --git a/gcc/m2/gm2-compiler/M2SymInit.mod b/gcc/m2/gm2-compiler/M2SymInit.mod
index ffe1f9b..6c8912f 100644
--- a/gcc/m2/gm2-compiler/M2SymInit.mod
+++ b/gcc/m2/gm2-compiler/M2SymInit.mod
@@ -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
index 0000000..155b725
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/tinyfor4.mod
@@ -0,0 +1,7 @@
+MODULE tinyfor4 ;
+
+VAR
+ v: INTEGER;
+BEGIN
+ FOR i := 0 TO v DO END
+END tinyfor4.