From: Gaius Mulley Date: Sun, 2 Mar 2025 19:04:37 +0000 (+0000) Subject: PR modula2/119088 ICE when for loop accesses an unknown variable as the iterator X-Git-Tag: basepoints/gcc-16~1767 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=585aa4065f1028c2fbfab55462e5e5e6b3c208c4;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/m2/gm2-compiler/M2SymInit.mod b/gcc/m2/gm2-compiler/M2SymInit.mod index ffe1f9b8da3..6c8912f2c4c 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 00000000000..155b72565da --- /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.