[m-rev.] for review:

Julien Fischer jfischer at opturion.com
Fri Jan 27 16:27:42 AEDT 2023


For review by anyone.

A couple of notes about this:

1. Some of the existing documentation in compiler/format_call.m looks
dodgy. I will update it separately.

2. Some further integer casts need to be added to the standard library.
I will also do that separately.

----------------------------

Fix a bug in string.format.

The current implementation of the unsigned conversion specifiers (i.e. %x, %X,
%o, %u) for fixed-size 8-, 16- and 32-bit signed integers works by casting
theses values into (word-sized) ints and then using the existing code for
formatting ints as unsigned values. This does not work for negative values as
they are being sign extended when converted to ints. For example,

       io.format("%x", [i8(min_int8)], !IO)

prints:

       ffffffffffffff80 (on a 64-bit machine)

rather than just:

       80

Fix the above problem by casting ints, int8s, int16s etc. that are being
formatted as unsigned values to uints and using the uint formatting code.

NOTE: the formatting code for 64-bit integers follows a different code path
and is not affected by any of this.

library/string.format.m:
     Implement unsigned conversion specifiers for non-64-bit signed
     integers by casting to uint and using the uint formatting code.

     Add predicates for converting signed integers into uints.

     The format_unsigned_int_* predicates can be deleted after this change
     is installed.

compiler/format_call.m:
     Implement unsigned conversion specifiers for non-64-bit signed
     integers by casting to uint and using the uint formatting code.

compiler/introduced_call_table.m:
     Update the table of introduced predicates.

compiler/options.m:
     Add an option that can be used to test whether this fix is
     installed.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/opt_format_sign_extend.{m,exp}:
     Test that formatting code introduced by the compiler does not
     accidentally sign-extend negative values.

tests/string_format/string_format_{o,x,u}.{m,exp,exp2}:
     Make these tests much more comprehensive then they previously
     were.

Julien.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.fmt_sign_extend.gz
Type: application/gzip
Size: 326419 bytes
Desc: 
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20230127/10aa9198/attachment-0001.gz>


More information about the reviews mailing list