]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/110865 Unable to access copied const array
authorGaius Mulley <gaiusmod2@gmail.com>
Tue, 1 Aug 2023 00:42:16 +0000 (01:42 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Tue, 1 Aug 2023 00:42:16 +0000 (01:42 +0100)
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>
gcc/m2/gm2-compiler/M2Quads.mod
gcc/testsuite/gm2/iso/pass/constvec.mod [new file with mode: 0644]
gcc/testsuite/gm2/iso/pass/constvec2.mod [new file with mode: 0644]
gcc/testsuite/gm2/iso/run/pass/constvec3.mod [new file with mode: 0644]

index 44648deb49fcd856a53c9c3fdabc80692d9a9edc..031ee8947107c7b340aab840b21d536ebee6a3cc 100644 (file)
@@ -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 (file)
index 0000000..8f7e9b6
--- /dev/null
@@ -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 (file)
index 0000000..99b4cdf
--- /dev/null
@@ -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 (file)
index 0000000..3b773bd
--- /dev/null
@@ -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.