Skip to content

Commit 0a97720

Browse files
committed
[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
1 parent 0b8c636 commit 0a97720

File tree

1 file changed

+9
-49
lines changed

1 file changed

+9
-49
lines changed

libcxx/include/__config

+9-49
Original file line numberDiff line numberDiff line change
@@ -417,48 +417,19 @@
417417
# include <features.h> // for __NATIVE_ASCII_F
418418
# endif
419419

420-
# ifdef __LITTLE_ENDIAN__
421-
# if __LITTLE_ENDIAN__
422-
# define _LIBCPP_LITTLE_ENDIAN
423-
# endif // __LITTLE_ENDIAN__
424-
# endif // __LITTLE_ENDIAN__
425-
426-
# ifdef __BIG_ENDIAN__
427-
# if __BIG_ENDIAN__
428-
# define _LIBCPP_BIG_ENDIAN
429-
# endif // __BIG_ENDIAN__
430-
# endif // __BIG_ENDIAN__
431-
432-
# ifdef __BYTE_ORDER__
433-
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
434-
# define _LIBCPP_LITTLE_ENDIAN
435-
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
436-
# define _LIBCPP_BIG_ENDIAN
437-
# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
438-
# endif // __BYTE_ORDER__
420+
# ifndef __BYTE_ORDER__
421+
# error \
422+
"Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
423+
# endif
439424

440-
# ifdef __FreeBSD__
441-
# include <osreldate.h>
442-
# include <sys/endian.h>
443-
# if _BYTE_ORDER == _LITTLE_ENDIAN
444-
# define _LIBCPP_LITTLE_ENDIAN
445-
# else // _BYTE_ORDER == _LITTLE_ENDIAN
446-
# define _LIBCPP_BIG_ENDIAN
447-
# endif // _BYTE_ORDER == _LITTLE_ENDIAN
448-
# endif // __FreeBSD__
449-
450-
# if defined(__NetBSD__) || defined(__OpenBSD__)
451-
# include <sys/endian.h>
452-
# if _BYTE_ORDER == _LITTLE_ENDIAN
453-
# define _LIBCPP_LITTLE_ENDIAN
454-
# else // _BYTE_ORDER == _LITTLE_ENDIAN
455-
# define _LIBCPP_BIG_ENDIAN
456-
# endif // _BYTE_ORDER == _LITTLE_ENDIAN
457-
# endif // defined(__NetBSD__) || defined(__OpenBSD__)
425+
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
426+
# define _LIBCPP_LITTLE_ENDIAN
427+
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
428+
# define _LIBCPP_BIG_ENDIAN
429+
# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
458430

459431
# if defined(_WIN32)
460432
# define _LIBCPP_WIN32API
461-
# define _LIBCPP_LITTLE_ENDIAN
462433
# define _LIBCPP_SHORT_WCHAR 1
463434
// Both MinGW and native MSVC provide a "MSVC"-like environment
464435
# define _LIBCPP_MSVCRT_LIKE
@@ -531,17 +502,6 @@
531502
# define _LIBCPP_USING_DEV_RANDOM
532503
# endif
533504

534-
# if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
535-
# include <endian.h>
536-
# if __BYTE_ORDER == __LITTLE_ENDIAN
537-
# define _LIBCPP_LITTLE_ENDIAN
538-
# elif __BYTE_ORDER == __BIG_ENDIAN
539-
# define _LIBCPP_BIG_ENDIAN
540-
# else // __BYTE_ORDER == __BIG_ENDIAN
541-
# error unable to determine endian
542-
# endif
543-
# endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
544-
545505
# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
546506
# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
547507
# else

0 commit comments

Comments
 (0)