[LLVMbugs] [Bug 13565] New: printf format specifiers for different platforms

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 9 08:57:21 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13565

             Bug #: 13565
           Summary: printf format specifiers for different platforms
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: vanboxem.ruben at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Running this code through MinGW-w64 based Clang:
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fstream>
int main(int argc,char **argv)
{
   uint64_t val=1234567890;
   printf("%" PRId64"\n",val);
   exit(0);
}
gives following warning:
M:\Development\x64\test>clang++ -std=c++11 test.cpp -c -Wall
test.cpp:11:15: warning: invalid conversion specifier 'I'
      [-Wformat-invalid-specifier]
   printf("%" PRId64"\n",val);
           ~~~^
M:/Development/mingw64/bin/../lib/clang/3.1/../../../x86_64-w64-mingw32/include\inttypes.h:42:17:
note:
      expanded from macro 'PRId64'
#define PRId64 "I64d"
                ^
1 warning generated.

The PRId64 is defined to a valid msvcrt (Windows C runtime) format specifier,
all of which are documented here:
http://msdn.microsoft.com/en-us/library/56e442dc.aspx

I dug through the code, and ended up in these files:
http://llvm.org/svn/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp
http://llvm.org/svn/llvm-project/cfe/trunk/lib/Analysis/ScanfFormatString.cpp

Which I believe need a new "case" in the "ParsePrintfSpecifier" function, which
would look somewhat like this:


    case 'I':
        if(triplet.third == "win32" || triplet.third == "mingw32")
            k = ConversionSpecifier::???;
        break;

And perhaps similar modifications for the glibc (which would check for glibc
being used) and objc (which should check for objc being used) conversion
specifier. I do not know what ??? should be, nor if this well then be properly
handled, so I'm leaving this to the experts.

I'll gladly test a patch for this, but I'm too stupid and C-agnostic to even
understand what the function in question is doing.

Related mailing list discussion:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-August/023600.html

PS: for testing on Windows, download the GCC dw2 4.6.3-1
(http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/release/i686-w64-mingw32-gcc-dw2-4.6.3-1-release-win32_rubenvb.7z/download)
and assorted Clang 3.1
(http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/release/i686-w64-mingw32-clang-3.1-release-win32_rubenvb.7z/download)
and extract to the same directory. But as I said, I can take care of the
testing myself.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list