]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Further fixes for cobol cross-compilation from 32-bit arches [PR119364]
authorJakub Jelinek <jakub@redhat.com>
Tue, 8 Apr 2025 13:57:45 +0000 (15:57 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 8 Apr 2025 13:57:45 +0000 (15:57 +0200)
On top of
https://gcc.gnu.org/pipermail/gcc-patches/2025-April/680256.html
patch this brings make check-cobol when using the cross compiler from
32-bit host to x86_64-linux to the following:
  Running /home/jakub/src/gcc/gcc/testsuite/cobol.dg/dg.exp ...
  FAIL: cobol.dg/group1/declarative_1.cob   -O0  execution test
  FAIL: cobol.dg/group1/declarative_1.cob   -O1  execution test
  FAIL: cobol.dg/group1/declarative_1.cob   -O2  execution test
  FAIL: cobol.dg/group1/declarative_1.cob   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  execution test
  FAIL: cobol.dg/group1/declarative_1.cob   -O3 -g  execution test
  FAIL: cobol.dg/group1/declarative_1.cob   -Os  execution test

                  === cobol Summary ===

  # of expected passes            3123
  # of unexpected failures        6
  # of expected failures          6
(which has some analysis but not a fix yet).

This patch fixes various cases where host size of various types
(void *, int, size_t, unsigned char) is used in place where
size of those types in bytes on the target should be used instead.
At least the size of void * and size_t actually differns between
ilp32 hosts and lp64 targets, int could be different in theory as well
but we actually don't support 16-bit ints on the host side and only support
lp64 targets right now for cobol, and finally sizeof(unsigned char) is
always 1, so there is no point to multiply by that and it is still
wrong to use host sizeof for the target decisions.

2025-04-08  Jakub Jelinek  <jakub@redhat.com>

PR cobol/119364
* genapi.cc (function_handle_from_name): Use sizeof_pointer.
(parser_file_add): Use int_size_in_bytes(VOID_P) and
int_size_in_bytes(int).
(inspect_tally): Use int_size_in_bytes(VOID_P).
(inspect_replacing): Likewise.
(gg_array_of_field_pointers): Likewise.
(gg_array_of_file_pointers): Likewise.
(parser_set_pointers): Use sizeof_pointer.
* cobol1.cc (create_our_type_nodes_init): Use
int_size_in_bytes(SIZE_T) and int_size_in_bytes(VOID_P).
* gengen.cc (gg_array_of_size_t): Use int_size_in_bytes(SIZE_T).
(gg_array_of_bytes): Just use N, don't multiply it by
sizeof(unsigned char).
* parse.y: Include tree.h.  Use int_size_in_bytes(ptr_type_node).

gcc/cobol/cobol1.cc
gcc/cobol/genapi.cc
gcc/cobol/gengen.cc
gcc/cobol/parse.y

index 0d07c460d4161172e6fb98b9c26a7c2cfdd1b295..1e690ff4ba54772a6832876770ced771606febdc 100644 (file)
@@ -166,8 +166,8 @@ create_our_type_nodes_init()
   long_double_ten_node = build_real_from_int_cst(
                            LONGDOUBLE,
                            build_int_cst_type(INT,10));
-  sizeof_size_t  = build_int_cst_type(SIZE_T, sizeof(size_t));
-  sizeof_pointer = build_int_cst_type(SIZE_T, sizeof(void *));
+  sizeof_size_t  = build_int_cst_type(SIZE_T, int_size_in_bytes(SIZE_T));
+  sizeof_pointer = build_int_cst_type(SIZE_T, int_size_in_bytes(VOID_P));
 
   bool_true_node = build2(EQ_EXPR,
                           integer_type_node,
index fbe0bbc75dc831b87231efbaeed2dc7bcc4752b8..c91237bd8d2c44e1eb8961fc2cbca974bd174cca 100644 (file)
@@ -787,13 +787,13 @@ function_handle_from_name(cbl_refer_t &name,
       {
       gg_memcpy(gg_get_address_of(function_handle),
                 member(name.field->var_decl_node, "data"),
-                build_int_cst_type(SIZE_T, sizeof(void *)));
+                sizeof_pointer);
       }
     else
       {
       gg_memcpy(gg_get_address_of(function_handle),
                 qualified_data_source(name),
-                build_int_cst_type(SIZE_T, sizeof(void *)));
+                sizeof_pointer);
       }
     return function_handle;
     }
