From d7099e830af6779a3d1141dba3fe530468da2c9c Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Tue, 19 Dec 2023 14:26:41 +1100 Subject: [PATCH] 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. --- configure.ac | 13 ------------- library/float.m | 19 ++++++++----------- runtime/mercury_conf.h.in | 5 ----- runtime/mercury_types.h | 12 +++++++----- 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/configure.ac b/configure.ac index 7f0c3b98a..bd1260b2a 100644 --- a/configure.ac +++ b/configure.ac @@ -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 #-----------------------------------------------------------------------------# diff --git a/library/float.m b/library/float.m index 72dabff96..bd0bd383b 100644 --- a/library/float.m +++ b/library/float.m @@ -348,12 +348,9 @@ :- import_module exception. :- import_module int. -% -% Header files of mathematical significance. -% - :- pragma foreign_decl("C", " #include + #include #include #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); diff --git a/runtime/mercury_conf.h.in b/runtime/mercury_conf.h.in index b847ffce1..168f9bcc5 100644 --- a/runtime/mercury_conf.h.in +++ b/runtime/mercury_conf.h.in @@ -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. diff --git a/runtime/mercury_types.h b/runtime/mercury_types.h index 11085e550..85ae23c91 100644 --- a/runtime/mercury_types.h +++ b/runtime/mercury_types.h @@ -44,11 +44,13 @@ #endif // This section defines types similar to C9X's header. -// We do not use , or the or 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 , or the or +// 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.