mingw compiler problem with printf/scanf formats

Bug #1853148 reported by Dirk Zimoch
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
Status tracked in 7.0
7.0
Fix Released
Low
Unassigned

Bug Description

../db/dbJLink.c: In function ‘dbjl_integer’:
../db/dbJLink.c:136:16: warning: unknown conversion type character ‘l’ in format [-Wformat=]
         printf("dbjl_integer(%s@%p, %lld)\n",
                ^
../db/dbJLink.c:136:16: warning: too many arguments for format [-Wformat-extra-args]

It seems that mingw does not like "%lld".

Tags: 7.0
Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

Also here:

../yajl/yajl_gen.c
../yajl/yajl_gen.c: In function ‘yajl_gen_integer’:
../yajl/yajl_gen.c:205:16: warning: unknown conversion type character ‘l’ in format [-Wformat=]
     sprintf(i, "%lld", number);
                ^
../yajl/yajl_gen.c:205:16: warning: too many arguments for format [-Wformat-extra-args]

and in several locations in dbUnitTest.c, lnkConst.c, lnkCalc.c line 131, lnkDebug.c line 112, testTimeStamp.cpp lines 36 and 52, lazycounter.cpp line 172.

Also "%zu" does not work in testPVData.cpp:

../../testApp/pv/testPVData.cpp: In function ‘void testSizes()’:
../../testApp/pv/testPVData.cpp:43:58: warning: unknown conversion type character ‘z’ in format [-Wformat=]
 #define SHOW(T) testDiag("sizeof(" #T ")==%zu", sizeof(T))
                                                          ^
../../testApp/pv/testPVData.cpp:44:5: note: in expansion of macro ‘SHOW’
     SHOW(Field);
     ^
and in blockingUDPTransport.cpp:

In file included from ../../src/remote/blockingUDPTransport.cpp:29:0:
../../src/remote/blockingUDPTransport.cpp: In member function ‘bool epics::pvAccess::BlockingUDPTransport::send(const char*, size_t, const osiSockAddr&)’:
../../src/utils/pv/logger.h:48:73: warning: unknown conversion type character ‘z’ in format [-Wformat=]
 #define LOG(level, format, ...) pvAccessLog(level, format, ##__VA_ARGS__)
                                                                         ^
../../src/remote/blockingUDPTransport.cpp:437:9: note: in expansion of macro ‘LOG’
         LOG(logLevelDebug, "UDP Tx (%zu) %s -> %s.",
         ^

as well as in transportRegistry.cpp line 48, codec.cpp line 1610, responseHandlers.cpp line 2029, pvlist.cpp several lines, testpdb.cpp line 310.

It seems we have a problem with mingw.

Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :
Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :
Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

FYI: I used Ralph's new .ci features on Travis with configurations like this:

  - env: BASE=7.0 WINE=32 TEST=NO STATIC=YES
    compiler: mingw

  - env: BASE=7.0 WINE=64 TEST=NO STATIC=NO
    compiler: mingw

summary: - mingw compiler problem in dbJLink.c
+ mingw compiler problem with printf/scanf formats
Revision history for this message
Martin Konrad (info-martin-konrad) wrote :

Have you tried something like the following?

printf("dbjl_integer(%s@%p, %"PRId64")\n", pjlink->pif->name, pjlink, num);

You might need to include <inttypes.h>. Also see https://bugs.launchpad.net/epics-base/+bug/1740426.

Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

Martin, none of that is my code. I just noticed it when testing something completely different.

Revision history for this message
Andrew Johnson (anj) wrote :

We've been seeing this warning for a long time but haven't known about a fix for it. From the links you posted it would appear that adding the flag -D__USE_MINGW_ANSI_STDIO to OP_SYS_CPPFLAGS in configure/os/CONFIG.Common.win32-x86-mingw might solve it (for 64-bit builds as well), although when I just tried that it doesn't seem to silence the warnings:

/usr/bin/x86_64-w64-mingw32-g++ -DUSE_TYPED_RSET -I../../pdbApp -I../../p2pApp -I../../common -DNOMINMAX -D_MINGW -D__USE_MINGW_ANSI_STDIO -O3 -Wall -m64 -DEPICS_BUILD_DLL -DEPICS_CALL_DLL -I. -I../O.Common -I. -I. -I.. -I/local/anj/base-7.0/include/compiler/gcc -I/local/anj/base-7.0/include/os/WIN32 -I/local/anj/base-7.0/include -I/local/anj/base-7.0/include/compiler/gcc -I/local/anj/base-7.0/include/os/WIN32 -I/local/anj/base-7.0/include -o testpdb.obj -c ../testpdb.cpp
../testpdb.cpp: In function 'int main(int, char**)':
../testpdb.cpp:310:99: warning: unknown conversion type character 'z' in format [-Wformat=]
             testDiag("Cnt %s = %zu (%ld)", it->first.c_str(), it->second.current, it->second.delta);
                                                                                                   ^
../testpdb.cpp:310:99: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t {aka long long unsigned int}' [-Wformat=]
../testpdb.cpp:310:99: warning: too many arguments for format [-Wformat-extra-args]
../testpdb.cpp:348:99: warning: unknown conversion type character 'z' in format [-Wformat=]
             testDiag("Cnt %s = %zu (%ld)", it->first.c_str(), it->second.current, it->second.delta);
                                                                                                   ^
../testpdb.cpp:348:99: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'size_t {aka long long unsigned int}' [-Wformat=]
../testpdb.cpp:348:99: warning: too many arguments for format [-Wformat-extra-args]

My gcc cross-compiler is from RHEL-7, so maybe it might still help with a newer gcc/MinGW version:

tux% x86_64-w64-mingw32-g++ --version
x86_64-w64-mingw32-g++ (GCC) 4.9.3 20150626 (Fedora MinGW 4.9.3-1.el7)

If someone sees that it does help on newer versions I can add that flag to 3.15.

Changed in epics-base:
status: New → Triaged
importance: Undecided → Low
Revision history for this message
mdavidsaver (mdavidsaver) wrote :

I admit that I'm responsible for spreading this through the PVA code. I knew that recent windows and WINE both handle the standard "%lld" spec., and assumed that this was just mingw legacy. (historically MSVC used "%I64d") However, I hadn't considered the existence of a compiler builtin.

Revision history for this message
mdavidsaver (mdavidsaver) wrote :

An old, incomplete patch against pvDataCPP investigating portability issues of using PRIx64 and friends. Might be of interest, or not.

Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

I have now installed mingw on my local PC (RHEL-7)
gcc version 4.9.3 20150626 (Fedora MinGW 4.9.3-1.el7) (GCC)

I see the format problem here as well and adding -D__USE_MINGW_ANSI_STDIO does not help. Same as in Andrews's case.

So I wrote at test program that uses those offending formats, compiled it with mingw 32 and 64 bit and run it on Windows 10. No problem. Formats are interpreted correctly.

So it seems that "only" the warnings are wrong. I suggest to add -Wno-format to the mingw configurations to silence the warnings (optimally dependent on the mingw version but that is a bit hard to do -- and has some overhead cost).

Revision history for this message
Andrew Johnson (anj) wrote :

I think we concluded that this issue is related to older versions of MinGW, and that using the -D__USE_MINGW_ANSI_STDIO flag is as far as we're going to go. That has been in place since January, so I am marking this bug as fixed.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.