[libcxx-commits] [libcxx] 1bd7c02 - [libc++] Clean up tests for "optional" C11 features

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 28 12:13:12 PDT 2020


Author: Louis Dionne
Date: 2020-07-28T15:13:05-04:00
New Revision: 1bd7c02233969b430b2d49e95345f507fdcc9f30

URL: https://github.com/llvm/llvm-project/commit/1bd7c02233969b430b2d49e95345f507fdcc9f30
DIFF: https://github.com/llvm/llvm-project/commit/1bd7c02233969b430b2d49e95345f507fdcc9f30.diff

LOG: [libc++] Clean up tests for "optional" C11 features

First, add a TEST_HAS_QUICK_EXIT macro to mirror other C11 features like
TEST_HAS_ALIGNED_ALLOC, and update the tests for that.

Second, get rid of TEST_HAS_C11_FEATURES and _LIBCPP_HAS_C11_FEATURES,
which were only used to ensure that feature macros don't get out of
sync between <__config> and "test_macros.h". This is not necessary
anymore, since we have tests for each individual macro now.

Added: 
    libcxx/test/libcxx/language.support/has_aligned_alloc.compile.pass.cpp
    libcxx/test/libcxx/language.support/has_quick_exit.compile.pass.cpp
    libcxx/test/libcxx/language.support/has_timespec_get.compile.pass.cpp
    libcxx/test/std/language.support/support.start.term/at_quick_exit.compile.fail.cpp
    libcxx/test/std/language.support/support.start.term/quick_exit.compile.fail.cpp

Modified: 
    libcxx/include/__config
    libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
    libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
    libcxx/test/std/language.support/support.start.term/quick_exit.pass.cpp
    libcxx/test/support/msvc_stdlib_force_include.h
    libcxx/test/support/test_macros.h

Removed: 
    libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
    libcxx/test/std/language.support/support.start.term/quick_exit_check1.compile.fail.cpp
    libcxx/test/std/language.support/support.start.term/quick_exit_check2.compile.fail.cpp


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index ebdd64ed4292..a9eca04959bf 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -348,13 +348,11 @@
 #  if defined(__FreeBSD__)
 #    define _LIBCPP_HAS_ALIGNED_ALLOC
 #    define _LIBCPP_HAS_QUICK_EXIT
