https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66311
Mikael Morin <mikael at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mikael at gcc dot gnu.org --- Comment #7 from Mikael Morin <mikael at gcc dot gnu.org> --- (In reply to Francois-Xavier Coudert from comment #6) > I tracked the issue to the two calls to wi::from_mpz() and > wide_int_to_tree() in gcc/fortran/trans-const.c:gfc_conv_mpz_to_tree(). > There the mpz value (which is correct) in translated into: > > wide_int_storage = { > val = ([0] = -2, [1] = 0, [2] = 56) > len = 1 > precision = 128 > } > > which appears to be where the -2 comes from. And in wi::from_mpz it probably comes from the mpz_sizeinbytes and mpz_export functions not paying attention to the sign, as stated in the documentation: https://gmplib.org/manual/Integer-Import-and-Export.html > The sign of op is ignored, just the absolute value is exported. An application > can use mpz_sgn to get the sign and handle it as desired. (see Integer > Comparisons) https://gmplib.org/manual/Miscellaneous-Integer-Functions.html#Miscellaneous-Integer-Functions > The sign of op is ignored, just the absolute value is used.