[libcxx-commits] [PATCH] D158216: [libc++] Assume that __BYTE_ORDER__ is always present

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 18 15:35:29 PDT 2023


philnik created this revision.
Herald added a subscriber: krytarowski.
Herald added a project: All.
philnik published this revision for review.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158216

Files:
  libcxx/include/__config


Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -425,48 +425,14 @@
 #    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__
-
-#  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
@@ -539,17 +505,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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158216.551257.patch
Type: text/x-patch
Size: 2557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230818/d71b7805/attachment-0001.bin>


More information about the libcxx-commits mailing list