-#    define _LIBCPP_HAS_C11_FEATURES
 #    if __FreeBSD_version >= 1300064 || \
        (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
 #      define _LIBCPP_HAS_TIMESPEC_GET
 #    endif
 #  elif defined(__BIONIC__)
-#    define _LIBCPP_HAS_C11_FEATURES
 #    if __ANDROID_API__ >= 21
 #      define _LIBCPP_HAS_QUICK_EXIT
 #    endif
@@ -368,7 +366,6 @@
 #    define _LIBCPP_HAS_ALIGNED_ALLOC
 #    define _LIBCPP_HAS_QUICK_EXIT
 #    define _LIBCPP_HAS_TIMESPEC_GET
-#    define _LIBCPP_HAS_C11_FEATURES
 #  elif defined(__linux__)
 #    if !defined(_LIBCPP_HAS_MUSL_LIBC)
 #      if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
@@ -376,14 +373,12 @@
 #      endif
 #      if _LIBCPP_GLIBC_PREREQ(2, 17)
 #        define _LIBCPP_HAS_ALIGNED_ALLOC
-#        define _LIBCPP_HAS_C11_FEATURES
 #        define _LIBCPP_HAS_TIMESPEC_GET
 #      endif
 #    else // defined(_LIBCPP_HAS_MUSL_LIBC)
 #      define _LIBCPP_HAS_ALIGNED_ALLOC
 #      define _LIBCPP_HAS_QUICK_EXIT
 #      define _LIBCPP_HAS_TIMESPEC_GET
-#      define _LIBCPP_HAS_C11_FEATURES
 #    endif
 #  endif // __linux__
 #endif

diff  --git a/libcxx/test/libcxx/language.support/has_aligned_alloc.compile.pass.cpp b/libcxx/test/libcxx/language.support/has_aligned_alloc.compile.pass.cpp
new file mode 100644
index 000000000000..d1b41de5dc1a
--- /dev/null
+++ b/libcxx/test/libcxx/language.support/has_aligned_alloc.compile.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure TEST_HAS_ALIGNED_ALLOC (defined by the test suite) and
+// _LIBCPP_HAS_ALIGNED_ALLOC (defined by libc++) stay in sync.
+
+#include <__config>
+#include "test_macros.h"
+
+#if defined(TEST_HAS_ALIGNED_ALLOC) != defined(_LIBCPP_HAS_ALIGNED_ALLOC)
+#   error "TEST_HAS_ALIGNED_ALLOC and _LIBCPP_HAS_ALIGNED_ALLOC are out of sync"
+#endif

diff  --git a/libcxx/test/libcxx/language.support/has_c11_features.pass.cpp b/libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
deleted file mode 100644
index ab1e6ea61925..000000000000
--- a/libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14
-
-//	We have two macros for checking whether or not the underlying C library
-//	 has C11 features:
-//		TEST_HAS_C11_FEATURES    - which is defined in "test_macros.h"
-//		_LIBCPP_HAS_C11_FEATURES - which is defined in <__config>
-//	They should always be the same
-
-#include <__config>
-#include "test_macros.h"
-
-#ifdef TEST_HAS_C11_FEATURES
-# ifndef _LIBCPP_HAS_C11_FEATURES
-#  error "TEST_HAS_C11_FEATURES is defined, but _LIBCPP_HAS_C11_FEATURES is not"
-# endif
-#endif
-
-#ifdef _LIBCPP_HAS_C11_FEATURES
-# ifndef TEST_HAS_C11_FEATURES
-#  error "_LIBCPP_HAS_C11_FEATURES is defined, but TEST_HAS_C11_FEATURES is not"
-# endif
-#endif
-
-int main(int, char**) {
-  return 0;
-}

diff  --git a/libcxx/test/libcxx/language.support/has_quick_exit.compile.pass.cpp b/libcxx/test/libcxx/language.support/has_quick_exit.compile.pass.cpp
new file mode 100644
index 000000000000..ad0fe6fb18fd
--- /dev/null
+++ b/libcxx/test/libcxx/language.support/has_quick_exit.compile.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure TEST_HAS_QUICK_EXIT (defined by the test suite) and
+// _LIBCPP_HAS_QUICK_EXIT (defined by libc++) stay in sync.
+
+#include <__config>
+#include "test_macros.h"
+
+#if defined(TEST_HAS_QUICK_EXIT) != defined(_LIBCPP_HAS_QUICK_EXIT)
+#   error "TEST_HAS_QUICK_EXIT and _LIBCPP_HAS_QUICK_EXIT are out of sync"
+#endif

diff  --git a/libcxx/test/libcxx/language.support/has_timespec_get.compile.pass.cpp b/libcxx/test/libcxx/language.support/has_timespec_get.compile.pass.cpp
new file mode 100644
index 000000000000..8b86a5ef9719
--- /dev/null
+++ b/libcxx/test/libcxx/language.support/has_timespec_get.compile.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure TEST_HAS_TIMESPEC_GET (defined by the test suite) and
+// _LIBCPP_HAS_TIMESPEC_GET (defined by libc++) stay in sync.
+
+#include <__config>
+#include "test_macros.h"
+
+#if defined(TEST_HAS_TIMESPEC_GET) != defined(_LIBCPP_HAS_TIMESPEC_GET)
+#   error "TEST_HAS_TIMESPEC_GET and _LIBCPP_HAS_TIMESPEC_GET are out of sync"
+#endif

diff  --git a/libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
index 779fbc66f5d0..1069a679263f 100644
--- a/libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
@@ -24,7 +24,7 @@
 #error FLT_RADIX not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_HAS_SUBNORM
 #error FLT_HAS_SUBNORM not defined
 #endif
@@ -54,7 +54,7 @@
 #error DECIMAL_DIG not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_DECIMAL_DIG
 #error FLT_DECIMAL_DIG not defined
 #endif
@@ -164,7 +164,7 @@
 #error LDBL_MIN not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_TRUE_MIN
 #error FLT_TRUE_MIN not defined
 #endif

diff  --git a/libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp b/libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
index 12b80adf0116..6ddd8c60834b 100644
--- a/libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
@@ -24,7 +24,7 @@
 #error FLT_RADIX not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_HAS_SUBNORM
 #error FLT_HAS_SUBNORM not defined
 #endif
@@ -54,7 +54,7 @@
 #error DECIMAL_DIG not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_DECIMAL_DIG
 #error FLT_DECIMAL_DIG not defined
 #endif
@@ -164,7 +164,7 @@
 #error LDBL_MIN not defined
 #endif
 
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && 0
+#if TEST_STD_VER > 14 && 0
 #ifndef FLT_TRUE_MIN
 #error FLT_TRUE_MIN not defined
 #endif

diff  --git a/libcxx/test/std/language.support/support.start.term/quick_exit_check1.compile.fail.cpp b/libcxx/test/std/language.support/support.start.term/at_quick_exit.compile.fail.cpp
similarity index 70%
rename from libcxx/test/std/language.support/support.start.term/quick_exit_check1.compile.fail.cpp
rename to libcxx/test/std/language.support/support.start.term/at_quick_exit.compile.fail.cpp
index 10bd5767de0e..79051fb5167d 100644
--- a/libcxx/test/std/language.support/support.start.term/quick_exit_check1.compile.fail.cpp
+++ b/libcxx/test/std/language.support/support.start.term/at_quick_exit.compile.fail.cpp
@@ -5,23 +5,23 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
-//
+
 // UNSUPPORTED: c++03
 
-// test that referencing at_quick_exit when _LIBCPP_HAS_QUICK_EXIT is not defined
+// test that referencing at_quick_exit when TEST_HAS_QUICK_EXIT is not defined
 // results in a compile error.
 
 #include <cstdlib>
 
-void f() {}
+#include "test_macros.h"
 
-int main(int, char**)
-{
-#ifndef _LIBCPP_HAS_QUICK_EXIT
+void f() { }
+
+int main(int, char**) {
+#if !defined(TEST_HAS_QUICK_EXIT)
     std::at_quick_exit(f);
 #else
-#error
+#   error
 #endif
-
-  return 0;
+    return 0;
 }

diff  --git a/libcxx/test/std/language.support/support.start.term/quick_exit_check2.compile.fail.cpp b/libcxx/test/std/language.support/support.start.term/quick_exit.compile.fail.cpp
similarity index 72%
rename from libcxx/test/std/language.support/support.start.term/quick_exit_check2.compile.fail.cpp
rename to libcxx/test/std/language.support/support.start.term/quick_exit.compile.fail.cpp
index cb0dbd35c557..f9c5bdc83569 100644
--- a/libcxx/test/std/language.support/support.start.term/quick_exit_check2.compile.fail.cpp
+++ b/libcxx/test/std/language.support/support.start.term/quick_exit.compile.fail.cpp
@@ -5,22 +5,21 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+
 // UNSUPPORTED: c++03
 
-// test that referencing quick_exit when _LIBCPP_HAS_QUICK_EXIT is not defined
+// test that referencing quick_exit when TEST_HAS_QUICK_EXIT is not defined
 // results in a compile error.
 
 #include <cstdlib>
 
-void f() {}
+#include "test_macros.h"
 
-int main(int, char**)
-{
-#ifndef _LIBCPP_HAS_QUICK_EXIT
+int main(int, char**) {
+#if !defined(TEST_HAS_QUICK_EXIT)
     std::quick_exit(0);
 #else
-#error
+#   error
 #endif
-
-  return 0;
+    return 0;
 }

diff  --git a/libcxx/test/std/language.support/support.start.term/quick_exit.pass.cpp b/libcxx/test/std/language.support/support.start.term/quick_exit.pass.cpp
index b45b3391ba5c..16f68d435640 100644
--- a/libcxx/test/std/language.support/support.start.term/quick_exit.pass.cpp
+++ b/libcxx/test/std/language.support/support.start.term/quick_exit.pass.cpp
@@ -17,7 +17,7 @@ void f() {}
 
 int main(int, char**)
 {
-#ifdef _LIBCPP_HAS_QUICK_EXIT
+#ifdef TEST_HAS_QUICK_EXIT
     std::at_quick_exit(f);
     std::quick_exit(0);
 #endif

diff  --git a/libcxx/test/support/msvc_stdlib_force_include.h b/libcxx/test/support/msvc_stdlib_force_include.h
index cf8696af5588..0869be349e23 100644
--- a/libcxx/test/support/msvc_stdlib_force_include.h
+++ b/libcxx/test/support/msvc_stdlib_force_include.h
@@ -65,9 +65,6 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
 // MSVC doesn't have __int128_t.
 #define _LIBCPP_HAS_NO_INT128
 
-// MSVC has quick_exit() and at_quick_exit().
-#define _LIBCPP_HAS_QUICK_EXIT
-
 #ifndef _LIBCXX_IN_DEVCRT
     // atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
     #define _ENABLE_ATOMIC_ALIGNMENT_FIX

diff  --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index 63aa4f47a70f..15c6a280dc19 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -169,9 +169,11 @@
 //  Specifically, FreeBSD does NOT have timespec_get, even though they have all
 //  the rest of C11 - this is PR#38495
 #    define TEST_HAS_ALIGNED_ALLOC
-#    define TEST_HAS_C11_FEATURES
+#    define TEST_HAS_QUICK_EXIT
 #  elif defined(__BIONIC__)
-#    define TEST_HAS_C11_FEATURES
+#    if __ANDROID_API__ >= 21
+#      define TEST_HAS_QUICK_EXIT
+#    endif
 #    if __ANDROID_API__ >= 28
 #      define TEST_HAS_ALIGNED_ALLOC
 #    endif
@@ -179,8 +181,8 @@
 #      define TEST_HAS_TIMESPEC_GET
 #    endif
 #  elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
+#    define TEST_HAS_QUICK_EXIT
 #    define TEST_HAS_ALIGNED_ALLOC
-#    define TEST_HAS_C11_FEATURES
 #    define TEST_HAS_TIMESPEC_GET
 #  elif defined(__linux__)
 // This block preserves the old behavior used by include/__config:
@@ -188,20 +190,22 @@
 // available. The configuration here may be too vague though, as Bionic, uClibc,
 // newlib, etc may all support these features but need to be configured.
 #    if defined(TEST_GLIBC_PREREQ)
+#      if TEST_GLIBC_PREREQ(2, 15)
+#        define TEST_HAS_QUICK_EXIT
+#      endif
 #      if TEST_GLIBC_PREREQ(2, 17)
 #        define TEST_HAS_ALIGNED_ALLOC
 #        define TEST_HAS_TIMESPEC_GET
-#        define TEST_HAS_C11_FEATURES
 #      endif
 #    elif defined(_LIBCPP_HAS_MUSL_LIBC)
+#      define TEST_HAS_QUICK_EXIT
 #      define TEST_HAS_ALIGNED_ALLOC
-#      define TEST_HAS_C11_FEATURES
 #      define TEST_HAS_TIMESPEC_GET
 #    endif
 #  elif defined(_WIN32)
 #    if defined(_MSC_VER) && !defined(__MINGW32__)
+#      define TEST_HAS_QUICK_EXIT
 #      define TEST_HAS_ALIGNED_ALLOC
-#      define TEST_HAS_C11_FEATURES // Using Microsoft's C Runtime library
 #      define TEST_HAS_TIMESPEC_GET
 #    endif
 #  endif


        


More information about the libcxx-commits mailing list