@@ -8917,8 +8917,8 @@ parser_file_add(struct cbl_file_t *file)
   gg_assign(array_of_keys,
             gg_cast(build_pointer_type(cblc_field_p_type_node),
                     gg_malloc(build_int_cst_type(SIZE_T,
-                                                (number_of_key_fields+1)
-                                                            *sizeof(void *)))));
+                                                 (number_of_key_fields+1)
+                                                 *int_size_in_bytes(VOID_P)))));
 
   strcpy(achName, "_");
   strcat(achName, file->name);
@@ -8929,8 +8929,8 @@ parser_file_add(struct cbl_file_t *file)
   gg_assign(key_numbers,
             gg_cast(build_pointer_type(INT),
                     gg_malloc(build_int_cst_type(SIZE_T,
-                                                (number_of_key_fields+1)
-                                                            *sizeof(int)))));
+                                                 (number_of_key_fields+1)
+                                                            *int_size_in_bytes(INT)))));
 
   strcpy(achName, "_");
   strcat(achName, file->name);
@@ -8942,7 +8942,7 @@ parser_file_add(struct cbl_file_t *file)
             gg_cast(build_pointer_type(INT),
                     gg_malloc(build_int_cst_type(SIZE_T,
                                                 (number_of_key_fields+1)
-                                                            *sizeof(int)))));
+                                                            *int_size_in_bytes(INT)))));
 
   size_t index = 0;
   for( size_t i=0; i<file->nkey; i++ )
