From: Jakub Jelinek Date: Fri, 2 May 2025 17:10:59 +0000 (+0200) Subject: cobol: Fix up exception handling [PR119364] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=167f3663ccc7d0a5cf2a83e0c29461ca79841e99;p=thirdparty%2Fgcc.git cobol: Fix up exception handling [PR119364] The following patch on top of the https://gcc.gnu.org/pipermail/gcc-patches/2025-May/682500.html fixes most of the remaining make check-cobol FAILs in the i686-linux -> x86_64-linux cross-compiler. Using the testing environment detailed in https://gcc.gnu.org/pipermail/gcc-patches/2025-April/680403.html with this patch I get just cobol.dg/group1/declarative_1.cob FAILs in i686-linux -> x86_64-linux cross and no FAILs in x86_64-linux native one. The patch isn't needed just for cross-compilation with different hosts, but also on x86_64-linux/aarch64-linux native, because without it the FE is hashing padding bits which contain random garbage and making code generation decisions based on that. That is very much against the reproduceability requirements. 2025-05-02 Jakub Jelinek PR cobol/119364 * structs.h (cbl_enabled_exception_type_node): New variable declaration. * structs.cc (cbl_enabled_exception_type_node): New variable. (create_cbl_enabled_exception_t): New function. (create_our_type_nodes): Initialize cbl_enabled_exception_type_node using it. * genapi.cc (stash_exceptions): Don't compare padding bits to determine if the exceptions are the same as last time. Use cbl_enabled_exception_type_node for target size and field offsets and native_encode_expr to write each field into byte sequence. (cherry picked from commit c77d04506e6abdc45969d0ff146204be7485244a) --- diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc index eba10b0bdfe..dca52ce080d 100644 --- a/gcc/cobol/genapi.cc +++ b/gcc/cobol/genapi.cc @@ -13301,24 +13301,29 @@ static void stash_exceptions( const cbl_enabled_exceptions_array_t *enabled ) { // We need to create a static array of bytes - size_t narg = enabled->nbytes(); - unsigned char *p = (unsigned char *)(enabled->ecs); + size_t nec = enabled->nec; + size_t sz = int_size_in_bytes(cbl_enabled_exception_type_node); + size_t narg = nec * sz; + cbl_enabled_exception_t *p = enabled->ecs; - static size_t prior_narg = 0; - static size_t max_narg = 128; - static unsigned char *prior_p = (unsigned char *)xmalloc(max_narg); + static size_t prior_nec = 0; + static size_t max_nec = 0; + static cbl_enabled_exception_t *prior_p; bool we_got_new_data = false; - if( prior_narg != narg ) + if( prior_nec != nec ) { we_got_new_data = true; } else { - // The narg counts are the same. - for(size_t i=0; i max_narg ) + if( nec > max_nec ) { - max_narg = narg; - prior_p = (unsigned char *)xrealloc(prior_p, max_narg); + max_nec = nec; + prior_p = (cbl_enabled_exception_t *) + xrealloc(prior_p, max_nec * sizeof(cbl_enabled_exception_t)); } - memcpy(prior_p, p, narg); + memcpy((unsigned char *)prior_p, (unsigned char *)p, + nec * sizeof(cbl_enabled_exception_t)); static int count = 1; @@ -13355,12 +13362,33 @@ stash_exceptions( const cbl_enabled_exceptions_array_t *enabled ) TREE_TYPE(constr) = array_of_chars_type; TREE_STATIC(constr) = 1; TREE_CONSTANT(constr) = 1; - - for(size_t i=0; i