← Back to Pull requests

[libc++] Fix build with older mingw-w64 lacking _strtof_l #234640

Closed
Himadhith closed this pull request without merging on Nov 26, 2026 06:34 UTC
View on GitHub
Himadhith Himadhith commented on Oct 22, 2026 14:20 UTC
Author

This patch fixes the build break reported after #229456 landed:

  libcxx/include/__locale_dir/support/windows.h:183:12: error: no member named '_strtof_l' in the global namespace

This only happens when building with mingw-w64 v10 or older. v11 and newer
polyfill _strtof_l (mingw-w64/mingw-w64@03ad04e), so they are not affected.

ERANGE is set on overflow to infinity and when the result is nonzero and below FLT_MIN in magnitude (subnormals included), same as glibc's strtof and mingw-w64/mingw-w64@03ad04e.

The only difference is that we compare the narrowed float and not the double, so a double just below FLT_MIN that rounds up to FLT_MIN gets no ERANGE.

Diff: 12 lines (+12 / -0) across 1 files Reviewer: venk-ks Review duration: 49933m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.18) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.18 · 12 lines diff across 1 files
0.18
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.75 · 5 substantive comment(s)
0.75
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.153
Real PR Conversation Timeline
15 items
llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Oct 22, 2026 14:32 UTC
Bot

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Himadhith

<details>
<summary>Changes</summary>

This patch fixes the MinGW cross-compilation break reported after #<!-- -->229456
landed:

  libcxx/include/__locale_dir/support/windows.h:183:12: error: no member
  named '_strtof_l' in the global namespace

ERANGE is set on overflow to infinity and when the result is nonzero and below FLT_MIN in magnitude (subnormals included), same as glibc's strtof and mingw-w64/mingw-w64@<!-- -->03ad04e.

The only difference is that we compare the narrowed float and not the double, so a double just below FLT_MIN that rounds up to FLT_MIN gets no ERANGE.

---
Full diff: https://github.com/llvm/llvm-project/pull/234640.diff

