https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108644
Bug ID: 108644
Summary: Format string warnings related to longs under
MigW-W64/MSYS2 on Windows 10
Product: gcc
Version: 13.0
Status: UNCONFIRMED
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
Build: x86_64-w64-mingw32
Below are three excerpts from my gcc's build log. I believe that all these
warnings are caused by the fact that on Windows (at least x86_64 Win 10, but
AFAIR it applies to all versions) sizeof(long) = 4. The warnings do not appear
on a x86_64 Linux, where sizeof(long) = 8. I think that some of the warnings
could be fixed by using size_t and %zu format string instead of long and %l.
make[3]: Entering directory '/d/Works/xcomp/gcc-build/lto-plugin'
/bin/sh ./libtool --tag=CC --tag=disable-static --mode=compile gcc
-DHAVE_CONFIG_H -I. -I../../../gcc/lto-plugin
-I../../../gcc/lto-plugin/../include -DHAVE_CONFIG_H -Wall
-DBASE_VERSION='"13.0.1"' -g -O2 -c -o lto-plugin.lo
../../../gcc/lto-plugin/lto-plugin.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../../gcc/lto-plugin
-I../../../gcc/lto-plugin/../include -DHAVE_CONFIG_H -Wall
-DBASE_VERSION=\"13.0.1\" -g -O2 -c ../../../gcc/lto-plugin/lto-plugin.c
-DDLL_EXPORT -DPIC -o .libs/lto-plugin.o
../../../gcc/lto-plugin/lto-plugin.c: In function 'dump_symtab':
../../../gcc/lto-plugin/lto-plugin.c:501:19: warning: 'I' flag used with '%x'
gnu_printf format [-Wformat=]
501 | fprintf (f, "%u %" PRI_LL "x %s %s\n",
| ^~~~~~
../../../gcc/lto-plugin/lto-plugin.c:501:34: note: format string is defined
here
501 | fprintf (f, "%u %" PRI_LL "x %s %s\n",
| ^
../../../gcc/lto-plugin/lto-plugin.c:501:19: warning: format '%x' expects
argument of type 'unsigned int', but argument 4 has type 'long long unsigned
int' [-Wformat=]
501 | fprintf (f, "%u %" PRI_LL "x %s %s\n",
| ^~~~~~
502 | (unsigned int) slot, symtab->aux[j].id,
| ~~~~~~~~~~~~~~~~~
| |
| long long unsigned
int
../../../gcc/lto-plugin/lto-plugin.c:501:34: note: format string is defined
here
501 | fprintf (f, "%u %" PRI_LL "x %s %s\n",
| ~~~~~~~~~~~^
| |
| unsigned int
| %" PRI_LL "llx
../../../gcc/lto-plugin/lto-plugin.c: In function 'process_symtab':
../../../gcc/lto-plugin/lto-plugin.c:1088:16: warning: 'I' flag used with '%x'
gnu_scanf format [-Wformat=]
1088 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ^~~~
../../../gcc/lto-plugin/lto-plugin.c:1088:29: note: format string is defined
here
1088 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ^
../../../gcc/lto-plugin/lto-plugin.c:1088:16: warning: format '%x' expects
argument of type 'unsigned int *', but argument 3 has type 'long long unsigned
int *' [-Wformat=]
1088 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ^~~~ ~~~~~~~~~~~~~
| |
| long long unsigned int *
../../../gcc/lto-plugin/lto-plugin.c:1088:29: note: format string is defined
here
1088 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ~~~~~~~~~~~^
| |
| unsigned int *
| %" PRI_LL "llx
../../../gcc/lto-plugin/lto-plugin.c: In function 'process_symtab_extension':
../../../gcc/lto-plugin/lto-plugin.c:1140:16: warning: 'I' flag used with '%x'
gnu_scanf format [-Wformat=]
1140 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ^~~~
../../../gcc/lto-plugin/lto-plugin.c:1140:29: note: format string is defined
here
1140 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ^
../../../gcc/lto-plugin/lto-plugin.c:1140:16: warning: format '%x' expects
argument of type 'unsigned int *', but argument 3 has type 'long long unsigned
int *' [-Wformat=]
1140 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ^~~~ ~~~~~~~~~~~~~
| |
| long long unsigned int *
../../../gcc/lto-plugin/lto-plugin.c:1140:29: note: format string is defined
here
1140 | sscanf (s, ".%" PRI_LL "x", &obj->out->id);
| ~~~~~~~~~~~^
| |
| unsigned int *
| %" PRI_LL "llx
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 ira-conflicts.o -MT
ira-conflicts.o -MMD -MP -MF ./.deps/ira-conflicts.TPo
../../../gcc/gcc/ira-conflicts.cc
../../../gcc/gcc/ira-conflicts.cc: In function 'bool
build_conflict_bit_table()':
../../../gcc/gcc/ira-conflicts.cc:153:25: warning: format '%ld' expects
argument of type 'long int', but argument 3 has type 'long long unsigned int'
[-Wformat=]
153 | "+++Allocating %ld bytes for conflict table (uncompressed size
%ld)\n",
| ~~^
| |
| long int
| %lld
154 | (long) allocated_words_num * sizeof (IRA_INT_TYPE),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long unsigned int
../../../gcc/gcc/ira-conflicts.cc:153:73: warning: format '%ld' expects
argument of type 'long int', but argument 4 has type 'long long unsigned int'
[-Wformat=]
153 | "+++Allocating %ld bytes for conflict table (uncompressed size
%ld)\n",
|
~~^
|
|
|
long int
|
%lld
154 | (long) allocated_words_num * sizeof (IRA_INT_TYPE),
155 | (long) object_set_words * ira_objects_num * sizeof
(IRA_INT_TYPE));
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| long long unsigned int
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