@@ -9686,7 +9686,9 @@ inspect_tally(bool backward,
     gg_assign(int_size, build_int_cst_type(INT, n_integers));
     gg_assign(integers,
               gg_cast(SIZE_T_P,
-                      gg_realloc(integers, n_integers * sizeof(void *))));
+                      gg_realloc(integers,
+                                 n_integers
+                                 * int_size_in_bytes(VOID_P))));
     }
   ELSE
     {
@@ -9837,7 +9839,9 @@ inspect_replacing(int backward,
     gg_assign(int_size, build_int_cst_type(INT, n_integers));
     gg_assign(integers,
               gg_cast(SIZE_T_P,
-                      gg_realloc(integers, n_integers * sizeof(void *))));
+                      gg_realloc(integers,
+                                 n_integers
+                                 * int_size_in_bytes(VOID_P))));
     }
   ELSE
     {
@@ -11074,7 +11078,9 @@ gg_array_of_field_pointers( size_t N,
                             cbl_field_t **fields )
   {
   tree retval = gg_define_variable(build_pointer_type(cblc_field_p_type_node));
-  gg_assign(retval, gg_cast(build_pointer_type(cblc_field_p_type_node), gg_malloc(  build_int_cst_type(SIZE_T, N * sizeof(void *)))));
+  gg_assign(retval, gg_cast(build_pointer_type(cblc_field_p_type_node),
+                            gg_malloc(build_int_cst_type(SIZE_T,
+                                                         N * int_size_in_bytes(VOID_P)))));
   for(size_t i=0; i<N; i++)
     {
     gg_assign(gg_array_value(retval, i), gg_get_address_of(fields[i]->var_decl_node));
@@ -11566,7 +11572,8 @@ gg_array_of_file_pointers(  size_t N,
   {
   tree retval = gg_define_variable(build_pointer_type(cblc_file_p_type_node));
   gg_assign(retval, gg_cast(  build_pointer_type(cblc_file_p_type_node),
-                              gg_malloc(  build_int_cst_type(SIZE_T, N * sizeof(void *)))));
+                              gg_malloc(  build_int_cst_type(SIZE_T,
+                                                             N * int_size_in_bytes(VOID_P)))));
   for(size_t i=0; i<N; i++)
     {
     gg_assign(gg_array_value(retval, i), gg_get_address_of(files[i]->var_decl_node));
@@ -12853,7 +12860,7 @@ parser_set_pointers( size_t ntgt, cbl_refer_t *tgts, cbl_refer_t source )
                                                    COBOL_FUNCTION_RETURN_TYPE);
       gg_memcpy(qualified_data_dest(tgts[i]),
                 gg_get_address_of(function_handle),
-                build_int_cst_type(SIZE_T, sizeof(void *)));
+                sizeof_pointer);
       }
     else
       {
index e7a4e3c51653a95341084fe753816723859dfc61..f182f7f9cd5e84df625ac3088eb582008836964b 100644 (file)
@@ -3355,7 +3355,8 @@ tree
 gg_array_of_size_t( size_t N, size_t *values)
   {
   tree retval = gg_define_variable(build_pointer_type(SIZE_T));
-  gg_assign(retval, gg_cast(build_pointer_type(SIZE_T), gg_malloc(  build_int_cst_type(SIZE_T, N * sizeof(size_t)))));
+  tree sz = build_int_cst_type(SIZE_T, N * int_size_in_bytes(SIZE_T));
+  gg_assign(retval, gg_cast(build_pointer_type(SIZE_T), gg_malloc(sz)));
   for(size_t i=0; i<N; i++)
     {
     gg_assign(gg_array_value(retval, i), build_int_cst_type(SIZE_T, values[i]));
@@ -3367,7 +3368,7 @@ tree
 gg_array_of_bytes( size_t N, unsigned char *values)
   {
   tree retval = gg_define_variable(UCHAR_P);
-  gg_assign(retval, gg_cast(UCHAR_P, gg_malloc(  build_int_cst_type(SIZE_T, N * sizeof(unsigned char)))));
+  gg_assign(retval, gg_cast(UCHAR_P, gg_malloc(  build_int_cst_type(SIZE_T, N))));
   for(size_t i=0; i<N; i++)
     {
     gg_assign(gg_array_value(retval, i), build_int_cst_type(UCHAR, values[i]));
index 3f282013a4ab997de05d170b7924a9424342e1ee..61ffa7cc00d71a0fa7ee0917934b80cd2b2c053c 100644 (file)
@@ -33,6 +33,7 @@
   #include "coretypes.h"
   #include "../../libgcobol/io.h"
   #include "../../libgcobol/ec.h"
+  #include "tree.h"
 
 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
 
@@ -3822,7 +3823,8 @@ data_clauses:   data_clause
                         if( yydebug ) {
                           yywarn("expanding %s size from %u bytes to %zu "
                                 "because it redefines %s with USAGE POINTER",
-                                field->name, field->size(), sizeof(void*),
+                                field->name, field->size(),
+                                (size_t)int_size_in_bytes(ptr_type_node),
                                 redefined->name);
                         }
                         field->embiggen();
@@ -4282,7 +4284,7 @@ usage_clause1:  usage COMPUTATIONAL[comp]   native
                   if( gcobol_feature_embiggen() && redefined &&
                       is_numeric(redefined->type) && redefined->size() == 4) {
                     // For now, we allow POINTER to expand a 32-bit item to 64 bits.
-                    field->data.capacity = sizeof(void *);
+                    field->data.capacity = int_size_in_bytes(ptr_type_node);
                     dbgmsg("%s: expanding #%zu %s capacity %u => %u", __func__,
                           field_index(redefined), redefined->name,
                           redefined->data.capacity, field->data.capacity);