From: Gaius Mulley Date: Tue, 1 Aug 2023 00:42:16 +0000 (+0100) Subject: PR modula2/110865 Unable to access copied const array X-Git-Tag: basepoints/gcc-15~7247 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a47474f2cf48837d6adf4a1232a89fd398ca7fa;p=thirdparty%2Fgcc.git PR modula2/110865 Unable to access copied const array This patch allows constants of an array type to be indexed. gcc/m2/ChangeLog: PR modula2/110865 * gm2-compiler/M2Quads.mod (BuildDesignatorArray): Rename t as type and d as dim. New variable result. Allow constants of an array type to be indexed. gcc/testsuite/ChangeLog: PR modula2/110865 * gm2/iso/pass/constvec.mod: New test. * gm2/iso/pass/constvec2.mod: New test. * gm2/iso/run/pass/constvec3.mod: New test. Signed-off-by: Gaius Mulley --- diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod index 44648deb49fc..031ee8947107 100644 --- a/gcc/m2/gm2-compiler/M2Quads.mod +++ b/gcc/m2/gm2-compiler/M2Quads.mod @@ -11169,29 +11169,30 @@ PROCEDURE BuildDesignatorArray ; VAR combinedTok, arrayTok, - exprTok : CARDINAL ; - e, t, d, + exprTok : CARDINAL ; + e, type, dim, + result, Sym, - Type : CARDINAL ; + Type : CARDINAL ; BEGIN - IF IsConst (OperandT (2)) AND IsConstructor (OperandT (2)) + IF IsConst (OperandT (2)) THEN - t := GetDType (OperandT (2)) ; - IF t = NulSym + type := GetDType (OperandT (2)) ; + IF type = NulSym THEN - InternalError ('constructor type should have been resolved') - ELSIF IsArray (t) + InternalError ('constant type should have been resolved') + ELSIF IsArray (type) THEN PopTtok (e, exprTok) ; - PopTFDtok (Sym, Type, d, arrayTok) ; - t := MakeTemporary (exprTok, RightValue) ; - PutVar (t, Type) ; - PushTFtok (t, GetSType(t), exprTok) ; + PopTFDtok (Sym, Type, dim, arrayTok) ; + result := MakeTemporary (exprTok, RightValue) ; + PutVar (result, Type) ; + PushTFtok (result, GetSType (result), exprTok) ; PushTtok (Sym, arrayTok) ; combinedTok := MakeVirtualTok (arrayTok, arrayTok, exprTok) ; - PutVarConst (t, TRUE) ; + PutVarConst (result, TRUE) ; BuildAssignConstant (combinedTok) ; - PushTFDtok (t, GetDType(t), d, arrayTok) ; + PushTFDtok (result, GetDType (result), dim, arrayTok) ; PushTtok (e, exprTok) END END ; diff --git a/gcc/testsuite/gm2/iso/pass/constvec.mod b/gcc/testsuite/gm2/iso/pass/constvec.mod new file mode 100644 index 000000000000..8f7e9b6c809f --- /dev/null +++ b/gcc/testsuite/gm2/iso/pass/constvec.mod @@ -0,0 +1,21 @@ +MODULE constvec ; + +TYPE + Vec5 = ARRAY [1..5] OF LONGREAL; + +CONST + con1 = Vec5 { 1.0, + 2.0, + 3.0, + 4.0, + 5.0 } ; + +CONST + con2 = con1 ; + +VAR + x: LONGREAL; +BEGIN + x := con1[3] ; + x := con2[3] +END constvec. diff --git a/gcc/testsuite/gm2/iso/pass/constvec2.mod b/gcc/testsuite/gm2/iso/pass/constvec2.mod new file mode 100644 index 000000000000..99b4cdf779bc --- /dev/null +++ b/gcc/testsuite/gm2/iso/pass/constvec2.mod @@ -0,0 +1,21 @@ +MODULE constvec2 ; + +CONST + con2 = con1 ; + +TYPE + Vec5 = ARRAY [1..5] OF LONGREAL; + +CONST + con1 = Vec5 { 1.0, + 2.0, + 3.0, + 4.0, + 5.0 } ; + +VAR + x: LONGREAL; +BEGIN + x := con1[3] ; + x := con2[3] +END constvec2. diff --git a/gcc/testsuite/gm2/iso/run/pass/constvec3.mod b/gcc/testsuite/gm2/iso/run/pass/constvec3.mod new file mode 100644 index 000000000000..3b773bde7327 --- /dev/null +++ b/gcc/testsuite/gm2/iso/run/pass/constvec3.mod @@ -0,0 +1,26 @@ +MODULE constvec3 ; + +FROM libc IMPORT exit ; + +CONST + con2 = con1 ; + +TYPE + Vec5 = ARRAY [1..5] OF INTEGER ; + +CONST + con1 = Vec5 { 100, + 200, + 300, + 400, + 500 } ; + +VAR + x: INTEGER ; +BEGIN + x := con1[3] ; + IF x # con2[1] + con2[2] + THEN + exit (1) + END +END constvec3.