Remove MR_INT_LEAST64_LENGTH_MODIFIER.

We had configure choose the format string length modifier for
MR_int_least64_t based on whether the type is an alias for "int",
"long", "long long" or "__int64". That does not work for some versions
of MinGW-w64, which warn about the "ll" length modifier even though
MR_int_least64_t is an alias for "long long". The reason is that
we would be calling the MSVC runtime *printf functions,
which require the "I64" length modifier instead of "ll".

The only place MR_INT_LEAST64_LENGTH_MODIFIER is used in the Mercury
system is in the hidden function float64_bits_string (which is also
no longer used by the Mercury compiler after the removal of the hl
grades). We can replace that use with PRIdLEAST64 from inttypes.h.

Users are unlikely to be using MR_INT_LEAST64_LENGTH_MODIFIER,
so it should be safe to remove it.

configure.ac:
runtime/mercury_conf.h.in:
    Don't define MR_INT_LEAST64_LENGTH_MODIFIER.

library/float.m:
    Replace use of MR_INT_LEAST64_LENGTH_MODIFIER with PRIdLEAST64
    in float64_bits_string.

    Mark all float32_bits_string and float64_bits_string foreign procs
    as 'may_not_export_body'. There is no need to opt-export procedures
    that will rarely be used, if ever.

runtime/mercury_types.h:
    Update comment.
This commit is contained in:
Peter Wang
2023-12-19 14:26:41 +11:00
parent 15181aa8c2
commit d7099e830a
4 changed files with 15 additions and 34 deletions

View File

@@ -1752,19 +1752,6 @@ if test "$mercury_cv_int_least64_type" != unknown; then
AC_DEFINE_UNQUOTED(MR_INT_LEAST64_TYPE, $mercury_cv_int_least64_type)
MR_INT_LEAST64_TYPE=$mercury_cv_int_least64_type
AC_SUBST(MR_INT_LEAST64_TYPE)
if test "$mercury_cv_int_least64_type" = int; then
AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "")
elif test "$mercury_cv_int_least64_type" = long; then
AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "l")
elif test "$mercury_cv_int_least64_type" = "long long"; then
AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "ll")
elif test "$mercury_cv_int_least64_type" = "__int64"; then
AC_DEFINE_UNQUOTED(MR_INT_LEAST64_LENGTH_MODIFIER, "I64")
else
AC_MSG_ERROR(Cannot determine the length modifier for the MR_int_least64_t type.)
fi
AC_SUBST(MR_INT_LEAST64_LENGTH_MODIFIER)
fi
#-----------------------------------------------------------------------------#

View File

@@ -348,12 +348,9 @@
:- import_module exception.
:- import_module int.
%
% Header files of mathematical significance.
%
:- pragma foreign_decl("C", "
#include <float.h>
#include <inttypes.h>
#include <math.h>
#ifdef MR_HAVE_IEEEFP_H
@@ -1166,7 +1163,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
:- pragma foreign_proc("C",
float32_bits_string(Flt::in) = (Str::uo),
[will_not_call_mercury, promise_pure, thread_safe],
[will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
"
union {
float f;
@@ -1181,7 +1178,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
:- pragma foreign_proc("Java",
float32_bits_string(Flt::in) = (Str::uo),
[will_not_call_mercury, promise_pure, thread_safe],
[will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
"
float f = (float) Flt;
int i = Float.floatToIntBits(f);
@@ -1190,7 +1187,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
:- pragma foreign_proc("C#",
float32_bits_string(Flt::in) = (Str::uo),
[will_not_call_mercury, promise_pure, thread_safe],
[will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
"
float f = (float) Flt;
int i = System.BitConverter.ToInt32(System.BitConverter.GetBytes(f), 0);
@@ -1199,7 +1196,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
:- pragma foreign_proc("C",
float64_bits_string(Flt::in) = (Str::uo),
[will_not_call_mercury, promise_pure, thread_safe],
[will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
"
#if defined(MR_INT_LEAST64_TYPE)
@@ -1210,7 +1207,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
char buf[64];
u.f = (double) Flt;
sprintf(buf, ""%"" MR_INT_LEAST64_LENGTH_MODIFIER ""d"", u.i);
sprintf(buf, ""%"" PRIdLEAST64, u.i);
MR_make_aligned_string_copy(Str, buf);
#else
MR_fatal_error(
@@ -1220,7 +1217,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
:- pragma foreign_proc("Java",
float64_bits_string(Flt::in) = (Str::uo),
[will_not_call_mercury, promise_pure, thread_safe],
[will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
"
double d = (double) Flt;
long i = Double.doubleToLongBits(d);
@@ -1229,7 +1226,7 @@ float_to_doc(F) = pretty_printer.float_to_doc(F).
:- pragma foreign_proc("C#",
float64_bits_string(Flt::in) = (Str::uo),
[will_not_call_mercury, promise_pure, thread_safe],
[will_not_call_mercury, promise_pure, thread_safe, may_not_export_body],
"
double d = (double) Flt;
long i = System.BitConverter.DoubleToInt64Bits(d);

View File

@@ -67,11 +67,6 @@
#undef MR_INT_LEAST64_TYPE
// MR_INT_LEAST64_LENGTH_MODIFIER: the print() length modifier for
// a MR_int_least64_t.
#undef MR_INT_LEAST64_LENGTH_MODIFIER
// MR_INT_LEAST32_TYPE:
// This must be a C integral type (e.g. short, int, long)
// without any explicit signedness.

View File

@@ -44,11 +44,13 @@
#endif
// This section defines types similar to C9X's <stdint.h> header.
// We do not use <stdint.h>, or the <inttypes.h> or <sys/types.h> files
// that substitute for it on some systems because (a) some such files
// do not define the types we need, and (b) some such files include
// inline function definitions. The latter is a problem because we want to
// reserve some real machine registers for Mercury abstract machine registers.
// Historically, we did not use <stdint.h>, or the <inttypes.h> or
// <sys/types.h> files that substitute for it on some systems because
// (a) some such files do not define the types we need, and
// (b) some such files include inline function definitions.
// While the former reason is very much out of date,
// the latter may still be a problem because we want to reserve some
// real machine registers for Mercury abstract machine registers.
// To be effective, the definitions of these global register variables
// must precede all function definitions, and we want to put their
// definitions after mercury_types.h.