[libcxx-commits] [libcxx] 80ef412 - [libcxx] Use runtime rather then compile-time glibc version check

Petr Hosek via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 7 17:59:29 PDT 2020


Author: Petr Hosek
Date: 2020-10-07T17:59:16-07:00
New Revision: 80ef4126b100fd3c9823b20ac641fe76c4d5a11f

URL: https://github.com/llvm/llvm-project/commit/80ef4126b100fd3c9823b20ac641fe76c4d5a11f
DIFF: https://github.com/llvm/llvm-project/commit/80ef4126b100fd3c9823b20ac641fe76c4d5a11f.diff

LOG: [libcxx] Use runtime rather then compile-time glibc version check

glibc supports versioning, so it's possible to build against older
version and run against newer version. This is sometimes relied on
in practice, e.g. in Fuchsia build we build against older sysroot
(equivalent to Ubuntu Trusty) to cover the broadest possible range
of host systems, but that doesn't necessarily match the system that
binary is going to run on which may have newer version, in which case
the compile test used in curr_symbol is going to fail. Using runtime
check is more reliable. This is a follow up to D56702 which addressed
one instance, this patch addresses all of the remaining ones.

Differential Revision: https://reviews.llvm.org/D88188

Added: 
    

Modified: 
    libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp
    libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp
    libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
    libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp
    libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/thousands_sep.pass.cpp
    libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
    libcxx/test/support/platform_support.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp
