<div class="gmail_quote">2012/8/8 Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div>Interesting. Shouldn't be too hard to add support here (conditioned on -fms-compatibility, perhaps?), and PrintfFormatString is probably the right place to do this. If you don't feel comfortable writing a patch yourself, please file a bug at <a href="http://llvm.org/bugs/" target="_blank">http://llvm.org/bugs/</a> and eventually someone will get to it. (Perhaps Hans, since he's been doing a number of format string fixes lately?)</div>
</div></blockquote><div><br>If -fms-compatibility is enabled by default on Windows, this is fine by me. But I noticed the glibc and objc stuff is just "in plain sight" too, is this intended or just "easier to implement"?<br>
<br>I can take a look tomorrow and based on my findings/trials I'll submit a bug report and/or patch ;-) Unless someone beats me to it of course...<br><br>Ruben<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div>Thanks for catching this!</div><div>Jordan</div><div><br></div><br><div><div><div class="h5"><div>On Aug 8, 2012, at 13:48 , Ruben Van Boxem <<a href="mailto:vanboxem.ruben@gmail.com" target="_blank">vanboxem.ruben@gmail.com</a>> wrote:</div>
<br></div></div><blockquote type="cite"><div><div class="h5">Hi,<br><br>Windows' msvcrt.dll has weird printf format strings that aren't used anywhere else.<br><br>For example this code with Clang 3.1 on MinGW-w64 using GCC 4.6.3 libstdc++ headers:<br>
#define __STDC_FORMAT_MACROS<br>
#include <inttypes.h><br>#include <stdio.h><br>#include <stdlib.h><br>#include <stdint.h><br>#include <fstream><br>int main(int argc,char **argv)<br>{<br>   uint64_t val=1234567890;<br>   printf("%" PRId64"\n",val);<br>

   exit(0);<br>}<br><br>produces this warning:<br>M:\Development\x64\test>clang++ -std=c++11 test.cpp -c -Wall<br>test.cpp:11:15: warning: invalid conversion specifier 'I'<br>      [-Wformat-invalid-specifier]<br>

   printf("%" PRId64"\n",val);<br>           ~~~^<br>M:/Development/mingw64/bin/../lib/clang/3.1/../../../x86_64-w64-mingw32/include\inttypes.h:42:17: note:<br>      expanded from macro 'PRId64'<br>

#define PRId64 "I64d"<br>                ^<br>1 warning generated.<br><br>The "I64d" form is the "correct" msvcrt printf format string for this case, and the define in the mingw-w64 header inttypes.h is used to make the code correct and thus work around the msvcrt limitations.<br>

<br>Clang (and don't worry, GCC too) warns on this use, while it really shouldn't, as this is correct on Windows. I understand from a MinGW-w64 dev that they annotate their printf prototype correctly, but the compiler's builtin definition conflicts with this, and hence the warning. So I think the right solution here is to allow the MS printf format strings as well. This should work for both Visual Studio based and MinGW-w64 based Clang.<br>

<br>I was looking through the code, and found:<br><a href="http://llvm.org/svn/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp" target="_blank">http://llvm.org/svn/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp</a><br>

where I think the format string is handled, because printf is defined in<br><a href="http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def" target="_blank">http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def</a><br>

as a builtin.<br>The warning is thrown from<br><a href="http://llvm.org/svn/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp" target="_blank">http://llvm.org/svn/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp</a><br>as "diag::warn_format_invalid_conversion" I *think*.<br>

<br>Am I right that there should be a modification to PrintfFormatString.cpp (and maybe ScanfFormatString.cpp as well?) to allow the MS specific format specifiers as defined here <a href="http://msdn.microsoft.com/en-us/library/56e442dc.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/56e442dc.aspx</a> ?<br>

<br>I would prepare a patch, but I have no idea if the above is correct and what exactly (and how) I'd have to add this.<br><br>Therefore: any help is much appreciated!<br><br>Thanks,<br><br>Ruben<br><br>PS: please reply to my email directly as well, I'm not subscribed to cfe-dev<br>

<br><br></div></div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></blockquote></div><br>