1 Files Affected:

  • (modified) libcxx/include/__locale_dir/support/windows.h (+12)
  • ``````

    diff --git a/libcxx/include/__locale_dir/support/windows.h b/libcxx/include/__locale_dir/support/windows.h
    index a72aaccccef15..726fc00f9968f 100644
    --- a/libcxx/include/__locale_dir/support/windows.h
    +++ b/libcxx/include/__locale_dir/support/windows.h
    @@ -15,6 +15,8 @@
     #include <clocale> // std::lconv & friends
     #include <cstddef>
     #include <ctype.h>  // ::_isupper_l & friends
    +#include <errno.h>  // errno, ERANGE
    +#include <float.h>  // FLT_MIN
     #include <locale.h> // ::_locale_t
     #include <stdio.h>  // ::_sscanf_l
     #include <stdlib.h> // ::_strtod_l & friends
    @@ -180,7 +182,17 @@ _LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char**
     
     template <>
     inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
    +#if defined(_LIBCPP_MSVCRT)
       return ::_strtof_l(__nptr, __endptr, __get_c_locale());
    +#else
    +  // MinGW has no _strtof_l, so we narrow the _strtod_l result to float and set
    +  // ERANGE on overflow and underflow like mingw-w64.
    +  const double __res = ::_strtod_l(__nptr, __endptr, __get_c_locale());
    +  const float __f    = static_cast<float>(__res);
    +  if (__builtin_isfinite(__res) && (__builtin_isinf(__f) || (__res != 0 && __builtin_fabsf(__f) < FLT_MIN)))
    +    errno = ERANGE;
    +  return __f;
    +#endif
     }
     
     template <>
    
    
    ``````

    </details>

    mstorsjo mstorsjo commented on code on Oct 22, 2026 14:38 UTC
    Code Review
    libcxx/include/__locale_dir/support/windows.h:1
    @@ -180,7 +182,17 @@ _LIBCPP_HIDE_FROM_ABI _FloatT __str_to_float_c_locale(const char* __nptr, char**
     
     template <>
     inline _LIBCPP_HIDE_FROM_ABI float __str_to_float_c_locale<float>(const char* __nptr, char** __endptr) {
    +#if defined(_LIBCPP_MSVCRT)
       return ::_strtof_l(__nptr, __endptr, __get_c_locale());
    +#else
    +  // MinGW has no _strtof_l, so we narrow the _strtod_l result to float and set

    Older versions of mingw lack it; recent versions do have _strtof_l polyfilled for all CRT versions.

    mstorsjo mstorsjo commented on Oct 22, 2026 14:42 UTC
    Reviewer

    Code wise this looks good to me, thanks!

    One tweak request about a code comment, and one about the commit message/PR description:

    This patch fixes the MinGW cross-compilation break reported after https://github.com/llvm/llvm-project/pull/229456 landed:

    This makes it sound like MinGW cross compilation in general is broken - it isn't, it isn't related to whether cross compiling or compiling natively at all. It's about building with older versions of mingw-w64.

    Specifically, the polyfill is available in mingw-w64 v11 and newer, so it is only broken if building with v10 or older.

    venk-ks venk-ks commented on Oct 22, 2026 17:20 UTC
    Contributor

    Tested this against Android's toolchain setup (cross-compiling libc++ for x86_64-w64-windows-gnu with our prebuilt MinGW sysroot). The patch cleanly compiles and resolves the build breakage. The float range check logic and use of compiler builtins look very solid. LGTM from our side, thanks!

    venk-ks venk-ks approved these changes on Oct 22, 2026 17:21 UTC
    Approved Reviewer

    Approved these changes.

    mstorsjo mstorsjo approved these changes on Oct 22, 2026 20:05 UTC
    Approved Reviewer

    LGTM, thanks!

    philnik777 philnik777 requested changes on Oct 22, 2026 20:14 UTC
    Changes Requested Reviewer

    What is the expected support window for MinGW? We can't keep accumulating workarounds forever.

    nickdesaulniers nickdesaulniers commented on Oct 22, 2026 22:25 UTC
    Contributor

    I think Android's mingw is ancient and needs to be upgraded. We'll take a look to see how feasible that is.
    cc @llvm/android-maintainers

    Himadhith Himadhith commented on Oct 27, 2026 05:02 UTC
    Author

    @philnik777 Can I go ahead and merge this?

    philnik777 philnik777 commented on Oct 28, 2026 10:39 UTC
    Contributor

    I'd really like an answer here before doing anything. I don't think there is precedent for adding workarounds for older mingw installations. Given that the Android people are looking into just updating I'm also not sure this is too urgent.

    mstorsjo mstorsjo commented on Oct 28, 2026 11:20 UTC
    Contributor

    I'd really like an answer here before doing anything.

    Who do you want to answer?

    For my take on your question,

    What is the expected support window for MinGW?

    I don't exactly know; we do have CI testing which usually uses a very recent git version - so we don't catch issues occurring on releases that may be slightly older. Usually there aren't many issues like this, but apparently it does happen some times. Fixing issues with reasonably recent releases of mingw should definitely be allowed IMO.

    This case is only an issue with really old versions of mingw, so it's arguably less important. That said, I don't mind this workaround either.

    Given that the Android people are looking into just updating I'm also not sure this is too urgent.

    Yes - if they're able to update to something more recent (and set things up so they can update at a somewhat regular basis, i.e. at least every other year or so), that's certainly better. So I agree we can probably wait and hear back from them if they manage to sort out upgrading it.

    nickdesaulniers nickdesaulniers commented on Oct 29, 2026 17:16 UTC
    Contributor

    IIUC, Android is using a build of mingw based on v7.0.0 which I suspect is from around ~2018. We're looking to upgrade to v14.0.0 (and improve our processes so that we can update more frequently). @Sharjeel-Khan is driving that effort. I met with @ldionne and @compnerd at the dev meeting to discuss, and @compnerd is stopping by today for lunch. Sorry we missed you @mstorsjo and @philnik777 at the dev meeting. Looks like we missed the libc++ monthly meeting (conflicted with the dev meeting), but @Sharjeel-Khan and I can stop by the next libc++ monthly meeting on 11/24 to share any updates.

    Sharjeel-Khan Sharjeel-Khan commented on Nov 24, 2026 03:07 UTC
    Contributor

    I was able to upgrade to the latest version of MinGW in Android so we can close this PR. I also set up a method to regularly update MinGW (every new release) so we do not need to worry about these workarounds anymore for us in the future.

    Himadhith Himadhith commented on Nov 26, 2026 06:34 UTC
    Author

    I was able to upgrade to the latest version of MinGW in Android so we can close this PR. I also set up a method to regularly update MinGW (every new release) so we do not need to worry about these workarounds anymore for us in the future.

    Closing the PR.

    Reviewers
    Assignees
    Himadhith Himadhith
    Labels
    risk: low confidence: 83.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 18.3% (LOW) · Higher = larger blast radius
    18.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.6% · Lower = rushed or shallow review
    83.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3% · Safe to merge
    3%