index 7ec83e27dd4ee..862bc9018cbf9 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.get/locale.money.get.members/get_long_double_fr_FR.pass.cpp
@@ -54,10 +54,9 @@ class my_facetw
 // this function converts the spaces in string inputs to that character if need
 // be.
 static std::wstring convert_thousands_sep(std::wstring const& in) {
-#ifndef TEST_GLIBC_PREREQ
-#define TEST_GLIBC_PREREQ(x, y) 0
-#endif
-#if TEST_GLIBC_PREREQ(2,27)
+#if defined(_CS_GNU_LIBC_VERSION)
+  if (glibc_version_less_than("2.27"))
+    return in;
   std::wstring out;
   unsigned I = 0;
   bool seen_decimal = false;

diff  --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp
index 4a800bce02db9..e35bc2573d8cd 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.money.put/locale.money.put.members/put_long_double_fr_FR.pass.cpp
@@ -54,10 +54,9 @@ class my_facetw
 // this function converts the spaces in string inputs to that character if need
 // be.
 static std::wstring convert_thousands_sep(std::wstring const& in) {
-#ifndef TEST_GLIBC_PREREQ
-#define TEST_GLIBC_PREREQ(x, y) 0
-#endif
-#if TEST_GLIBC_PREREQ(2,27)
+#if defined(_CS_GNU_LIBC_VERSION)
+  if (glibc_version_less_than("2.27"))
+    return in;
   std::wstring out;
   unsigned I = 0;
   bool seen_num_start = false;

diff  --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
index fca8dcd2f40f1..983a3db6a197b 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp
@@ -61,20 +61,6 @@ class Fwt
         : std::moneypunct_byname<wchar_t, true>(nm, refs) {}
 };
 
-#if defined(_CS_GNU_LIBC_VERSION)
-static bool glibc_version_less_than(char const* version) {
-    std::string test_version = std::string("glibc ") + version;
-
-    size_t n = confstr(_CS_GNU_LIBC_VERSION, nullptr, (size_t)0);
-    char *current_version = new char[n];
-    confstr(_CS_GNU_LIBC_VERSION, current_version, n);
-
-    bool result = strverscmp(current_version, test_version.c_str()) < 0;
-    delete[] current_version;
-    return result;
-}
-#endif
-
 int main(int, char**)
 {
     {

diff  --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp
index bec52e6abc0dd..783e4ec86da6a 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/decimal_point.pass.cpp
@@ -110,15 +110,12 @@ int main(int, char**)
     }
 // GLIBC 2.23 uses '.' as the decimal point while other C libraries use ','
 // GLIBC 2.27 corrects this
-#ifndef TEST_GLIBC_PREREQ
-#define TEST_GLIBC_PREREQ(x, y) 0
-#endif
-#if !defined(TEST_HAS_GLIBC) || TEST_GLIBC_PREREQ(2, 27)
+#if defined(_CS_GNU_LIBC_VERSION)
+    const char sep = glibc_version_less_than("2.27") ? '.' : ',';
+    const wchar_t wsep = glibc_version_less_than("2.27") ? L'.' : L',';
+#else
     const char sep = ',';
     const wchar_t wsep = L',';
-#else
-    const char sep = '.';
-    const wchar_t wsep = L'.';
 #endif
     {
         Fnf f(LOCALE_ru_RU_UTF_8, 1);

diff  --git a/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/thousands_sep.pass.cpp b/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/thousands_sep.pass.cpp
index c789c4e5b1b1e..aa60055a96c2e 100644
--- a/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/thousands_sep.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/thousands_sep.pass.cpp
@@ -103,11 +103,8 @@ int main(int, char**)
         assert(f.thousands_sep() == ' ');
     }
 // The below tests work around GLIBC's use of U202F as mon_thousands_sep.
-#ifndef TEST_GLIBC_PREREQ
-#define TEST_GLIBC_PREREQ(x, y) 0
-#endif
-#if defined(TEST_HAS_GLIBC) && TEST_GLIBC_PREREQ(2, 27)
-    const wchar_t fr_sep = L'\u202F';
+#if defined(_CS_GNU_LIBC_VERSION)
+    const wchar_t fr_sep = glibc_version_less_than("2.27") ? L' ' : L'\u202F';
 #else
     const wchar_t fr_sep = L' ';
 #endif
@@ -123,18 +120,15 @@ int main(int, char**)
 // and U002E as mon_decimal_point.
 // TODO: Fix thousands_sep for 'char'.
 // related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16006
-#ifndef TEST_HAS_GLIBC
+#if defined(_CS_GNU_LIBC_VERSION)
     const char sep = ' ';
-    const wchar_t wsep = L' ';
-#elif TEST_GLIBC_PREREQ(2, 27)
     // FIXME libc++ specifically works around \u00A0 by translating it into
     // a regular space.
-    const char sep = ' ';
-    const wchar_t wsep = L'\u202F';
+    const wchar_t wsep = glibc_version_less_than("2.27") ? L'\u00A0' : L'\u202F';
 #else
+    const char sep = ' ';
     // FIXME libc++ specifically works around \u00A0 by translating it into
     // a regular space.
-    const char sep = ' ';
     const wchar_t wsep = L'\u00A0';
 #endif
     {

diff  --git a/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp b/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
index 2569002402727..b1c814fd84dbc 100644
--- a/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
+++ b/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp
@@ -56,14 +56,10 @@ int main(int, char**)
     }
     {
         std::locale l(LOCALE_fr_FR_UTF_8);
-#if defined(TEST_HAS_GLIBC)
-        const char sep = ' ';
 // The below tests work around GLIBC's use of U202F as LC_NUMERIC thousands_sep.
-# if TEST_GLIBC_PREREQ(2, 27)
-        const wchar_t wsep = L'\u202f';
-# else
-        const wchar_t wsep = L' ';
-# endif
+#if defined(_CS_GNU_LIBC_VERSION)
+        const char sep = ' ';
+        const wchar_t wsep = glibc_version_less_than("2.27") ? L' ' : L'\u202f';
 #else
         const char sep = ',';
         const wchar_t wsep = L',';

diff  --git a/libcxx/test/support/platform_support.h b/libcxx/test/support/platform_support.h
index e897ba7625ca6..9290dbd7b76bc 100644
--- a/libcxx/test/support/platform_support.h
+++ b/libcxx/test/support/platform_support.h
@@ -110,4 +110,18 @@ std::wstring get_wide_temp_file_name()
 
 #endif // __CloudABI__
 
+#if defined(_CS_GNU_LIBC_VERSION)
+inline bool glibc_version_less_than(char const* version) {
+  std::string test_version = std::string("glibc ") + version;
+
+  size_t n = confstr(_CS_GNU_LIBC_VERSION, nullptr, (size_t)0);
+  char *current_version = new char[n];
+  confstr(_CS_GNU_LIBC_VERSION, current_version, n);
+
+  bool result = strverscmp(current_version, test_version.c_str()) < 0;
+  delete[] current_version;
+  return result;
+}
+#endif // _CS_GNU_LIBC_VERSION
+
 #endif // PLATFORM_SUPPORT_H


        


More information about the libcxx-commits mailing list