[libcxx-commits] [libcxx] 0a97720 - [libc++] Assume that __BYTE_ORDER__ is always present

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 1 09:12:13 PDT 2023


Author: Nikolas Klauser
Date: 2023-09-01T09:12:07-07:00
New Revision: 0a97720d0197e60a10c93f8af7d24e5f6d6a9807

URL: https://github.com/llvm/llvm-project/commit/0a97720d0197e60a10c93f8af7d24e5f6d6a9807
DIFF: https://github.com/llvm/llvm-project/commit/0a97720d0197e60a10c93f8af7d24e5f6d6a9807.diff

LOG: [libc++] Assume that __BYTE_ORDER__ is always present

Both Clang and GCC always define __BYTE_ORDER__, so there is no need to test the byte order a million different ways.

Reviewed By: #libc, ldionne

Spies: ldionne, libcxx-commits, krytarowski

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

Added: 
    

Modified: 
    libcxx/include/__config

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 1da412b7dea92a..8231d9f3cd2226 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -417,48 +417,19 @@
 #    include <features.h> // for __NATIVE_ASCII_F
 #  endif
 
-#  ifdef __LITTLE_ENDIAN__
-#    if __LITTLE_ENDIAN__
-#      define _LIBCPP_LITTLE_ENDIAN
-#    endif // __LITTLE_ENDIAN__
-#  endif   // __LITTLE_ENDIAN__
-
-#  ifdef __BIG_ENDIAN__
-#    if __BIG_ENDIAN__
-#      define _LIBCPP_BIG_ENDIAN
-#    endif // __BIG_ENDIAN__
-#  endif   // __BIG_ENDIAN__
-
-#  ifdef __BYTE_ORDER__
-#    if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#      define _LIBCPP_LITTLE_ENDIAN
-#    elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#      define _LIBCPP_BIG_ENDIAN
-#    endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#  endif   // __BYTE_ORDER__
+#  ifndef __BYTE_ORDER__
+#    error                                                                                                             \
+        "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
+#  endif
 
-#  ifdef __FreeBSD__
-#    include <osreldate.h>
-#    include <sys/endian.h>
-#    if _BYTE_ORDER == _LITTLE_ENDIAN
-#      define _LIBCPP_LITTLE_ENDIAN
-#    else // _BYTE_ORDER == _LITTLE_ENDIAN
-#      define _LIBCPP_BIG_ENDIAN
-#    endif // _BYTE_ORDER == _LITTLE_ENDIAN
-#  endif   // __FreeBSD__
-
-#  if defined(__NetBSD__) || defined(__OpenBSD__)
-#    include <sys/endian.h>
-#    if _BYTE_ORDER == _LITTLE_ENDIAN
-#      define _LIBCPP_LITTLE_ENDIAN
-#    else // _BYTE_ORDER == _LITTLE_ENDIAN
-#      define _LIBCPP_BIG_ENDIAN
-#    endif // _BYTE_ORDER == _LITTLE_ENDIAN
-#  endif   // defined(__NetBSD__) || defined(__OpenBSD__)
+#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#    define _LIBCPP_LITTLE_ENDIAN
+#  elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#    define _LIBCPP_BIG_ENDIAN
+#  endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 
 #  if defined(_WIN32)
 #    define _LIBCPP_WIN32API
-#    define _LIBCPP_LITTLE_ENDIAN
 #    define _LIBCPP_SHORT_WCHAR 1
 // Both MinGW and native MSVC provide a "MSVC"-like environment
 #    define _LIBCPP_MSVCRT_LIKE
@@ -531,17 +502,6 @@
 #    define _LIBCPP_USING_DEV_RANDOM
 #  endif
 
-#  if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
-#    include <endian.h>
-#    if __BYTE_ORDER == __LITTLE_ENDIAN
-#      define _LIBCPP_LITTLE_ENDIAN
-#    elif __BYTE_ORDER == __BIG_ENDIAN
-#      define _LIBCPP_BIG_ENDIAN
-#    else // __BYTE_ORDER == __BIG_ENDIAN
-#      error unable to determine endian
-#    endif
-#  endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
-
 #  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
 #    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
 #  else


        


More information about the libcxx-commits mailing list