aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2023-08-01 01:42:16 +0100
committerGaius Mulley <gaiusmod2@gmail.com>2023-08-01 01:42:16 +0100
commit8a47474f2cf48837d6adf4a1232a89fd398ca7fa (patch)
tree317ed728033c318f859a1a2b8e0bb7dd8815e1c6 /gcc
parenta2f31d79ad623de6809b3cf2055483525f1903ab (diff)
downloadgcc-8a47474f2cf48837d6adf4a1232a89fd398ca7fa.zip
gcc-8a47474f2cf48837d6adf4a1232a89fd398ca7fa.tar.gz
gcc-8a47474f2cf48837d6adf4a1232a89fd398ca7fa.tar.bz2
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 <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/m2/gm2-compiler/M2Quads.mod29
-rw-r--r--gcc/testsuite/gm2/iso/pass/constvec.mod21
-rw-r--r--gcc/testsuite/gm2/iso/pass/constvec2.mod21
-rw-r--r--gcc/testsuite/gm2/iso/run/pass/constvec3.mod26
4 files changed, 83 insertions, 14 deletions
diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 44648de..031ee89 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 0000000..8f7e9b6
--- /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 0000000..99b4cdf
--- /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 0000000..3b773bd
--- /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.