[go: up one dir, main page]

Menu

#2352 Including <cmath> in mingw with sse results in missing '::double_t'

WSL
closed
None
Bug
fixed
IINR_-_Include_In_Next_Release
True
2017-11-28
2017-10-03
Alex
No

This is pretty much the same as https://stackoverflow.com/questions/13883199/g-mingw-c11-and-sse

I do have the latest MinGW release and executing echo "#include <cmath>" | g++ -x c++ - -msse -mfpmath=sse -o /dev/null yields in

c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cmath:1101:11: error:
'::double_t' has not been declared using ::double_t;

c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cmath:1102:11: error:
'::float_t' has not been declared using ::float_t;

According to the other question this was a bug from 2012 which is supposed to be fixed. However it seems to be still there.

A bit of digging brought me to the realization that __FLT_EVAL_METHOD__ is defined but empty which causes undefined float_t/double_t.
Omitting the -mfpmath=sse option makes the problem disappear but that is not sensible.

MinGW version is 5.0.1 and gcc is 6.3.0.

Discussion

  • Keith Marshall

    Keith Marshall - 2017-10-19
    • status: unread --> open
    • Group: OTHER --> WSL
     
  • Keith Marshall

    Keith Marshall - 2017-10-19

    Thanks for reporting this; frankly, I'm astonished that it has taken nine and a half years, since Danny Smith introduced the double_t and float_t typedefs into <math.h>, for anyone to get around to filing such a report, and even then, only after what appears to me to be a regression in GCC-6 has increased the visibility of the underlying bug.

    First, let's address that GCC-6 regression, (for which you should file a report on GCC's upstream bug tracker -- https://gcc.gnu.org/bugzilla): the combination of -msse and -mfpmath=sse, as used in your command example, causes GCC-6 to define its internal __FLT_EVAL_METHOD__ to -1, (I can neither reproduce nor confirm your claim that it is defined but "empty"), whereas with releases from GCC-3 to GCC-5, this same combination of options cause __FLT_EVAL_METHOD__ to assume a value of zero, (which I think is correct; -1 indicates an indeterminate __FLT_EVAL_METHOD__ state, which arises with the earlier GCC versions only when -mfpmath is indeterminately specified as 387,sse, 387+sse, or both ... the latter two equivalents being unsupported in GCC-3). FWIW, if you specify the combination -msseN -mfpmath=sse for N = 2, 3, or 4, then __FLT_EVAL_METHOD__ will be correctly specified as zero.

    Secondly, in spite of your issue arising out of a GCC-6 regression, there is an underlying MinGW.org bug; in <math.h> I see:

    #ifdef __FLT_EVAL_METHOD__
     /* Use the compiler's builtin define for FLT_EVAL_METHOD to
      * to establish appropriate float_t and double_t typedefs.
      */
    # if __FLT_EVAL_METHOD__ == 0
       typedef float float_t;
       typedef double double_t;
    # elif __FLT_EVAL_METHOD__ == 1
       typedef double float_t;
       typedef double double_t;
    # elif __FLT_EVAL_METHOD__ == 2
       typedef long double float_t;
       typedef long double double_t;
    # endif
    #else
     /* ix87 FPU default
      */
      typedef long double float_t;
      typedef long double double_t;
    #endif
    

    The problem with this is that it presumes that __FLT_EVAL_METHOD__, if defined, will always assume a value of 0, 1, or 2; it completely ignores the (legitimate) case of GCC defining __FLT_EVAL_METHOD__ with a value of -1. We can, (and should), fix that, but code compiled with the combination of -msse -mfpmath=sse options, as in your example case, will remain vulnerable to the effects of the GCC-6 regression, and will likely misbehave, if the double_t, or float_t data types are actually used; (note that this regression will also affect C code, in the (perhaps less likely) event that these data types are used).

    Finally, as an aside, I assume that your reference to "the other question" relates to your StackOverflow reference. This is a perfect illustration of the utter futility of discussing bugs in that particular forum: not only is that entire site top heavy with disinformation, but those participating in such discussions are unlikely to be in any position to fix the underlying issue, and are also unlikely to report the problem to anyone who actually is in such a position. How could this problem have been fixed in 2012, in MinGW.org code, when no one here was ever made aware that the problem even existed?

     

    Last edit: Keith Marshall 2017-10-19
  • Alex

    Alex - 2017-10-20

    Thank you for your analysis and explanation.
    First I reported this as a bug in GCC and got shot down quickly with the explanation that without -msse2 the correct value is indeed -1. If you think this is wrong, please participate in the discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82626

    Besides that, yes the -1 case should be handled. But please also note, that other negative values are possible too (http://en.cppreference.com/w/c/types/limits/FLT_EVAL_METHOD).

    And lastly: My mistake there. It seems someone from the MinGW64 team answered to the SO post and also fixed it in their code. Probably confused this with MinGW(32).
    But besides that it is a good way of asking for help first, as most likely it is a user error not a compiler bug. (Just read the comment on my (unrelated) question "And even a bug in g++ is more unlikely than you did something wrong.") And if people find that it is a compiler bug, one can still go to the bugtrackers.

     
    • Keith Marshall

      Keith Marshall - 2017-10-20

      This is way off topic here, but...

      besides [SO] is a good way of asking for help first

      Sorry, but I can't agree with you there ... unless you are willing to accept that most of those who respond are likely to be ill-informed SO reputation seekers, who will say anything in an attempt to attract reputation-enhancing votes; it doesn't matter how accurate the information they provide is, (because those who vote know no better anyway). Around 90% of the MinGW related content on SO is utter garbage, and its quality is roughly inversely proportional to the reputation of those providing it.

      And if people find that it is a compiler bug, one can still go to the bugtrackers.

      They could, but in my experience they rarely do ... probably because they lack the confidence in their ability to adequately diagnose the attendant issues, and they don't want to expose their ignorance.

      Much better, by far, to avoid such sites as SO entirely, and direct questions to the mailing lists or fora which are specific to the projects in question, where you will stand a much better chance of getting informed, and accurate responses.

       
  • Keith Marshall

    Keith Marshall - 2017-10-20
    • assigned_to: Keith Marshall
    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -0,0 +1 @@
    +mingwrt-fpmath.patch (3.3 kB; text/x-patch)
    
    • Patch attached: False --> True
     
  • Keith Marshall

    Keith Marshall - 2017-10-20

    Attached patch should resolve the MinGW.org aspect of this bug. GCC-6 regression remains, (and may never be resolved, because GCC maintainers seem reluctant to acknowledge their culpability). Please note that, for the specific combination of -msse -mfpmath=sse options, both float_t and double_t will default to 80-bit long double precision, which may not be what you want, but it is the best compromise we can offer, unless GCC maintainers can be persuaded to DTRT.

     

    Last edit: Keith Marshall 2017-10-20
  • Keith Marshall

    Keith Marshall - 2017-10-20
    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +0,0 @@
    -mingwrt-fpmath.patch (3.3 kB; text/x-patch)
    
     
  • Keith Marshall

    Keith Marshall - 2017-11-28
    • status: open --> closed
    • Resolution: none --> fixed
    • Category: Unknown --> IINR_-_Include_In_Next_Release
     
  • Keith Marshall

    Keith Marshall - 2017-11-28

    I believe that [7cd51d] resolves this, to the extent we can achieve; it will be included in the next release.

     

    Related

    Commit: [7cd51d]