On 2/1/24 14:33, Xi Ruoyao wrote:

I mean if you are casting it to unsigned HOST_WIDE_INT, you should use
HOST_WIDE_INT_PRINT_UNSIGNED,  If you are casting it to size_t you
cannot use it (as Jakub has explained).

When you use printf-like things you have to keep the correspondence
between format specifier and the argument itself,

No, that is wrong.  That will break bootstrap on lots of hosts, any time
size_t is not unsigned long (if unsigned long is 64-bit) or unsigned long
long (if unsigned long is not 64-bit).
That includes e.g. all targets where size_t is unsigned int, and some others
too.

        Jakub



Thanks, that makes sense, tested on x86_64-linux.

diff --git a/gcc/ira-conflicts.cc b/gcc/ira-conflicts.cc
index 671b4e42b6f..ff5db18ffcc 100644
--- a/gcc/ira-conflicts.cc
+++ b/gcc/ira-conflicts.cc
@@ -150,9 +150,9 @@ build_conflict_bit_table (void)
   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));
+       "+++Allocating "HOST_WIDE_INT_PRINT_UNSIGNED" bytes for conflict table (uncompressed 
size "HOST_WIDE_INT_PRINT_UNSIGNED")\n",
+       (unsigned HOST_WIDE_INT)(allocated_words_num * sizeof (IRA_INT_TYPE)),
+       (unsigned HOST_WIDE_INT)(object_set_words * ira_objects_num * sizeof 
(IRA_INT_TYPE)));
objects_live = sparseset_alloc (ira_objects_num);
   for (i = 0; i < ira_max_point; i++)
From ab44628feca0b200aaaa2d3344af1a96cb1437c0 Mon Sep 17 00:00:00 2001
From: Jonathan Yong <10wa...@gmail.com>
Date: Thu, 1 Feb 2024 12:35:52 +0000
Subject: [PATCH] PR target/43613: use HOST_WIDE_INT_PRINT_UNSIGNED for
 build_conflict_bit_table

LLP64 platforms like uses 32bit for long and may truncate. Use
unsigned HOST_WIDE_INT and HOST_WIDE_INT_PRINT_UNSIGNED to guarantee
64bit widths.

gcc:
	*ira-conflicts.cc (build_conflict_bit_table):
	use unsigned HOST_WIDE_INT and HOST_WIDE_INT_PRINT_UNSIGNED.
---
 gcc/ira-conflicts.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/ira-conflicts.cc b/gcc/ira-conflicts.cc
index 671b4e42b6f..ff5db18ffcc 100644
--- a/gcc/ira-conflicts.cc
+++ b/gcc/ira-conflicts.cc
@@ -150,9 +150,9 @@ build_conflict_bit_table (void)
   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));
+       "+++Allocating "HOST_WIDE_INT_PRINT_UNSIGNED" bytes for conflict table (uncompressed size "HOST_WIDE_INT_PRINT_UNSIGNED")\n",
+       (unsigned HOST_WIDE_INT)(allocated_words_num * sizeof (IRA_INT_TYPE)),
+       (unsigned HOST_WIDE_INT)(object_set_words * ira_objects_num * sizeof (IRA_INT_TYPE)));
 
   objects_live = sparseset_alloc (ira_objects_num);
   for (i = 0; i < ira_max_point; i++)
-- 
2.43.0

Reply via email to