<div dir="ltr"><div><div><div style="margin-left:40px">+#if ((FLT_MIN < DBL_MIN) || (DBL_MIN < LDBL_MIN))<br>+    #error "Mandatory macros {FLT,DBL,LDBL}_MIN are invalid."<br></div>This value again depends on the minimum exponent, and so the relationship being tested here is not required to hold.<br><div style="margin-left:40px">+#endif<br></div><br></div>For the enumeration-like cases, perhaps it would be better to test that the value is one of the specific values.<br><br></div>-- HT<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 12, 2016 at 11:39 PM, Jorge Teixeira <span dir="ltr"><<a href="mailto:j.lopes.teixeira@gmail.com" target="_blank">j.lopes.teixeira@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I decided to strike while the iron was hot and add the remaining tests<br>
for float.h.<br>
<br>
1) clang was missing the C11 mandatory *_HAS_SUBNORM macros, so I<br>
added them. The internal underscored versions are *_HAS_DENORM, and<br>
the Std. defines only "subnormal" and "unnormalized", so there could<br>
be, in theory, a discrepancy. I tried to learn more about APfloat<br>
supported types (IEEEsingle,PPCDoubleDouble,etc.) and how the<br>
underscored macros are generated in<br>
/lib/Preprocessor/InitPreprocessor.cpp, but it was inconclusive<br>
whether *_HAS_DENORM was added to mean subnormal like C11 expects, or<br>
not normalized. If the former, all is good, if the latter, my patch is<br>
wrong and C11 compliance is not achieved - the solution would be to<br>
study all supported fp implementations and add a new macro stating<br>
only the subnormal capabilities.<br>
<br>
2) FLT_EVAL_METHOD was only introduced in C99, so I changed float.h<br>
and float.c to reflect that.<br>
<br>
3) To help ensure that all macros were tested, I reordered them in<br>
float.h and float.c to match the C11 section. This added a little<br>
noise to this diff, but should be a one-off thing and simplify<br>
maintenance if further tests or new macros are added in the future.<br>
<br>
4) The tests for the remaining macros in float.h were added. I have<br>
some reservations about the ones involving floating point literals<br>
(*_MAX, *_EPSILON, *_MIN, *_TRUE_MIN) due to the conversions and<br>
rounding among the types. Not sure how to improve them without making<br>
assumptions and/or overcomplicating the test<br>
(<a href="https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/" rel="noreferrer" target="_blank">https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/</a>).<br>
<br>
5) There were no meaningful fp changes in the Technical Corrigenda for<br>
C89, so the current tests (c89,c99,c11) should suffice. Not sure if<br>
gnuxx modes are affected, but I don't expect them to define<br>
__STRICT_ANSI__, so all macros should be exposed and tested<br>
successfully.<br>
<br>
<br>
Cheers,<br>
<br>
JT<br>
<br>
On Fri, Feb 12, 2016 at 2:32 PM, Hubert Tong<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:hubert.reinterpretcast@gmail.com">hubert.reinterpretcast@gmail.com</a>> wrote:<br>
> Committed as r260710.<br>
><br>
><br>
> On Fri, Feb 12, 2016 at 9:53 AM, Hubert Tong<br>
> <<a href="mailto:hubert.reinterpretcast@gmail.com">hubert.reinterpretcast@gmail.com</a>> wrote:<br>
>><br>
>> Thanks Jorge. I'll work on committing this today.<br>
>><br>
>> -- HT<br>
>><br>
>> On Fri, Feb 12, 2016 at 12:10 AM, Jorge Teixeira<br>
>> <<a href="mailto:j.lopes.teixeira@gmail.com">j.lopes.teixeira@gmail.com</a>> wrote:<br>
>>><br>
>>> Hubert,<br>
>>><br>
>>> Thanks for the code review. Over the weekend I'll try to learn a bit<br>
>>> more about using Phabricator, but for now I'll reply here, and attach<br>
>>> a new patch.<br>
>>><br>
>>> a) *_MANT_DIG < 1 --> *_MANT_DIG < 2<br>
>>> That is a stricter check and I agree with your rationale. Done.<br>
>>><br>
>>> b) _MIN_EXP --> FLT_MIN_EXP<br>
>>> Done.<br>
>>><br>
>>> c) Remove _MIN_EXP and _MIN_10_EXP FLT,DBL,LDBL comparisons<br>
>>> Yes, as you and Richard pointed out the added mantissa bits can<br>
>>> compensate for the lack of increase of the exponent.<br>
>>> Already fixed in <a href="http://reviews.llvm.org/rL260639" rel="noreferrer" target="_blank">http://reviews.llvm.org/rL260639</a>.<br>
>>><br>
>>> d) *_MAX_EXP and *_MIN_EXP 2,-2 --> 1,-1<br>
>>> Done.<br>
>>><br>
>>> Richard, will do re: single patch for multiple files. Also, can you<br>
>>> close the bug report? Even if more tests for float.h get<br>
>>> added/changed, the original problem has been solved.<br>
>>><br>
>>> JT<br>
>>><br>
>>><br>
>>> On Thu, Feb 11, 2016 at 8:38 PM, Hubert Tong<br>
>>> <<a href="mailto:hubert.reinterpretcast@gmail.com">hubert.reinterpretcast@gmail.com</a>> wrote:<br>
>>> > Hi Jorge,<br>
>>> ><br>
>>> > I responded to the initial commit with some comments here:<br>
>>> > <a href="http://reviews.llvm.org/rL260577" rel="noreferrer" target="_blank">http://reviews.llvm.org/rL260577</a><br>
>>> ><br>
>>> > -- HT<br>
>>> ><br>
>>> > On Thu, Feb 11, 2016 at 7:53 PM, Jorge Teixeira<br>
>>> > <<a href="mailto:j.lopes.teixeira@gmail.com">j.lopes.teixeira@gmail.com</a>><br>
>>> > wrote:<br>
>>> >><br>
>>> >> > You'll also need to change <float.h> to only provide DECIMAL_DIG in<br>
>>> >> > C99<br>
>>> >> > onwards.<br>
>>> >> Done!<br>
>>> >><br>
>>> >> > All of our -std versions are that standard plus applicable Defect<br>
>>> >> > Reports. So -std=c89 includes TC1 and TC2, but not Amendment 1 (we<br>
>>> >> > have -std=c94 for that, but the only difference from our C89 mode is<br>
>>> >> > the addition of digraphs).<br>
>>> >> I'll try to find the c89 TC2 and check if anything changed regarding<br>
>>> >> these macros (unlikely).<br>
>>> >><br>
>>> >> > __STRICT_ANSI__ is defined if Clang has not been asked to provide<br>
>>> >> > extensions (either GNU extensions, perhaps via a flag like<br>
>>> >> > -std=gnu99,<br>
>>> >> > or MS extensions), and is used by C library headers to determine<br>
>>> >> > that<br>
>>> >> > they should provide a strictly-conforming set of declarations<br>
>>> >> > without<br>
>>> >> > extensions.<br>
>>> >> Ok, so if !defined(__STRICT__ANSI__) clang should always expose "as<br>
>>> >> much as possible", including stuff from later versions of the Std.<br>
>>> >> and/or eventual extensions, just as it now on float.h and float.c,<br>
>>> >> right?<br>
>>> >><br>
>>> >> > Testing __STDC_VERSION__ for C94 makes sense if you're trying to<br>
>>> >> > detect whether Amendment 1 features should be provided.<br>
>>> >> Since this will affect only digraphs, I guess there is no need (for<br>
>>> >> float.h, float.c).<br>
>>> >><br>
>>> >> >> 3) Lastly, can you expand (...)<br>
>>> >> ><br>
>>> >> > No, it does not mean that.<br>
>>> >> ><br>
>>> >> > For PPC64, long double is (sometimes) modeled as a pair of doubles.<br>
>>> >> > Under that model, the smallest normalized value for long double is<br>
>>> >> > actually larger than the smallest normalized value for double<br>
>>> >> > (remember that for a normalized value with exponent E, all numbers<br>
>>> >> > of<br>
>>> >> > the form 1.XXXXX * 2^E, with the right number of mantissa digits,<br>
>>> >> > are<br>
>>> >> > exactly representable, so increasing the number of mantissa bits<br>
>>> >> > without changing the number of exponent bits increases the magnitude<br>
>>> >> > of the smallest normalized positive number).<br>
>>> >> ><br>
>>> >> > The set of values of long double in this model *is* a superset of<br>
>>> >> > the<br>
>>> >> > set of values of double.<br>
>>> >> ><br>
>>> >> I see now, and removed the bogus tests. The patch should now test<br>
>>> >> cleanly unless something needs DECIMAL_DIG but did not set the<br>
>>> >> appropriate std. level, or defined __STRICT__ANSI__.<br>
>>> >><br>
>>> >> Thanks for the learning experience,<br>
>>> >><br>
>>> >> JT<br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >> >> From /test/Preprocessor/init.cpp:<br>
>>> >> >> // PPC64:#define __DBL_MIN_EXP__ (-1021)<br>
>>> >> >> // PPC64:#define __FLT_MIN_EXP__ (-125)<br>
>>> >> >> // PPC64:#define __LDBL_MIN_EXP__ (-968)<br>
>>> >> >><br>
>>> >> >> This issue happened before<br>
>>> >> >><br>
>>> >> >> (<a href="https://lists.gnu.org/archive/html/bug-gnulib/2011-08/msg00262.html" rel="noreferrer" target="_blank">https://lists.gnu.org/archive/html/bug-gnulib/2011-08/msg00262.html</a>,<br>
>>> >> >> <a href="http://www.openwall.com/lists/musl/2013/11/15/1" rel="noreferrer" target="_blank">http://www.openwall.com/lists/musl/2013/11/15/1</a>), but all it means<br>
>>> >> >> is<br>
>>> >> >> that ppc64 is not compliant with C without soft-float. The test is<br>
>>> >> >> valid and should stay, and if someone tries to compile for ppc64 in<br>
>>> >> >> c89, c99 or c11 modes, clang should 1) use soft float (bad idea),<br>
>>> >> >> 2)<br>
>>> >> >> issue a diagnostic saying that that arch cannot meet the desired C<br>
>>> >> >> standard without a big performance penalty - the diag should be<br>
>>> >> >> suppressible with some special cmd line argument.<br>
>>> >> >> Thus, I added the tests back and the FAIL for PPC64 for the time<br>
>>> >> >> being, with a comment. If you know of a way to skip only the<br>
>>> >> >> specific<br>
>>> >> >> *_MIN_EXP and *_MIN_10_EXP tests, please add it, because there<br>
>>> >> >> might<br>
>>> >> >> be more similar cases in the future.<br>
>>> >> >><br>
>>> >> >> JT<br>
>>> >> >><br>
>>> >> >> On Thu, Feb 11, 2016 at 3:04 PM, Richard Smith<br>
>>> >> >> <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>><br>
>>> >> >> wrote:<br>
>>> >> >>> Thanks, I modified the test to also test C89 and C99 modes and<br>
>>> >> >>> committed this as r260577.<br>
>>> >> >>><br>
>>> >> >>> On Thu, Feb 11, 2016 at 11:29 AM, Jorge Teixeira<br>
>>> >> >>> <<a href="mailto:j.lopes.teixeira@gmail.com">j.lopes.teixeira@gmail.com</a>> wrote:<br>
>>> >> >>>> Here is a revised test, which I renamed to c11-5_2_4_2_2p11.c<br>
>>> >> >>>> instead<br>
>>> >> >>>> of float.c because I am only checking a subset of what the<br>
>>> >> >>>> standard<br>
>>> >> >>>> mandates for float.h, and because there were similar precedents,<br>
>>> >> >>>> like<br>
>>> >> >>>> test/Preprocessor/c99-*.c. Feel free to override, though.<br>
>>> >> >>><br>
>>> >> >>> test/Preprocessor/c99-* are an aberration. The goal would be that<br>
>>> >> >>> this<br>
>>> >> >>> test grows to cover all of the parts of float.h that we define, so<br>
>>> >> >>> float.c seems like the appropriate name for it.<br>
>>> >> >>><br>
>>> >> >>>> The first part checks for basic compliance with the referred C11<br>
>>> >> >>>> paragraph, the second for internal consistency between the<br>
>>> >> >>>> underscored<br>
>>> >> >>>> and exposed versions of the macros.<br>
>>> >> >>>> No attempt was made to support C99 or C89.<br>
>>> >> >>>><br>
>>> >> >>>> I am not very clear on the proper use of the whole lit.py / RUN<br>
>>> >> >>>> framework, so someone should really confirm if what I wrote is<br>
>>> >> >>>> correct. The goal was to test both hosted and freestanding<br>
>>> >> >>>> implementations with C11, and expect no diagnostics from either.<br>
>>> >> >>><br>
>>> >> >>> We generally avoid testing hosted mode, because we don't want the<br>
>>> >> >>> success of our tests to depend on the libc installed on the host<br>
>>> >> >>> system.<br>
>>> >> >>><br>
>>> >> >>>> Thanks for the help,<br>
>>> >> >>>><br>
>>> >> >>>> JT<br>
>>> >> >>>><br>
>>> >> >>>> On Tue, Feb 9, 2016 at 5:56 PM, Richard Smith<br>
>>> >> >>>> <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>><br>
>>> >> >>>> wrote:<br>
>>> >> >>>>> On Tue, Feb 9, 2016 at 2:43 PM, Jorge Teixeira<br>
>>> >> >>>>> <<a href="mailto:j.lopes.teixeira@gmail.com">j.lopes.teixeira@gmail.com</a>> wrote:<br>
>>> >> >>>>>> Richard,<br>
>>> >> >>>>>><br>
>>> >> >>>>>> Can you be more specific?<br>
>>> >> >>>>>><br>
>>> >> >>>>>> I assume you mean something like my newly attached .h file that<br>
>>> >> >>>>>> tests<br>
>>> >> >>>>>> very basic implementation compliance (i.e., it's required, but<br>
>>> >> >>>>>> not<br>
>>> >> >>>>>> sufficient), but I would need a bit more guidance about the<br>
>>> >> >>>>>> structure<br>
>>> >> >>>>>> of the file, how to perform the tests, and where to exactly<br>
>>> >> >>>>>> place<br>
>>> >> >>>>>> and<br>
>>> >> >>>>>> name the file within test/Headers.<br>
>>> >> >>>>>><br>
>>> >> >>>>>> I some sort of template exists, or if someone else takes point<br>
>>> >> >>>>>> and<br>
>>> >> >>>>>> makes it, I can "port" the attached p11 test cases. I am unsure<br>
>>> >> >>>>>> of<br>
>>> >> >>>>>> how<br>
>>> >> >>>>>> to perform a more normative compliance - for example, to assert<br>
>>> >> >>>>>> that<br>
>>> >> >>>>>> LDBL_DECIMAL_DIG is 21 on x86-64 and that indeed those many<br>
>>> >> >>>>>> digits<br>
>>> >> >>>>>> are<br>
>>> >> >>>>>> guaranteed to be correct, etc. This is probably not possible /<br>
>>> >> >>>>>> does<br>
>>> >> >>>>>> not make sense.<br>
>>> >> >>>>><br>
>>> >> >>>>> That looks like a decent basic test for this. The test should be<br>
>>> >> >>>>> named<br>
>>> >> >>>>> something like test/Headers/float.c, and needs to contain a<br>
>>> >> >>>>> "RUN:"<br>
>>> >> >>>>> line so that the test runner infrastructure knows how to run it.<br>
>>> >> >>>>> You<br>
>>> >> >>>>> can look at test/Header/limits.cpp for an example of how this<br>
>>> >> >>>>> works.<br>
>>> >> >>>>><br>
>>> >> >>>>> We already have platform-specific tests that<br>
>>> >> >>>>> __LDBL_DECIMAL_DIG__ is<br>
>>> >> >>>>> the right value, so you could test the values are correct by<br>
>>> >> >>>>> checking<br>
>>> >> >>>>> that LDBL_DECIMAL_DIG == __LDBL_DECIMAL_DIG__.<br>
>>> >> >>>>><br>
>>> >> >>>>>> JT<br>
>>> >> >>>>>><br>
>>> >> >>>>>> On Tue, Feb 9, 2016 at 3:58 PM, Richard Smith<br>
>>> >> >>>>>> <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
>>> >> >>>>>>> Patch looks good. Please also add a testcase to test/Headers.<br>
>>> >> >>>>>>><br>
>>> >> >>>>>>> On Tue, Feb 9, 2016 at 12:08 PM, Hubert Tong via cfe-commits<br>
>>> >> >>>>>>> <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
>>> >> >>>>>>>> I see no immediate issue with this patch, but I am not one of<br>
>>> >> >>>>>>>> the<br>
>>> >> >>>>>>>> usual<br>
>>> >> >>>>>>>> reviewers for this part of the code base.<br>
>>> >> >>>>>>>><br>
>>> >> >>>>>>>> -- HT<br>
>>> >> >>>>>>>><br>
>>> >> >>>>>>>><br>
>>> >> >>>>>>>> On Tue, Feb 9, 2016 at 2:56 PM, Jorge Teixeira<br>
>>> >> >>>>>>>> <<a href="mailto:j.lopes.teixeira@gmail.com">j.lopes.teixeira@gmail.com</a>><br>
>>> >> >>>>>>>> wrote:<br>
>>> >> >>>>>>>>><br>
>>> >> >>>>>>>>> Thanks Hubert. Somehow I omitted that prefix when typing the<br>
>>> >> >>>>>>>>> macros,<br>
>>> >> >>>>>>>>> and I did not noticed it when I was testing because on my<br>
>>> >> >>>>>>>>> arch<br>
>>> >> >>>>>>>>> DECIMAL_DIG is defined to be the LDBL version...<br>
>>> >> >>>>>>>>><br>
>>> >> >>>>>>>>> Updated patch is attached.<br>
>>> >> >>>>>>>>><br>
>>> >> >>>>>>>>> JT<br>
>>> >> >>>>>>>>><br>
>>> >> >>>>>>>>> On Tue, Feb 9, 2016 at 1:41 PM, Hubert Tong<br>
>>> >> >>>>>>>>> <<a href="mailto:hubert.reinterpretcast@gmail.com">hubert.reinterpretcast@gmail.com</a>> wrote:<br>
>>> >> >>>>>>>>> > There is a __LDBL_DECIMAL_DIG__ predefined macro.<br>
>>> >> >>>>>>>>> > __DECIMAL_DIG__ will<br>
>>> >> >>>>>>>>> > not<br>
>>> >> >>>>>>>>> > always be the same as __LDBL_DECIMAL_DIG__.<br>
>>> >> >>>>>>>>> ><br>
>>> >> >>>>>>>>> > -- HT<br>
>>> >> >>>>>>>>> ><br>
>>> >> >>>>>>>>> > On Mon, Feb 8, 2016 at 11:26 PM, Jorge Teixeira via<br>
>>> >> >>>>>>>>> > cfe-commits<br>
>>> >> >>>>>>>>> > <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> Hi, I filed the bug<br>
>>> >> >>>>>>>>> >> (<a href="https://llvm.org/bugs/show_bug.cgi?id=26283" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=26283</a>) some<br>
>>> >> >>>>>>>>> >> time ago and nobody picked it up, so here is a trivial<br>
>>> >> >>>>>>>>> >> patch<br>
>>> >> >>>>>>>>> >> exposing<br>
>>> >> >>>>>>>>> >> the missing macros, that to the best of my ability were<br>
>>> >> >>>>>>>>> >> already<br>
>>> >> >>>>>>>>> >> present as the internal underscored versions.<br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> Perhaps a more general bug about C11 floating point (lack<br>
>>> >> >>>>>>>>> >> of)<br>
>>> >> >>>>>>>>> >> conformance should be filed, so that some form of unit<br>
>>> >> >>>>>>>>> >> test/macro<br>
>>> >> >>>>>>>>> >> validation could be worked on, but this patch does<br>
>>> >> >>>>>>>>> >> scratch my<br>
>>> >> >>>>>>>>> >> current<br>
>>> >> >>>>>>>>> >> itch.<br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> Successfully tested on x86-64 Xubuntu 14.04 with clang<br>
>>> >> >>>>>>>>> >> 3.8<br>
>>> >> >>>>>>>>> >> from the<br>
>>> >> >>>>>>>>> >> ppa, patched with the attached diff.<br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> First contribution, so feel free to suggest improvements<br>
>>> >> >>>>>>>>> >> or<br>
>>> >> >>>>>>>>> >> point to<br>
>>> >> >>>>>>>>> >> more detailed step-by-step instructions/guidelines.<br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> Cheers,<br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> JT<br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> _______________________________________________<br>
>>> >> >>>>>>>>> >> cfe-commits mailing list<br>
>>> >> >>>>>>>>> >> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> >> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
>>> >> >>>>>>>>> >><br>
>>> >> >>>>>>>>> ><br>
>>> >> >>>>>>>><br>
>>> >> >>>>>>>><br>
>>> >> >>>>>>>><br>
>>> >> >>>>>>>> _______________________________________________<br>
>>> >> >>>>>>>> cfe-commits mailing list<br>
>>> >> >>>>>>>> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
>>> >> >>>>>>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
>>> >> >>>>>>>><br>
>>> ><br>
>>> ><br>
>><br>
>><br>
><br>
</div></div></blockquote></div><br></div>