public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/109189] New: Format string warnings in gcc/config/h8300/h8300.cc under MigW-W64/MSYS2
@ 2023-03-19 8:57 jdx at o2 dot pl
2023-03-19 9:13 ` [Bug other/109189] " jdx at o2 dot pl
2023-03-20 8:37 ` [Bug target/109189] " jakub at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: jdx at o2 dot pl @ 2023-03-19 8:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109189
Bug ID: 109189
Summary: Format string warnings in gcc/config/h8300/h8300.cc
under MigW-W64/MSYS2
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: internal-improvement
Severity: normal
Priority: P3
Component: other
Assignee: unassigned at gcc dot gnu.org
Reporter: jdx at o2 dot pl
Target Milestone: ---
Host: x86_64-w64-mingw32
Target: h8300-elf
Created attachment 54704
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54704&action=edit
Proposed patch
I get the following messages when I build different gcc versions (12.2, master)
for H8/300:
[...]
g++ -fno-PIE -c -g -O2 -DIN_GCC -fPIC -DCROSS_DIRECTORY_STRUCTURE
-fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing
-Wwrite-strings -Wcast-qual -Wmissing-format-attribute
-Wconditionally-supported -Woverloaded-virtual -pedantic -Wno-long-long
-Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I.
-I../../../gcc/gcc -I../../../gcc/gcc/. -I../../../gcc/gcc/../include
-I../../../gcc/gcc/../libcpp/include -I../../../gcc/gcc/../libcody
-I../../../gcc/gcc/../libdecnumber -I../../../gcc/gcc/../libdecnumber/dpd
-I../libdecnumber -I../../../gcc/gcc/../libbacktrace -o h8300.o -MT h8300.o
-MMD -MP -MF ./.deps/h8300.TPo ../../../gcc/gcc/config/h8300/h8300.cc
../../../gcc/gcc/config/h8300/h8300.cc: In function 'void
h8300_print_operand(FILE*, rtx, int)':
../../../gcc/gcc/config/h8300/h8300.cc:1447:26: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1447 | fprintf (file, "#%ld", (-INTVAL (x)) & 0xff);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1460:26: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1460 | fprintf (file, "#%ld", ((-INTVAL (x)) & 0xff00) >> 8);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1468:22: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1468 | fprintf (file, "#%ld", 0xff & (-INTVAL (x)));
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1545:26: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1545 | fprintf (file, "#%ld", ((INTVAL (x) >> 16) & 0xffff));
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1570:26: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1570 | fprintf (file, "#%ld", INTVAL (x) & 0xffff);
| ^~~~~~
../../../gcc/gcc/config/h8300/h8300.cc:1624:24: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1624 | fprintf (file, "#%ld", (INTVAL (x)) & 0xff);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1632:24: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1632 | fprintf (file, "#%ld", (INTVAL (x) >> 8) & 0xff);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1640:24: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1640 | fprintf (file, "#%ld", INTVAL (x) & 0xff);
| ^~~~~~
../../../gcc/gcc/config/h8300/h8300.cc:1648:24: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1648 | fprintf (file, "#%ld", (INTVAL (x) >> 8) & 0xff);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1656:24: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1656 | fprintf (file, "#%ld", (INTVAL (x) >> 16) & 0xff);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long int
../../../gcc/gcc/config/h8300/h8300.cc:1664:24: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long int'
[-Wformat=]
1664 | fprintf (file, "#%ld", (INTVAL (x) >> 24) & 0xff);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long int
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug other/109189] Format string warnings in gcc/config/h8300/h8300.cc under MigW-W64/MSYS2
2023-03-19 8:57 [Bug other/109189] New: Format string warnings in gcc/config/h8300/h8300.cc under MigW-W64/MSYS2 jdx at o2 dot pl
@ 2023-03-19 9:13 ` jdx at o2 dot pl
2023-03-20 8:37 ` [Bug target/109189] " jakub at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: jdx at o2 dot pl @ 2023-03-19 9:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109189
--- Comment #1 from Jan Dubiec <jdx at o2 dot pl> ---
BTW, it would be nice if someone experienced could inspect lines 1547–1553,
1572–1578 and 1751–1757 in that file. These ranges contain code which looks
like this:
case CONST_DOUBLE:
{
long val;
REAL_VALUE_TO_TARGET_SINGLE (*CONST_DOUBLE_REAL_VALUE (x), val);
fprintf (file, "#%ld", ((val >> 16) & 0xffff));
break;
}
They seem kinda suspicious to me.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/109189] Format string warnings in gcc/config/h8300/h8300.cc under MigW-W64/MSYS2
2023-03-19 8:57 [Bug other/109189] New: Format string warnings in gcc/config/h8300/h8300.cc under MigW-W64/MSYS2 jdx at o2 dot pl
2023-03-19 9:13 ` [Bug other/109189] " jdx at o2 dot pl
@ 2023-03-20 8:37 ` jakub at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-20 8:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109189
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Given that all values printed that way are 0..0xff or 0..0xffff, I think better
would be to cast those to unsigned int and use %u, or cast to long and keep
using %ld.
C/C++ guarantee int is at least 16-bit and long is at least 32-bit, which is
enough to hold all those values.
So say instead of
fprintf (file, "#%ld", (INTVAL (x) >> 8) & 0xff);
use
fprintf (file, "#%ld", (long) ((INTVAL (x) >> 8) & 0xff));
or
fprintf (file, "#%u", (unsigned) ((INTVAL (x) >> 8) & 0xff));
(the & 0xff cases can be even (int) and %d) rather than the even longer
fprintf (file, "#" HOST_WIDE_INT_PRINT_DEC, (INTVAL (x) >> 8) & 0xff);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-20 8:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-19 8:57 [Bug other/109189] New: Format string warnings in gcc/config/h8300/h8300.cc under MigW-W64/MSYS2 jdx at o2 dot pl
2023-03-19 9:13 ` [Bug other/109189] " jdx at o2 dot pl
2023-03-20 8:37 ` [Bug target/109189] " jakub at gcc dot gnu.org
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).