On 6/27/19 4:11 PM, Jakub Jelinek wrote: > On Thu, Jun 27, 2019 at 04:03:06PM +0200, Martin Liška wrote: >> * ggc-page.c (free_page): Use (char *) for %p printf format >> argument. > >> --- a/gcc/ggc-page.c >> +++ b/gcc/ggc-page.c >> @@ -977,7 +977,7 @@ free_page (page_entry *entry) >> if (GGC_DEBUG_LEVEL >= 2) >> fprintf (G.debug_file, >> "Deallocating page at %p, data %p-%p\n", (void *) entry, >> - entry->page, entry->page + entry->bytes - 1); >> + (char *)entry->page, (char *)entry->page + entry->bytes - 1); >> >> /* Mark the page as inaccessible. Discard the handle to avoid handle >> leak. */ > > Can you explain this? It makes no sense to me. What is the warning? > entry->page already has char * type, so why are any casts needed? > If you want to be pedantic, C says that %p argument should be pointer to > void, so I'd understand more > (void *) entry->page, (void *) (entry->page + entry->bytes - 1)); > with that formatting.
You are right, it should be the other way around: /home/marxin/Programming/gcc/gcc/ggc-page.c:946:60: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] (void *) entry, (unsigned long) OBJECT_SIZE (order), page, ^~~~ /home/marxin/Programming/gcc/gcc/ggc-page.c:947:7: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] page + entry_size - 1); ^~~~~~~~~~~~~~~~~~~~~ /home/marxin/Programming/gcc/gcc/ggc-page.c:980:7: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] entry->page, entry->page + entry->bytes - 1); ^~~~~~~~~~~ /home/marxin/Programming/gcc/gcc/ggc-page.c:980:20: warning: format specifies type 'void *' but the argument has type 'char *' [-Wformat-pedantic] entry->page, entry->page + entry->bytes - 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Martin > > Jakub >
>From 648388767ade0f7de683e79dca3fdcda3f2acda6 Mon Sep 17 00:00:00 2001 From: Martin Liska <mli...@suse.cz> Date: Thu, 27 Jun 2019 14:09:50 +0200 Subject: [PATCH] Fix 2 clang warnings. gcc/ChangeLog: 2019-06-27 Martin Liska <mli...@suse.cz> * edit-context.c (test_applying_fixits_unreadable_file): Do not use () for a constructor call. (test_applying_fixits_line_out_of_range): Likewise. * ggc-page.c (alloc_page): Use (void *) for %p printf format argument. (free_page): Likewise. --- gcc/edit-context.c | 4 ++-- gcc/ggc-page.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gcc/edit-context.c b/gcc/edit-context.c index d3246ab0334..93d10664ae9 100644 --- a/gcc/edit-context.c +++ b/gcc/edit-context.c @@ -1639,7 +1639,7 @@ static void test_applying_fixits_unreadable_file () { const char *filename = "this-does-not-exist.txt"; - line_table_test ltt (); + line_table_test ltt; linemap_add (line_table, LC_ENTER, false, filename, 1); location_t loc = linemap_position_for_column (line_table, 1); @@ -1670,7 +1670,7 @@ test_applying_fixits_line_out_of_range () const char *old_content = "One-liner file\n"; temp_source_file tmp (SELFTEST_LOCATION, ".txt", old_content); const char *filename = tmp.get_filename (); - line_table_test ltt (); + line_table_test ltt; linemap_add (line_table, LC_ENTER, false, filename, 2); /* Try to insert a string in line 2. */ diff --git a/gcc/ggc-page.c b/gcc/ggc-page.c index 7066ef2c488..a95ff466704 100644 --- a/gcc/ggc-page.c +++ b/gcc/ggc-page.c @@ -943,8 +943,8 @@ alloc_page (unsigned order) if (GGC_DEBUG_LEVEL >= 2) fprintf (G.debug_file, "Allocating page at %p, object size=%lu, data %p-%p\n", - (void *) entry, (unsigned long) OBJECT_SIZE (order), page, - page + entry_size - 1); + (void *) entry, (unsigned long) OBJECT_SIZE (order), + (void *) page, (void *) (page + entry_size - 1)); return entry; } @@ -977,7 +977,7 @@ free_page (page_entry *entry) if (GGC_DEBUG_LEVEL >= 2) fprintf (G.debug_file, "Deallocating page at %p, data %p-%p\n", (void *) entry, - entry->page, entry->page + entry->bytes - 1); + (void *) entry->page, (void *) (entry->page + entry->bytes - 1)); /* Mark the page as inaccessible. Discard the handle to avoid handle leak. */ -- 2.21.0