On Sun, Mar 23, 2025 at 08:28:47PM -0500, Robert Dubner wrote: > Jim is back from a short COBOL-related business trip. I am going to take > this working collection of patched patched patches and put it up where he > can get at it. > > That location is the float_to_tree branch of > > https://gitlab.cobolworx.com/COBOLworx/gcc-cobol.git > > And we'll review it. We want to make sure that these changes don't do any > damage that might be hidden because there are no tests for some things > that nonetheless might be visible to us when we look at it. > > So, with the understanding that this is still pending internal Jim & Bob > review, I am putting the probable patch here:
So, first of all, you'll need a ChangeLog entry for this. Here is a proposal for that. * gcobolspec.cc (lang_specific_driver): Formatting fix. * genapi.cc: Include fold-const.h and realmpfr.h. (initialize_variable_internal): Use real_to_decimal instead of strfromf128. (get_binary_value_from_float): Use wide_int_to_tree instead of build_int_cst_type. (psa_FldLiteralN): Use fold_convert instead of strfromf128, real_from_string and build_real. (parser_display_internal): Rewritten to work on REAL_VALUE_TYPE rather than _Float128. (mh_source_is_literalN): Use FIXED_WIDE_INT(128) rather than __int128, wide_int_to_tree rather than build_int_cst_type, fold_convert rather than build_string_literal. (real_powi10): New function. (binary_initial_from_float128): Change type of last argument from _Float128 to REAL_VALUE_TYPE, process it using real.cc and mpfr APIs. (digits_from_float128): Likewise. (initial_from_float128): Make static. Remove value argument, add local REAL_VALUE_TYPE value variable instead, process it using real.cc and native_encode_expr APIs. (parser_symbol_add): Adjust initial_from_float128 caller. * genapi.h (initial_from_float128): Remove declaration. * genutil.cc (get_power_of_ten): Change return type from __int128 to FIXED_WIDE_INT(128), ditto for retval type, change type of pos from __int128 to unsigned long long. (scale_by_power_of_ten_N): Use wide_int_to_tree instead of build_int_cst_type. Use FIXED_WIDE_INT(128) instead of __int128 as power_of_ten variable type. (copy_little_endian_into_place): Likewise. * genutil.h (get_power_of_ten): Change return type from __int128 to FIXED_WIDE_INT(128). (FIXED_WIDE_INT): * parse.y (%union): Change type of float128 from _Float128 to REAL_VALUE_TYPE. (string_of): Change argument type from _Float128 to const REAL_VALUE_TYPE &, use real_to_decimal rather than strfromf128. Add another overload with tree argument type. (field: cdf): Use real_zerop rather than comparison against 0.0. (occurs_clause, const_value): Use real_to_integer. (value78): Use build_real and real_to_integer. (data_descr1): Use real_to_integer. (count): Use real_to_integer, real_from_integer and real_identical instead of direct comparison. (value_clause): Use real_from_string3 instead of num_str2i. Use real_identical instead of direct comparison. Use build_real. (allocate): Use real_isneg and real_iszero instead of <= 0 comparison. (move_tgt): Use real_to_integer, real_value_truncate, real_from_integer and real_identical instead of comparison of casts. (cce_expr): Use real_arithmetic and real_convert or real_value_negate instead of direct arithmetics on _Float128. (cce_factor): Use real_from_string3 instead of numstr2i. (literal_refmod_valid): Use real_to_integer. * symbols.cc (symbol_table_t::registers_t::registers_t): Formatting fix. (ERROR_FIELD): Likewise. (extend_66_capacity): Likewise. (cbl_occurs_t::subscript_ok): Use real_to_integer, real_from_integer and real_identical. * symbols.h (cbl_field_data_t::etc_t::value): Change type from _Float128 to tree. (cbl_field_data_t::etc_t::etc_t): Adjust defaulted argument value. (cbl_field_data_t::cbl_field_data_t): Formatting fix. Use etc() rather than etc(0). (cbl_field_data_t::value_of): Change return type from _Float128 to tree. (cbl_field_data_t::operator=): Change return and argument type from _Float128 to tree. (cbl_field_data_t::valify): Use real_from_string, real_value_truncate and build_real. (cbl_field_t::same_as): Use build_zero_cst instead of _Float128(0.0). Co-authored-by: Richard Biener <rgue...@suse.de> Co-authored-by: Jakub Jelinek <ja...@redhat.com> Some functions etc. changed only in formatting (marked Formatting fix above in the proposed ChangeLog), the question is if you want those changes or drop them (and in that case drop from ChangeLog as well). > diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc > index ffb64c8993d9..98894f2e24ae 100644 > --- a/gcc/cobol/gengen.cc > +++ b/gcc/cobol/gengen.cc > @@ -915,7 +915,7 @@ gg_declare_variable(tree type_decl, > // Be it hereby known that the various attributes associated with a > var_decl, > // things like TREE_PUBLIC and TREE_STATIC and TREE_CONST seem to line > up with > // their meanings in the C language. But I haven't investigated it > enough to > - // be completely sure about that. A hard look at gcc/tree.h is on my > list of > + // be completely sure about that. A hard look at gcc ree.h is > on my list of > // homework assignments. In the meantime, I continue to learn by > compiling > // C programs with the fdump-generic-nodes option, and copying them as > // necessary to accomplish specific tasks. This hunk seems bogus, /t changed into a tab character, this should be dropped from the patch. > @@ -358,12 +358,17 @@ struct cbl_field_data_t { > > char *pend = NULL; > > - etc.value = strtof128(input.c_str(), &pend); > + strtof128(input.c_str(), &pend); > > if( pend != input.c_str() + len ) { > dbgmsg("%s: error: could not interpret '%s' of '%s' as a number", > __func__, pend, initial); > } > + > + REAL_VALUE_TYPE r; > + real_from_string (&r, input.c_str()); > + r = real_value_truncate (TYPE_MODE (float128_type_node), r); > + etc.value = build_real (float128_type_node, r); > return *this; > } > cbl_field_data_t& valify( const char *input ) { This hunk still leaves around strtof128 call (just to find out where it ends and emit diagnostics). I guess it can be handled incrementally. Perhaps using mpfr_strtofr, that one has the end argument as well. We need to look for remaining _Float128 and __int128 uses afterwards anyway. > --- a/libgcobol/libgcobol.h > +++ b/libgcobol/libgcobol.h > @@ -50,7 +50,7 @@ > #define ON_SIZE_ERROR 0x01 > #define REMAINDER_PRESENT 0x02 > > -/* 'offset' is overloaded for FldAlphanumeric/temporary/intermediate > variables > +/* 'offset' is overloaded for FldAlphanumeric > emporary/intermediate variables > * For such variables, offset is a copy of the initial capacity. This > is in > * support of the FUNCTION TRIM function, which both needs to be able to > * reduce the capacity of the target variable, and then to reset it back > to And this hunk doesn't belong to the commit either, again /t change to tab character. Jakub