Skip to content

[libcxx] [test] Detect the UCRT printf("%a") formatting bug #99846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

mstorsjo
Copy link
Member

This fixes testing with MinGW, if built without __USE_MINGW_ANSI_STDIO=1.

On x86 MinGW, such a configuration fails printf tests with long doubles due to mismatches between 80 and 64 bit long doubles - but on ARM, there's no such issue, so building without __USE_MINGW_ANSI_STDIO=1 is perfectly valid there.

Add another similar XFAIL to a libcxxabi test; this test isn't executed in MSVC environments, so no XFAIL has been needed so far.

@mstorsjo mstorsjo requested review from a team as code owners July 22, 2024 08:31
@llvmbot llvmbot added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. libc++abi libc++abi C++ Runtime Library. Not libc++. labels Jul 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2024

@llvm/pr-subscribers-libcxxabi

@llvm/pr-subscribers-libcxx

Author: Martin Storsjö (mstorsjo)

Changes

This fixes testing with MinGW, if built without __USE_MINGW_ANSI_STDIO=1.

On x86 MinGW, such a configuration fails printf tests with long doubles due to mismatches between 80 and 64 bit long doubles - but on ARM, there's no such issue, so building without __USE_MINGW_ANSI_STDIO=1 is perfectly valid there.

Add another similar XFAIL to a libcxxabi test; this test isn't executed in MSVC environments, so no XFAIL has been needed so far.


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

4 Files Affected:

  • (modified) libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp (+1-4)
  • (modified) libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp (+1-4)
  • (modified) libcxx/utils/libcxx/test/features.py (+20)
  • (modified) libcxxabi/test/test_demangle.pass.cpp (+2)
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
index 21efa978abdcc..946c26398fcb8 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_double.hex.pass.cpp
@@ -12,10 +12,7 @@
 
 // iter_type put(iter_type s, ios_base& iob, char_type fill, double v) const;
 
-// With the Microsoft UCRT, printf("%a", 0.0) produces "0x0.0000000000000p+0"
-// while other C runtimes produce just "0x0p+0".
-// https://developercommunity.visualstudio.com/t/Printf-formatting-of-float-as-hex-prints/1660844
-// XFAIL: msvc
+// XFAIL: win32-broken-printf-a-precision
 
 // XFAIL: LIBCXX-AIX-FIXME
 
diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp
index c97c9a0c40369..a195c34e5f8e8 100644
--- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.nm.put/facet.num.put.members/put_long_double.hex.pass.cpp
@@ -12,10 +12,7 @@
 
 // iter_type put(iter_type s, ios_base& iob, char_type fill, long double v) const;
 
-// With the Microsoft UCRT, printf("%a", 0.0) produces "0x0.0000000000000p+0"
-// while other C runtimes produce just "0x0p+0".
-// https://developercommunity.visualstudio.com/t/Printf-formatting-of-float-as-hex-prints/1660844
-// XFAIL: msvc
+// XFAIL: win32-broken-printf-a-precision
 
 // XFAIL: LIBCXX-AIX-FIXME
 
diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py
index 5e708da4f8fbe..3393bd61a8483 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -263,6 +263,26 @@ def _mingwSupportsModules(cfg):
           """,
         ),
     ),
+    # Check for a Windows UCRT bug (not fixed upstream yet).
+    # With UCRT, printf("%a", 0.0) produces "0x0.0000000000000p+0",
+    # while other C runtimes produce just "0x0p+0".
+    # https://developercommunity.visualstudio.com/t/Printf-formatting-of-float-as-hex-prints/1660844
+    Feature(
+        name='win32-broken-printf-a-precision',
+        when=lambda cfg: '_WIN32' in compilerMacros(cfg)
+        and not programSucceeds(
+            cfg,
+            """
+            #include <stdio.h>
+            #include <string.h>
+            int main(int, char**) {
+              char buf[100];
+              snprintf(buf, sizeof(buf), "%a", 0.0);
+              return strcmp(buf, "0x0p+0");
+            }
+          """,
+        ),
+    ),
     # Check for Glibc < 2.27, where the ru_RU.UTF-8 locale had
     # mon_decimal_point == ".", which our tests don't handle.
     Feature(
diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index fe5598991b831..ab783cf9d96f2 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -17,6 +17,8 @@
 // 80-bit format, and this demangling test is failing on it.
 // XFAIL: LIBCXX-ANDROID-FIXME && target={{i686|x86_64}}-{{.+}}-android{{.*}}
 
+// XFAIL: win32-broken-printf-a-precision
+
 #include "support/timer.h"
 #include <algorithm>
 #include <cassert>

Copy link

github-actions bot commented Jul 22, 2024

✅ With the latest revision this PR passed the Python code formatter.

This fixes testing with MinGW, if built without __USE_MINGW_ANSI_STDIO=1.

On x86 MinGW, such a configuration fails printf tests with long
doubles due to mismatches between 80 and 64 bit long doubles - but on
ARM, there's no such issue, so building without __USE_MINGW_ANSI_STDIO=1
is perfectly valid there.

Add another similar XFAIL to a libcxxabi test; this test isn't
executed in MSVC environments, so no XFAIL has been needed so far.
@mstorsjo mstorsjo force-pushed the libcxx-test-ucrt-bug branch from 4b0be46 to a0babe3 Compare July 22, 2024 09:04
Copy link
Member

@mordante mordante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@mstorsjo mstorsjo merged commit ca69f51 into llvm:main Jul 26, 2024
53 of 55 checks passed
@mstorsjo mstorsjo deleted the libcxx-test-ucrt-bug branch July 26, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++abi libc++abi C++ Runtime Library. Not libc++. libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants