diff options
author | Jakub Jelinek <jakub@redhat.com> | 2025-04-08 15:57:45 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2025-04-08 15:57:45 +0200 |
commit | 1b5b02be5740b69f670b1591ac63eb6a69ff1f79 (patch) | |
tree | 351de1d803d5ff357f5a2ab7fb6efec982834ec5 /gcc | |
parent | 04918a2d3f20b02ac3efad1096c33894d57789a0 (diff) | |
download | gcc-1b5b02be5740b69f670b1591ac63eb6a69ff1f79.zip gcc-1b5b02be5740b69f670b1591ac63eb6a69ff1f79.tar.gz gcc-1b5b02be5740b69f670b1591ac63eb6a69ff1f79.tar.bz2 |
cobol: Further fixes for cobol cross-compilation from 32-bit arches [PR119364]
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).
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cobol/cobol1.cc | 4 | ||||
-rw-r--r-- | gcc/cobol/genapi.cc | 31 | ||||
-rw-r--r-- | gcc/cobol/gengen.cc | 5 | ||||
-rw-r--r-- | gcc/cobol/parse.y | 6 |
4 files changed, 28 insertions, 18 deletions
diff --git a/gcc/cobol/cobol1.cc b/gcc/cobol/cobol1.cc index 0d07c46..1e690ff 100644 --- a/gcc/cobol/cobol1.cc +++ b/gcc/cobol/cobol1.cc @@ -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, diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index fbe0bbc..c91237b 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -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 { diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc index e7a4e3c..f182f7f 100644 --- a/gcc/cobol/gengen.cc +++ b/gcc/cobol/gengen.cc @@ -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])); diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 3f28201..61ffa7c 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -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); |