public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2892] PR modula2/110865 Unable to access copied const array
@ 2023-08-01  0:43 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2023-08-01  0:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8a47474f2cf48837d6adf4a1232a89fd398ca7fa

commit r14-2892-g8a47474f2cf48837d6adf4a1232a89fd398ca7fa
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Tue Aug 1 01:42:16 2023 +0100

    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>

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod              | 29 ++++++++++++++--------------
 gcc/testsuite/gm2/iso/pass/constvec.mod      | 21 ++++++++++++++++++++
 gcc/testsuite/gm2/iso/pass/constvec2.mod     | 21 ++++++++++++++++++++
 gcc/testsuite/gm2/iso/run/pass/constvec3.mod | 26 +++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 14 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 44648deb49f..031ee894710 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 00000000000..8f7e9b6c809
--- /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 00000000000..99b4cdf779b
--- /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 00000000000..3b773bde732
--- /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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-01  0:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-01  0:43 [gcc r14-2892] PR modula2/110865 Unable to access copied const array Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).