[PATCH] libcxx + MingW: correct printout of long doubles

Yaron Keren yaron.keren at gmail.com
Sun Oct 6 07:59:50 PDT 2013

I am somewhat conflicted on this.

Initially I wished the 80 bit long doubles to remain - why not use the HW
Intel gave us?
However, beyond the *scanf *printf* issues (as we learned not all of them
are solved in MingW), I just found out that the latest Visual C++ 2013
provides additional C99 math functions such as acosh, acoshf, acoshl which
is a good thing but the -l long double functions are 64 bit of course.
Previously they did not provide the -l functions so that you could just
provide them yourself say from the FreeBSD sources. Now however there is
great source of confusion since they do provide -l functions in the VC
runtime which do not work on 80 bit long doubles. The solution could be
along the lines of __minw_printf but does not exist right now.

So program compiled by clang -mingw32 would compile but produce wrong
runtime results, just like printf without the __USE_MINGW_ANSI_STDIO
defined. Not to mention __USE_MINGW_ANSI_STDIO is not even a default define
in MingW.
These are *awful* silent bugs to find. Turns out there are lots of problems
living with 80 bit long doubles in a 64 bit long double world!

In addition, clang -mingw32 clang actually produces assembler code and
calls on gcc to compile the assembler to object and link it while with
-win32 it creates object by itself and calls upon link.exe to link,
(possibly using lld in the future). So -win32 should be faster than

For the same reasons clang (and libcxx) are highly compatible with the
standard gcc on linux they should be highly compatible with standard VC on

I now think that the first priority should be -win32 since - flawed or not
- it is THE standard with Windows for others to follow.


2013/10/6 Anton Korobeynikov <anton at korobeynikov.info>

> Should definitely be both.
> On Sun, Oct 6, 2013 at 2:54 AM, Yaron Keren <yaron.keren at gmail.com> wrote:
> > The patch is required for target -mingw32 only since then clang makes 80
> bit
> > long doubles but not for target -win since clang behaves like Visual C++
> and
> > produces 64 bit long doubles.
> >
> > So this got me thinking, where libcxx on Windows is heading -
> > target -mingw32 with MingW32 headers and 80 bit long doubles?
> > target -win with Visual C++ headers with 64 bit long doubles?
> > both?
> >
> >
> > Yaron
> >
> >
> >
> > 2013/10/5 G M <gmisocpp at gmail.com>
> >>
> >> Hi Yaron
> >>
> >> I looked at this problem quite a bit a while back, FYI MS's routines are
> >> different from the libcxx versions in other ways too.
> >>
> >> I made some changes a while back to reduce and centralize some of the
> uses
> >> of snprintf in libcxx a while back in order to generally try to move
> towards
> >> what your patch proposes.
> >>
> >> I generally approve of where you are going with this patch. I'll apply
> it
> >> on my machine this weekend and try your patch out and contrast it with
> VS
> >> builds with it and report soon in more detail.
> >>
> >> I think it's a good area to focus on. Thanks for looking at this.
> >>
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
> --
> With best regards, Anton Korobeynikov
> Faculty of Mathematics and Mechanics, Saint Petersburg State University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131006/8c4b9815/attachment.html>

More information about the cfe-commits mailing list