https://gcc.gnu.org/g:62abe069506e67d2668e8de7c5e00c118c60d8a7

commit r15-7279-g62abe069506e67d2668e8de7c5e00c118c60d8a7
Author: Gaius Mulley <gaiusm...@gmail.com>
Date:   Wed Jan 29 20:32:07 2025 +0000

    PR modula2/116073 invalid rtl sharing compiling FileSystem.mod caused by 
ext-dce
    
    The bug fixes to PR modula2/118010 and PR modula2/118183 uncovered a bug
    in the procedure interface to lseek which uses SYSTEM.COFF_T rather than
    SYSTEM.CSSIZE_T.  This patch sets the default size for COFF_T to the same
    as CSSIZE_T.
    
    gcc/ChangeLog:
            PR modula2/118010
            PR modula2/118183
            PR modula2/116073
            * doc/gm2.texi (-fm2-file-offset-bits=): Change the default size
            description to CSSIZE_T.
            Add COFF_T to the list of data types exported by SYSTEM.def.
    
    gcc/m2/ChangeLog:
            PR modula2/118010
            PR modula2/118183
            PR modula2/116073
            * gm2-compiler/M2Options.mod (OffTBits): Assign to 0.
            * gm2-gcc/m2type.cc (build_m2_specific_size_type): Ensure that
            layout_type is called before returning c.
            (build_m2_offt_type_node): If GetFileOffsetBits returns 0 then
            use the type size of ssize_t.
    
    gcc/testsuite/ChangeLog:
    
            PR modula2/118010
            PR modula2/118183
            PR modula2/116073
            * gm2/pim/run/pass/printtypesize.mod: New test.
    
    Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>

Diff:
---
 gcc/doc/gm2.texi                                 | 14 +++++++++-----
 gcc/m2/gm2-compiler/M2Options.mod                |  2 +-
 gcc/m2/gm2-gcc/m2type.cc                         |  8 ++++++--
 gcc/testsuite/gm2/pim/run/pass/printtypesize.mod | 15 +++++++++++++++
 4 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index 5af8b228831f..f8ae148b99ba 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -502,7 +502,8 @@ the previous forms could be:
 
 @item -fm2-file-offset-bits=
 force the type @code{SYSTEM.COFF_T} to be built using the specified
-number of bits.  If this option is not used then default is 64 bits.
+number of bits.  If this option is not used then default is
+@code{CSSIZE_T} bits.
 
 @item -fm2-g
 improve the debugging experience for new programmers at the expense
@@ -2895,10 +2896,13 @@ base module).  PIM-2 defined @code{SIZE} in the 
@code{SYSTEM} module
 GNU Modula-2 allows users to specify the dialect of Modula-2 by using
 the @code{-fiso} and @code{-fpim2} command line switches.
 
-The data types @code{CSIZE_T} and @code{CSSIZE_T} are also exported from
-the @code{SYSTEM} module.  The type @code{CSIZE_T} is unsigned and is
-mapped onto the target C data type @code{size_t} whereas the type
-@code{CSSIZE_T} is mapped onto the signed C data type @code{ssize_t}.
+The data types @code{CSIZE_T}, @code{CSSIZE_T} and @code{COFF_T} are
+also exported from the @code{SYSTEM} module.  The type @code{CSIZE_T}
+is unsigned and is mapped onto the target C data type @code{size_t}
+whereas the type @code{CSSIZE_T} is mapped onto the signed C data type
+@code{ssize_t}.  The default size for the signed type @code{COFF_T} is
+the same as @code{CSSIZE_T} and this can be overridden by the
+@code{-fm2-file-offset-bits=} command line option.
 
 It is anticipated that these should only be used to provide cross
 platform definition modules for C libraries.
diff --git a/gcc/m2/gm2-compiler/M2Options.mod 
b/gcc/m2/gm2-compiler/M2Options.mod
index 4c03dfeddfba..39f0b2a73fb2 100644
--- a/gcc/m2/gm2-compiler/M2Options.mod
+++ b/gcc/m2/gm2-compiler/M2Options.mod
@@ -2147,5 +2147,5 @@ BEGIN
    M2Dump                            := NIL ;
    M2DumpFilter                      := NIL ;
    EnableForward                     := TRUE ;
-   OffTBits                          := 64 ;  (* Default to 64bit OFF_T.  *)
+   OffTBits                          := 0 ;  (* Default to CSSIZE_T.  *)
 END M2Options.
diff --git a/gcc/m2/gm2-gcc/m2type.cc b/gcc/m2/gm2-gcc/m2type.cc
index 9f7a433e9806..a946509d1c25 100644
--- a/gcc/m2/gm2-gcc/m2type.cc
+++ b/gcc/m2/gm2-gcc/m2type.cc
@@ -1077,7 +1077,6 @@ build_m2_specific_size_type (location_t location, enum 
tree_code base,
     {
       if (!float_mode_for_size (TYPE_PRECISION (c)).exists ())
         return NULL;
-      layout_type (c);
     }
   else if (base == SET_TYPE)
     return build_m2_size_set_type (location, precision);
@@ -1096,6 +1095,7 @@ build_m2_specific_size_type (location_t location, enum 
tree_code base,
           TYPE_UNSIGNED (c) = true;
         }
     }
+  layout_type (c);
   return c;
 }
 
@@ -1385,8 +1385,12 @@ static tree
 build_m2_offt_type_node (location_t location)
 {
   m2assert_AssertLocation (location);
+  int offt_size = M2Options_GetFileOffsetBits ();
+
+  if (offt_size == 0)
+    offt_size = TREE_INT_CST_LOW (TYPE_SIZE (ssizetype));
   return build_m2_specific_size_type (location, INTEGER_TYPE,
-                                     M2Options_GetFileOffsetBits (), true);
+                                     offt_size, true);
 }
 
 /* m2type_InitSystemTypes initialise loc and word derivatives.  */
diff --git a/gcc/testsuite/gm2/pim/run/pass/printtypesize.mod 
b/gcc/testsuite/gm2/pim/run/pass/printtypesize.mod
new file mode 100644
index 000000000000..690c4c187847
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/run/pass/printtypesize.mod
@@ -0,0 +1,15 @@
+MODULE printtypesize ;  
+
+FROM libc IMPORT printf ;
+FROM SYSTEM IMPORT SIZE, CSIZE_T, COFF_T ;
+
+BEGIN
+   printf ("SIZE (CHAR) = %d bytes\n", SIZE (CHAR));
+   printf ("SIZE (INTEGER) = %d bytes\n", SIZE (INTEGER));
+   printf ("SIZE (CARDINAL) = %d bytes\n", SIZE (CARDINAL));
+   printf ("SIZE (BITSET) = %d bytes\n", SIZE (BITSET));
+   printf ("SIZE (LONGINT) = %d bytes\n", SIZE (LONGINT));
+   printf ("SIZE (LONGCARD) = %d bytes\n", SIZE (LONGCARD));
+   printf ("SIZE (CSIZE_T) = %d bytes\n", SIZE (CSIZE_T));
+   printf ("SIZE (COFF_T) = %d bytes\n", SIZE (COFF_T));   
+END printtypesize.

Reply via email to