public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8898] hwint: Introduce HOST_SIZE_T_PRINT_*
@ 2024-02-09 10:59 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-02-09 10:59 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:2bb4556220285e92e599635c61029f25e9ca5e28
commit r14-8898-g2bb4556220285e92e599635c61029f25e9ca5e28
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Feb 9 11:51:08 2024 +0100
hwint: Introduce HOST_SIZE_T_PRINT_*
build_conflict_bit_table uses %ld format string for
(long) some_int_expression * sizeof (something)
argument, that doesn't work on LLP64 hosts because the
expression has then size_t aka unsigned long long type there.
It can be fixed with
(long) (some_int_expression * sizeof (something))
but it means the value is truncated if it doesn't fit into long.
Ideally we'd use %zd or %zu modifiers here, but it is unclear if we
can rely on it on all hosts, it has been introduced in C99 and C++11
includes C99 by reference, but in reality whether this works or not
depends on the host C library and some of them are helplessly obsolete.
This patch instead introduces new macros HOST_SIZE_T_PRINT_* which
one can use in *printf family function format strings and cast to
fmt_size_t type.
2024-02-09 Jakub Jelinek <jakub@redhat.com>
* hwint.h (GCC_PRISZ, fmt_size_t, HOST_SIZE_T_PRINT_DEC,
HOST_SIZE_T_PRINT_UNSIGNED, HOST_SIZE_T_PRINT_HEX,
HOST_SIZE_T_PRINT_HEX_PURE): Define.
* ira-conflicts.cc (build_conflict_bit_table): Use it. Formatting
fixes.
Diff:
---
gcc/hwint.h | 21 +++++++++++++++++++++
gcc/ira-conflicts.cc | 20 +++++++++++---------
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/gcc/hwint.h b/gcc/hwint.h
index 38b7a14cbc1d..e070e7d8dc22 100644
--- a/gcc/hwint.h
+++ b/gcc/hwint.h
@@ -115,6 +115,27 @@ typedef HOST_WIDE_INT __gcc_host_wide_int__;
#define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%" PRIx64 "%016" PRIx64
#define HOST_WIDE_INT_PRINT_PADDED_HEX "%016" PRIx64
+/* Similarly format modifier for printing size_t. As not all hosts support
+ z modifier in printf, use GCC_PRISZ and cast argument to fmt_size_t.
+ So, instead of doing fprintf ("%zu\n", sizeof (x) * y); use
+ fprintf (HOST_SIZE_T_PRINT_UNSIGNED "\n",
+ (fmt_size_t) (sizeof (x) * y)); */
+#if SIZE_MAX <= INT_MAX
+# define GCC_PRISZ ""
+# define fmt_size_t unsigned int
+#elif SIZE_MAX <= LONG_MAX
+# define GCC_PRISZ HOST_LONG_FORMAT
+# define fmt_size_t unsigned long int
+#else
+# define GCC_PRISZ HOST_LONG_LONG_FORMAT
+# define fmt_size_t unsigned long long int
+#endif
+
+#define HOST_SIZE_T_PRINT_DEC "%" GCC_PRISZ "d"
+#define HOST_SIZE_T_PRINT_UNSIGNED "%" GCC_PRISZ "u"
+#define HOST_SIZE_T_PRINT_HEX "%#" GCC_PRISZ "x"
+#define HOST_SIZE_T_PRINT_HEX_PURE "%" GCC_PRISZ "x"
+
/* Define HOST_WIDEST_FAST_INT to the widest integer type supported
efficiently in hardware. (That is, the widest integer type that fits
in a hardware register.) Normally this is "long" but on some hosts it
diff --git a/gcc/ira-conflicts.cc b/gcc/ira-conflicts.cc
index 671b4e42b6f5..83274c533300 100644
--- a/gcc/ira-conflicts.cc
+++ b/gcc/ira-conflicts.cc
@@ -115,10 +115,10 @@ build_conflict_bit_table (void)
> (uint64_t) param_ira_max_conflict_table_size * 1024 * 1024)
{
if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
- fprintf
- (ira_dump_file,
- "+++Conflict table will be too big(>%dMB) -- don't use it\n",
- param_ira_max_conflict_table_size);
+ fprintf (ira_dump_file,
+ "+++Conflict table will be too big(>%dMB) "
+ "-- don't use it\n",
+ param_ira_max_conflict_table_size);
return false;
}
}
@@ -148,11 +148,13 @@ build_conflict_bit_table (void)
object_set_words = (ira_objects_num + IRA_INT_BITS - 1) / IRA_INT_BITS;
if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
- fprintf
- (ira_dump_file,
- "+++Allocating %ld bytes for conflict table (uncompressed size %ld)\n",
- (long) allocated_words_num * sizeof (IRA_INT_TYPE),
- (long) object_set_words * ira_objects_num * sizeof (IRA_INT_TYPE));
+ fprintf (ira_dump_file,
+ "+++Allocating " HOST_SIZE_T_PRINT_UNSIGNED
+ " bytes for conflict table (uncompressed size "
+ HOST_SIZE_T_PRINT_UNSIGNED ")\n",
+ (fmt_size_t) (sizeof (IRA_INT_TYPE) * allocated_words_num),
+ (fmt_size_t) (sizeof (IRA_INT_TYPE) * object_set_words
+ * ira_objects_num));
objects_live = sparseset_alloc (ira_objects_num);
for (i = 0; i < ira_max_point; i++)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-09 10:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-09 10:59 [gcc r14-8898] hwint: Introduce HOST_SIZE_T_PRINT_* Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).